How to extract 3 distinct curves from a mask into separate matrices?
2 views (last 30 days)
Show older comments
I generated this mask (a 1018x2038 matrix with only 0 and 1 as values) from a PNG file. The mask shows three curves. I would like to retrieve the coordinates of these curves as separate matrices.
Matrix 'A' = coordinates of the points that comprise the top line
Matrix 'B' = coordinates of the points that comprise the middle line
Matrix 'C' = coordinates of the points that comprise the bottom line
I am trying to code something that will do so manually, but is there a prebuilt function (preferred) or strategy that anyone suggests?
In advance, thank you very much for your help!
0 Comments
Accepted Answer
Akira Agata
on 1 Jan 2019
Assuming your 1018x2038 mask is BW, the following code can extract coordinates of each line.
s = regionprops(BW,'PixelList');
A = s(1).PixelList;
B = s(2).PixelList;
C = s(3).PixelList;
2 Comments
More Answers (1)
Image Analyst
on 1 Jan 2019
You can use bwlabel() and then ismember()
[labeledImage, numregions] = bwlabel(binaryImage);
for k = 1 : numRegions
[rows, columns] = find(ismember(labeledImage, k));
regions{k, 1} = rows;
regions{k, 2} = columns;
end
Now the different rows and columns of the pixels in each line are in respective cells of the cell array.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!