Get pixels in a region
Show older comments
Hi,
I'm looking to get the locations of the first white pixel (top left) of each region and the last white pixel in each region (bottom right) of the image supplied. I do not need every white pixel in the region either, just the beginning and end points. I need this to determine the "entry and exit points" of the regions in the image so it can later be compared against a similar image.
If anyone has any suggestions of how this would be done, I'd really appreciate it. I've tried using find() but I only ever manage to get the very first white pixel and the very last in the image.

Thanks.
2 Comments
Walter Roberson
on 7 Mar 2016
Your question is ambiguous. Do you need the leftmost white pixel of the top row that has at least one white pixel, or do you need the topmost white pixel of the first column that has at least one white pixel? Likewise, do you need the rightmost white pixel of the bottom row that has at least one white pixel, or do you need the bottommost white pixel of the last column that has at least one white pixel?
Your image has slanted lines so it does make a difference.
Niamh Shiel
on 8 Mar 2016
Answers (1)
Image Analyst
on 8 Mar 2016
From your clarification, it sounds like you could do
[rows, columns] = find(binaryImage);
leftColumn = min(columns);
rightColumn = max(columns);
4 Comments
Niamh Shiel
on 8 Mar 2016
Edited: Niamh Shiel
on 8 Mar 2016
Image Analyst
on 8 Mar 2016
Try it. It will give you the same left and right columns, except that yours will be shifted by half a pixel so that it lies not on pixels but in between them. See my discussion here: http://www.mathworks.com/matlabcentral/answers/271694#comment_348710
Niamh Shiel
on 8 Mar 2016
Image Analyst
on 8 Mar 2016
Sure, do whatever you need to to get the right answer.
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!