Sampling a binary image with a matrix.

3 views (last 30 days)
I am looking to sample a binary matrix with a smaller matrix. For example, take a 100x100 "image" binary matrix and pass a 5*10 window centered on each pixel. Would it then be possible to tag certain spots in that frame I'm passing over the image and mark where "1's" occur?
For example, if the frame passes over a '1' in the image I want to look at spots (2,5) and (4,1) and see if there is a pixel that is also a 1.
  8 Comments
Geoff
Geoff on 30 May 2012
Is this correct? Let's for a moment assume that you can centre a 5x10 window on a pixel. I'll arbitrarily choose the co-ordinate (3,5) as the 'centre'. What you're asking is if there is a 1 at position (2,5) (the pixel immediately above) and/or (4,1) (the pixel immediately down and 3 places to the left). So in general I would compute two subimages slightly smaller than your large one, and offset one of them, then combine with AND. No convolution required.
Ryan
Ryan on 31 May 2012
I think this would work as well, running a for loop with offset counters for various spots in the matrices relative to the centre. Implementing the if statement in a for loop is probably less memory friendly than convolution though. This will eventually be implemented as part of a larger algorithm that will be run on a lot of images.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 30 May 2012
Construct a kernel that has a 1 in the center and a 1 at the point you want to sample. conv2() against that. The points that come out 2 in the result are the points that have both locations set. You can find() those to get the locations of the centers, and since you know the (X,Y) offset of the sample point you can add the offsets to get the location of the other end of the line.
  3 Comments
Walter Roberson
Walter Roberson on 31 May 2012
However, if there can be multiple matches, the center will get the sum of the numbers. That causes problems unless you can "decode" them, such as assigning the locations as powers of 2 and then converting the convolved sum to binary in order to figure out which positions were matched.
Ryan
Ryan on 31 May 2012
Ahhh, thank you very much! Everyone was extremely helpful!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!