I have a binary image with non closed curves of 1-pixel width on it. I want to grab this curves as a list of points (in proper order). I found bwboundaries function which tries to wrap all non-zero pixels and thus in this case returns duplicate points:
>> A = [0 0 0; 1 1 1; 0 0 0];
>> b = bwboundaries(A)
ans =
[5x2 double]
>> b{1}
ans =
2 1
2 2
2 3
2 2
2 1
bwtraceboundary do the same
>> bwtraceboundary(A, [2 1], 'E')
ans =
2 1
2 2
2 3
2 2
2 1
Is there any standard method to get matrix like [2 1; 2 2; 2 3] immediately?
It produces double entries because your region is only one pixel wide. I don’t think there’s a standard method that handles your special problem directly. However, you can simply use the unique() function to eliminate double entries of the result.
To keep the original order of the points, just do: