【发布时间】: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);
有没有更好的方法?
【问题讨论】:
输入:[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);
有没有更好的方法?
【问题讨论】:
“更好”总是在旁观者的眼中。无论如何,这是使用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);
【讨论】: