How to run a loop that counts the number of intersections with non-background values along a row?

1 view (last 30 days)
Hi guys,
I'm quite new at Matlab and am currently writing a script to count the number of times a non-background (>1) value is intersected along a row within a binary image. Sort of a moving search window. I have managed to code it so far to count the intersections along row 1, for example, in an image, but would like some hints as to how to write it so that it then counts again from x number of rows DOWN from the first, as a sort of automated process for the whole image.
Ie: Count number of intersections along row 1: Count number of intersections along row 10 Count number of intersections along row 20 ...so on and so forth until the end of the image.
Thanks for any help you can provide! Cheers

Answers (1)

Adam
Adam on 6 Aug 2014
sum( myImage > 1, 2 )
should give you the sum for every row without needing a loop. If you really don't want every row then you can use indexing to only choose certain rows either before the sum or after it. Unless your image is enormous the sum will be so fast there is unlikely any point filtering which rows you want prior to the sum.

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!