Histogram

Histogram of a monochrome image with LL possible gray levels, l=0,1,...,L1l = 0, 1, ..., L-1.

Histogram Calculation (Sample Matlab Script)

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

See: Histogram Equalization