I have a set of binary 2D images with objects in white and their boundaries in black (attached example). I also have a list of centroids (x,y coordinate pairs) identifying all objects.

enter image description here

For each object, I am trying to identify all the x,y coordinates of that object's boundary (black pixels). Anyone have an idea on programming logic that can help achieve this?

I apologize in advance if this post belongs in another section. If anything is unclear I can clarify. Thanks.

  • $\begingroup$ ...why not select all the black pixels in the image? $\endgroup$ – A_A Feb 25 at 7:56
  • $\begingroup$ So I can identify all black pixels in the entire object. However, after doing that, I don't know how to figure out which black pixels out of all the black pixels in the image surround a particular white object -which can be identified by its centroid. $\endgroup$ – Vivek Feb 25 at 21:22
  • $\begingroup$ Thanks. Is this homework by any chance? Nothing wrong with homework, just the "answer approach" will be slightly different. $\endgroup$ – A_A Feb 25 at 21:40
  • $\begingroup$ It's for my research. The sample image I attached is an image taken from a microscope and the white objects are biological cells. I just didn't want to add confusion by giving the background info. $\endgroup$ – Vivek Feb 27 at 1:01
  • $\begingroup$ Can I please ask if this was resolved? $\endgroup$ – A_A Jun 2 at 8:54

In general you would be looking at "Image Segmentation" techniques.

Since you do have the centroids, you can use them in "region growing".

In this technique, you start from a seed point and depending on the sort of pixel connectivity you are interested in you expand the identified region. For example, with 4 connectivity, you would start at the seed point, which is clearly part of the region. You would then examine the 4 immediate neighbours of the seed, each one having 2-3 neighbours (there will be overlaps). If those pixels belong to the region (e.g. they turn out to be white), you examine their neighbours and the neighbours neigbhours and so on.

The algorithm terminates when there are no more neighbours to consider for their connectivity.

You can write this from first principles, or you can use skimage's label(). In fact, that function applies pixel connectivity slightly differently, by building regions up as it reads the image, creating a new one if it finds a disconnected pixel, so, you would not even need the centroids in that case.

Hope this helps.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.