【问题标题】:grayscale normalized histogram without using hist() Matlab不使用 hist() Matlab 的灰度归一化直方图
【发布时间】:2012-11-10 18:26:42
【问题描述】:

输入:[0..255] 中的灰度图像
输出:归一化的图像直方图 - 1X256 数组除以总像素数

这是我的解决方案:

function [h] = histImage(img)
    h=zeros(1,256)
    for i=1:size(h,2)
       h(i) = length(find(img==i));
    end
    h = h./sum(h);

有没有更好的方法?

【问题讨论】:

    标签: matlab image-processing


    【解决方案1】:

    “更好”总是在旁观者的眼中。无论如何,这是使用accumarray 完成上述操作的一种方法:

    %# each pixel contributes 1/nPixels to the counts of the histogram
    %# to use graylevels as indices, we have to add 1 to make it 1...256
    
    nPix = numel(img);
    h = accumarray(img(:)+1,ones(nPix,1)/nPix,[256 1],@sum,0);
    

    【讨论】:

    • h = accumarray(img(:)+1,ones(nPix,1)/nPix,[256 1],@sum,0);我猜这就是你的想法
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-19
    • 1970-01-01
    • 2023-03-05
    • 2013-06-20
    • 2017-06-08
    • 2017-01-14
    相关资源
    最近更新 更多