MATLAB: How to sum and plot all pixels of an area in image and plot them

image processingpixels countingplotsegmentation

A new aproach and a NEW question of my previous query.
What I actually want to achieve is to get for every column of the image (see attached image) the sum of all its pixels. But not for the entire image. I want for part inside the red contour.
The counting should start from the bottom of the red segmented contour up until the top red contour. Is there a way to put a marker somewhere in the first one third of the image and tell Matlab to count from that point down to the bottom of the red contour, the total of pixels for every column and plot them.
YOu can see at image A3.jpg, I have marked with green pen the top point and the bottom point, of the area the pixel should be measured.
Is my question clear?

Best Answer

  • From your other question, you already have the masked image. So to sum vertically, just use sum(). To plot, use plot():
    horizontalProfile = sum(maskedImage, 1); % Sum vertically.
    plot(horizontalProfile, 'b-', 'LineWidth', 2);
    xlabel('Column', 'FontSize', 20);
    ylabel('Sum of gray levels in column', 'FontSize', 20);