MATLAB: How to draw vertical and horizontal histogram of an image

horizontal and vertical histogram

I need to draw vertical and horizontal histogram of a gray scale image to find out the rectangular ROI of my image. Is it possible ?

Best Answer

I wouldn't call them histograms but I think you are referring to the mean vertical or horizontal profile that you get by summing or averaging gray levels horizontally or vertically. To do that you'd do:
verticalProfile = sum(grayImage, 2);
horizontalProfile = sum(grayImage, 1);
or you can use mean() instead of sum().