I'm working on a function that takes in a grayscale image, turns it into a matrix, then takes that info and turns it into a histogram plot. I finally got it working but my histogram plot looks like the first image (blue), and it's supposed to look like the second (black). Anyone know what I should change to fix it? My code is below
% plotting the image data into a histogram %
function p = histogram(image)histogram = histogram_matlab(image);plot((0:1:255),histogram);xlabel('intensity value');xlim([0,255]);ylim([0 max(histogram)]);ylabel('PMF');end%computing the grayscale image %
function h = histogram_matlab(imageSource) openImage = imread(imageSource); [m,n] = size(openImage); h = zeros(256); for i = 1:m for j = 1:n p = double(openImage(i,j))+1; h(p) = h(p)+1; end end total_pixel = m*n; h = h./total_pixel; end
Best Answer