How to find the leftmost and rightmost white pixel in a binary image in Matlab ?

6 views (last 30 days)
I have a binary image in which there is only one nonzero region.How I find the leftmost and rightmost white pixel and then connect them by a line.

Accepted Answer

Image Analyst
Image Analyst on 24 Feb 2018
Lots of ways. For example call bwconvhull() and then regionprops to get bounding box.
binaryImage = bwconvhull(binaryImage, 'union');
props = regionprops(binaryImage, 'BoundingBox');
leftColumn = props.BoundingBox(1);
topRow = props.BoundingBox(2);
Or simply use find()
[rows, columns] = find(binaryImage);
leftColumn = min(columns);
topRow = min(rows);

More Answers (0)

Categories

Find more on Image Processing Toolbox 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!