Input: a grayscale img in [0..255]
Output: img histogram normalized – an array 1X256 divided by total number of pixels
This is my solution:
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);
Is there a better way to do it?
“Better” is always in the eye of the beholder. Anyway, here’s a way to do the above using
accumarray: