直方图 - 索引必须是正整数或逻辑(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);更多推荐
发布评论