【问题标题】:Histogram - Index must be a positive integer or logical直方图 - 索引必须是正整数或逻辑
【发布时间】:2018-08-25 02:22:53
【问题描述】:

我进行直方图标准化。当我尝试使用另一个图像lena256.bmp 时,代码正在运行。但是当我尝试使用另一张图片时,它会显示错误:

试图访问; index 必须是正整数或逻辑整数。
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);

【问题讨论】:

  • 看不到代码,可能是忘记发帖了
  • 不要放置内部链接。只需发布您的问题!

标签: matlab histogram normalization dicom


【解决方案1】:

矩阵索引不能是十进制值,因此,您需要将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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-16
    • 2014-09-11
    • 2012-04-14
    相关资源
    最近更新 更多