Ignore Branches on rounded object

Hi, this is my first post and I am fairly new to image processing. I am trying to get a 3D mask of the nucleus(i) of cancer cells, which is imaged in Z-stacks, but there are random branches sticking out of the mask due to my thresholding. I used an auto threshold but some other stuff outside the nucleus is included in it as well but I want a fairly rounded mask. I feel like this would be simple but I don’t know how to do it. I was thinking of watershedding it but then it splits the nucleus in two as well which is not what I want. An example of the branching is at the top right corner of the first two images, where there is a random thing poking out. I want the result to be similar to the third image, but as you can see there are still some small spikes which should be gotten rid of.
I used the Otsu threshold since other thresholding which would only capture the nuclear envelope would sometimes not capture the full envelope and then I can’t use Fill Holes to mask the inside of the nucleus as well. So two ways I could fix this issue would be to either have a higher threshold and somehow still fill the inside or threshold it the same way and somehow get rid of the branching, both of which I’m not sure how to do.

Sample image and/or macro code

1 Like

Hey @vicky,

there’s two ways to get smoother outlines while thresholding:

  • Either you “over-blur” the image before thresholding or
  • you apply binary opening after thresholding.

In this video you learn how to use both (after 25:00):

Let us know if this helps!


Hi @haesleinhuepf,

I already use a Gaussian blur with a sigma of 3 before thresholding, and I tried to apply binary opening, but it didn’t seem to do much. Any other suggestions?



1 Like

As told in the video: Try Gaussian blur with sigma 50 :wink:

Furthermore, if you want to get rid of objects that are 10 pixels wide, you need use at least 5 erosions + 5 dilations for the opening.

Let us know if this helps.

Hi @haesleinhuepf,

I think a sigma of 50 was too high but it works better with ~10 for me. It still includes the stuff below the nucleus on the left in the first two images but that wasn’t the main problem. Thanks!