4

I have a 2D Numpy array of the following form (up to 5000 rows):

 [ 247.68512  182.67136]
 [ 248.71936  182.67136]
 [ 249.74336  182.67136]
 [ 253.85984  269.1072 ]
 [ 254.89408  269.1072 ]
 [ 255.91808  269.1072 ]
 [ 249.74336  182.67136]
 [ 250.7776   182.67136]
 [ 251.8016   182.67136]
 ...

Where column 0 corresponds to x, and column 1 to y.

When plotted the data should resemble a blob shape.

Example blob

Example blob2

How can I reduce this data to just have the edge or contour around the blob?

I have looked at some of the skimage edge detection functions but I think there is a pure numpy solution out there.

Any help? If edge detection is the way to go what's the best tool?

Thanks

--- Edit ---- The data is also unsorted, but I can sort around the orgin of the blob with some existing code I have. Not sure if that helps.

Sorted Blob Example

--- Edit 2 --- Stumbled upon this beautiful solution by K.D.

I think this should work perfectly for this application. Will try this.

2
  • It's a bit hard to tell from the plot, but it looks like the points are very close to falling on a regular grid with a spacing of ~1 in X and Y. If you were to round each X and Y coordinate to the nearest integer value, would any of the points end up overlapping? Commented Apr 24, 2017 at 23:54
  • I added another plot to show the data a bit better. If I round each x,y to int there would definitely be overlap just due to the number of blob-points. Commented Apr 25, 2017 at 0:05

1 Answer 1

1

It depends on the topology of the blob. If the blob is smooth and has no voids inside you can do this: approach blob from far. Scan across blob location. When you hit a point - check neighboring grid. If you have high enough point density set isOnBorder = true. Now, for each neighboring point check if it is such that it has both empty and filled neighbors. If yes - this is a border point - add it to list. Repeat procedure until you get full border. If you have voids you would have to do grid inside and check for inner borders as well.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.