直方图

编程入门 行业动态 更新时间:2024-10-23 11:29:38
直方图 - 索引必须是正整数或逻辑(Histogram - Index must be a positive integer or logical)

我做直方图规范化。 当我尝试使用另一个图像lena256.bmp ,代码正在运行。 但是,当我尝试与另一个图像时,它会显示错误:

试图访问; 索引必须是正整数或逻辑。 test2错误(第10行) Histo(a(n,m)+1)=Histo(a(n,m)+1)+1;

代码如下:

a = dicomread('011fp5_256.dcm'); a = double(a); a=a/max(a(:)); figure; imshow(a); figure; imhist(a); [N, M] = size(a); Histo(1:256) = 0; for n = 1 : N for m = 1 : M Histo(a(n,m)+1) = Histo(a(n,m)+1)+1; end end Histo = Histo/(N*M); figure; plot(Histo);

I do the histogram normalization. When I try with another image lena256.bmp, the code is running. But when I try with another image it will show error:

Attempted to access ; index must be a positive integer or logical. Error in test2 (line 10) Histo(a(n,m)+1)=Histo(a(n,m)+1)+1;

Here's the code :

a = dicomread('011fp5_256.dcm'); a = double(a); a=a/max(a(:)); figure; imshow(a); figure; imhist(a); [N, M] = size(a); Histo(1:256) = 0; for n = 1 : N for m = 1 : M Histo(a(n,m)+1) = Histo(a(n,m)+1)+1; end end Histo = Histo/(N*M); figure; plot(Histo);

最满意答案

矩阵索引不能是十进制值,因此,需要将a(n,m)近似为最接近的整数值。

a = dicomread('CT-MONO2-16-ankle.dcm'); a = double(a); a=a/max(a(:)); figure; imshow(a); figure; imhist(a); [N, M] = size(a); Histo(1:256) = 0; for n = 1 : N for m = 1 : M if a(n,m)+1 ~= floor(a(n,m)+1)%I use this code for find the error disp(a(n,m)+1); end ind = floor(a(n,m)+1);% apprx. to the nearest integer. Histo(ind) = Histo(ind)+1; end end Histo = Histo/(N*M); figure; plot(Histo);

the matrix index can't be a decimal value, therefore, you need to approximate the a(n,m) to the nearest integer value.

a = dicomread('CT-MONO2-16-ankle.dcm'); a = double(a); a=a/max(a(:)); figure; imshow(a); figure; imhist(a); [N, M] = size(a); Histo(1:256) = 0; for n = 1 : N for m = 1 : M if a(n,m)+1 ~= floor(a(n,m)+1)%I use this code for find the error disp(a(n,m)+1); end ind = floor(a(n,m)+1);% apprx. to the nearest integer. Histo(ind) = Histo(ind)+1; end end Histo = Histo/(N*M); figure; plot(Histo);

更多推荐

本文发布于:2023-07-04 17:22:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1027025.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:直方图

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!