How to find sum of all pixels in rows whose value is 1 ?

1 view (last 30 days)
I want to calculate the sum of all pixels in rows whose value is 1 in greyscale image

Accepted Answer

Alex Mcaulley
Alex Mcaulley on 1 Jul 2019
Being im your image:
sum(im==1,2)
  6 Comments
Jan
Jan on 1 Jul 2019
@Nupur Goyal: "not work" is not a usefulö description of the problem. Please do not let the readers guess, what the problem is.
Grey scale images do not have 3 dimensions. So "(:,:,1) to (:,:,3)" means, that you do not have a grey scale image.
Alex's answer contains all you need: im==1 to get the indices and sum() to calculate the sum. Please try to combine these command until you get, what you want.

Sign in to comment.

More Answers (0)

Categories

Find more on Modify Image Colors in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!