otsu_filter = sitk.OtsuThresholdImageFilter()
otsu_filter.SetInsideValue(0)
otsu_filter.SetOutsideValue(1)
binary_image = otsu_filter.Execute(input_image)
cc_filter = sitk.ConnectedComponentImageFilter()
brain_mask = cc_filter.Execute(binary_image)
label_shape_filter = sitk.LabelShapeStatisticsImageFilter()
label_shape_filter.Execute(brain_mask)
labels = label_shape_filter.GetLabels()
sizes = [label_shape_filter.GetPhysicalSize(label) for label in labels]
max_label = labels[sizes.index(max(sizes))]
binary_mask = sitk.BinaryThreshold(brain_mask, max_label, max_label, 1, 0)
brain_image = sitk.Mask(input_image, binary_mask)
Hello @arpan56,
The Otsu filter is appropriate when you have a bi-modal intensity distribution. In your case you roughly have (1) brain (2) skull (3) background, so you could try the OtsuMultipleThresholdsImageFilter., setting the number of thresholds to two. Most likely this will not work well, though better than a single threshold which doesn’t match the image content.
The operation you want to perform is known as “skull stripping”. It requires more complex algorithmic flows. See the recipe from Slicer, or this paper for a registration based approach, or this paper which describes a deep learning based approach.
Hi,
If speed isn’t a requirement, there is an example notebook in itkTubeTK that performs CTA skull stripping (not that most skull stripping methods are for MRI/MRA/CT - few work with CTA).
The approach registers 8 pre-segmented head CTA with your data, uses a voting scheme to create an initial inner and outer mask, and then uses region growing and morphological operators to skull strip. It isn’t perfect by any means, but it is typically “good”-ish.
To run the notebook, you’ll need to clone ITKTubeTK from github, pip install girder-client (https://pypi.org/project/girder-client/), and then run the ITKTubeTK/examples/Download-Data.sh script to download the 8 pre-segmented head CTAs.
Note that there is an itk module called itkSkullStripping. You can pip install it, but I had no luck getting it to work with itkv5.3 last week. It probably needs updating.
Stephen
Correct link: https://github.com/InsightSoftwareConsortium/ITKTubeTK/blob/master/examples/CTA-Head/1-SegmentBrainFromCTA.ipynb
Yes, thank you. I will look into the materials you provided.