Fill “holes” in an image (T1-weighted)

Hi all!
I would like to fill holes of a binary input 3D image (cf. image and the code on it).
It’s possible with Scipy (link), but Scipy is not installed in slicer.

How could I do that?

Thanks in advance.!
Slicer_holes|690x310Slicer_holes

Dd you try the SimpleFilters module? There are a lot of hole filling options.

https://itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1BinaryFillholeImageFilter.html

https://itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1VotingBinaryIterativeHoleFillingImageFilter.html

https://itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1GrayscaleFillholeImageFilter.html

Hole filling using morphological operator is also available directly in Segment editor (in Smoothing effect).

Perfect. Thanks @pieper and @lassoan
For the next, the script is:

segmentEditorWidget.setActiveEffectByName("Smoothing")
effect = segmentEditorWidget.activeEffect()
effect.setParameter("SmoothingMethod", "MORPHOLOGICAL_CLOSING")
effect.setParameter("KernelSizeMm", 20)
1 Like

I allow myself to come back to your reply @lassoan @pieper .
This answer works but take a long time, is there a quicker way to fill the holes of a 3d model (or remove “the back-facing element”)?
Thanks in advance.

Kernel size of 20mm is extremely large! It is normal that it takes very long time to compute.

To remove internal holes from a segment, you may apply smoothing, then invert the segment, keep largest island, invert it back to get rid of most internal structures. If there are structures that are connected to the outside air (e.g., airways) then you can manually seal them off, to make them internal (disconnected from outside).

To extract skin, you should be able to use Flood fill effect (in SegmentEditorExtraEffects extension). Click in the air to create a segment (you can adjust neighborhood size to prevent leaking inside the body through small holes, like airways) and then invert the segment to get the skin surface.

I’ve created a repository where I’ll upload segmentation recipes and added detailed description of skin segmentation: https://lassoan.github.io/SlicerSegmentationRecipes/SkinSurface/

1 Like

Nice process and example Andras, thanks.
However, I use your previous script routinely and I do not want to make it manually (scissors, …).
Best.

If you find that Flood fill works better than thresholding, then you can use that from script, too. Scissors, smoothing, etc. are all optional post-processing that may improve quality of thresholding or flood-filling results.

Ok, I will try the two options.
thanks Andras.

1 Like