Fill small holes in the segmentation label image

Hi all, I have done a Sitk.MorphologicalWatershed to my image and got a label image, I find there are some small segments of one or two pixels, or like this little “cross”:
image

What would be the best filter/way to fill these small holes, I tried Sitk.BinaryFillhole but it doesn’t do much, any other API shall I try? Thanks!

That fill hole filter ought to work. Perhaps try SimpleITK’s MedianImageFilter?

https://simpleitk.org/doxygen/latest/html/classitk_1_1simple_1_1MedianImageFilter.html

1 Like

Frequently people look at 2D slices of 3D images, and “identify” holes. The little cross is a morphological hole if the image is 2D, but might be beginning (first slice) of a some 3D pit/cavity.

Take a look at this page. A slice through the middle of the torus would show a big “hole”, which in 3D is just the edge of the torus, and not a hole at all.

Thanks @dchen ! MedianImageFilter seems working for me. Do all the Binary* API assume the input image has one background value and one foreground value (hence binary), so they won’t work well with label image which usually has more values?

Thanks @dzenanz , currently I am working only with single 2D slices, but you have a good point and I will remember it when I start working with 3D images!

I am not sure what segmentation artifact you are trying to address. You may want to look into LabelVoting, or “LabelSet” morphology ( which is not enabled by default in SimpleITK ), or perhaps grayscale morphology operations such as closing or opening would work.

2 Likes

With multi-label images it gets more complicated to fill in holes with just a binary operator. You can set the foreground value, if you’re sure that the holes can never overlap.

If your labels can be nested, then a hole in label A might also be a hole in label B, in which case I would use something like the signed distance transform (SimpleITK: itk::simple::SignedMaurerDistanceMapImageFilter Class Reference) to decide which label should fill a particular hole.

2 Likes