How make endpoints of bwboundaries consistent in Matlab?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I have an image and if I then plot the boundary of just the left and edges with the code below:
imshow(I); hold on; [B,L,N] = bwboundaries(I);
for k=1:length(B),
boundary = B{k};
BL=size(boundary);
plot(boundary(1,2), boundary(1,1), '*g','MarkerSize',15);
for j=1:10:BL(1)
plot(boundary(j,2), boundary(j,1), '.r','MarkerSize',5);
end
end
I get this image
The starting point (the green star) for the left edge is at the left side of the image, which is what I expected. However, the starting point for the right edge is towards the middle
Apparently this is because `bwboundaries` deals with tracing objects in clockwise direction, whereas the 2nd edge needs to be traced counterclockwise for it to begin and end on the right boundary of the image
I was hoping the start and end points for both edges would be where the blue dots are
I also was hoping the boundary array for the right edge from `bwboundaries` would be sorted from the corrected startpoint to endpoint (like how it is for the left edge), so that for edges that don't touch the border, I can then draw a straight line connecting them (like in red in the last image), and then use `polyshape` and `area` on it, so I can find the area of that closed region, like in the image belo
how can I do this in Matlab?
0 Kommentare
Antworten (1)
Image Analyst
am 8 Mär. 2019
Bearbeitet: Image Analyst
am 8 Mär. 2019
Blobs are found in column major order, in other words, going down rows in the first column, until it hits something white, and then across to the next column to the right if it didn't find anything. So in your first blob, the upper left endpoint was the leftmost pixel, whereas in your second blob, the middle of the curve was the leftmost white pixel. Once it finds the first starting pixel, it follows the boundary, clockwise (I guess).
Why don't you skeletonize the blobs/snakes with bwmorph(mask, 'skel', inf) and then detect endpoints with bwmorph(mask, 'endpoints')?
0 Kommentare
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!