How to extract 3 distinct curves from a mask into separate matrices?

2 views (last 30 days)
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!

Accepted Answer

Akira Agata
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
Gir Val
Gir Val on 1 Jan 2019
Thank you Mr. Agata this has worked perfectly and saved me a significant amount of time manually inputing bounds for subsequent image analysis that I would have needed for my manual method!
Happy new year!

Sign in to comment.

More Answers (1)

Image Analyst
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.
  1 Comment
Gir Val
Gir Val on 1 Jan 2019
Image analyst thank you very much for your help and taking the time on new year's eve to help me. I've also seen and used several of your answers elsewhere in Mathworks blogs and apreciate your help!! Happy New Year!!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!