Skull stripping with python/simpleITK

Question:

I’m trying to perform a skull stripping with simpleITK in python.
I’m using the StripTsImageFilter function as follows:

#upload data
# Path of nii img
path = r'C:UsersKateJupyterDataThesisPROGRESSION003fet.nii.gz'

# Read the .nii image with SimpleITK:
img = sitk.ReadImage(path)

#read atlas and atlasmap
#Obtained from 3DSlicer documentation: https://www.slicer.org/wiki/Documentation/Nightly/Modules/SwissSkullStripper

atlas = sitk.ReadImage(r'C:UsersKateJupyterthesisatlasImage.mha')
atlasMask = sitk.ReadImage(r'C:UsersKateJupyterthesisatlasMask.mha')

#Skull stripping 
#https://www.istb.unibe.ch/e43946/e43949/e158631/e187931/pane187932/e187939/files187941/article_eng.pdf

brainMask = sitk.StripTsImageFilter(img, atlas, atlasMask)

I get the error ‘AttributeError: module ‘SimpleITK’ has no attribute ‘StripTsImageFilter”
I have tried implementing img.StripTsImageFilter and tried using sitk.SkullStrip.StripTsFilter as well.

Does anyone know how to solve this?

Asked By: Kate

||

Answers:

StripTsImageFilter is a ‘remote’ module for ITK. So it is not wrapped by SimpleITK and is not even built by default in ITK.

To gain access to it in Python you’re going to have to use ITK’s Python wrapping, and you’re going to have to build ITK-Python yourself, since it is not in the pre-build ITK-Python on PyPi.

Answered By: Dave Chen

As Dave pointed out, the StripTsImageFilter is included in SimpleITK (or ‘raw’ ITK) by default. You can install the remote module from PyPi like so:

pip install itk-skullstripping

More information is available here:
https://github.com/InsightSoftwareConsortium/ITKSkullStrip

Converting itk to sitk and back is explained here: https://discourse.itk.org/t/in-python-how-to-convert-between-simpleitk-and-itk-images/1922

Answered By: dyoll
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.