[英]grayscale normalized histogram without using hist() Matlab
: a grayscale img in [0..255] :[0..255]中的灰度img
: img histogram normalized - an array 1X256 divided by total number of pixels :img histogram标准化 - 数组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
进行上述操作的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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.