我做直方图归一化。当我尝试使用另一个图像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);
矩阵索引不能是十进制值,因此,您需要将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);