Histogram of a monochrome image with possible gray levels, .
function h = histogram(imgname)
img = imread(imgname);
figure; imshow(img);
% method 1
h = zeros(256,1);
for l = 0:255
for i = 1:N,
for j = 1:M,
if img(i, j) == l,
h(l + 1) = h(l + 1) + 1;
end
end
end
end
figure; bar(h);
% method 2
img = double(img); h = zeros(256,1);
for i=1:M,
for j=1:N,
f = img(i,j);
h(f+1) = h(f+1) + 1;
end
end
% method 3
h = zeros(256,1);
for l = 0 : 255,
h(l + 1)=sum(sum(img == l));
end
imhist( )
: can compute and display
histogramsmatplotlib.pyplot.hist( )
,
numpy.histogram( )