function histogram(file) image = imread(file); [rows, cols] = size(image); histogram = zeros(256); for i = 1:rows for j = 1:cols pixel = image(i,j); histogram(pixel+1) = histogram(pixel+1)+1; end end maxy = max(histogram); x = 0:1:255; plot(x, histogram(x+1)); set(gca,'XLim',[0 255]) end