count white pixels on each column of a binary image

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)

 Akzeptierte Antwort

Guillaume
Guillaume am 13 Mär. 2019
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.

3 Kommentare

How to obtain the column with minimum white pixels
[~, indexofcolumn] = min(counts)
I need to find the pixel coordinates at the portion marked.Please suggest a methodIMAGE.jpg

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by