MATLAB: Count white pixels on each column of a binary image

image analysisimage processing

I need to find the number of white pixels in each column and find the pixel position of column with minimum white pixels
Here is my image
topHalf.jpg
I have done the following code,but it finds white pixels in each row.How can I modify this code to get the correct value
counts(size(topHalf,1):-1:1,:) = sum(topHalf == 1,2)

Best Answer

It's puzzling why you can't modify your code:
counts = sum(topHalf, 1); %all you need to change is the ,2 into ,1 to sum along the rows instead of the columns.
Note that I've removed the == 1, since if the image is binary topHalf == 1 is exactly the same as topHalf.