I am using ITK in Python. I have a general question in dealing with 3D images.
Most of the examples in https://itk.org/ITKExamples/src/index.html are for 2D images. When I apply the code to 3D images, I got TypeError frequently.
Somehow, I realize that there is an option “IF3IF3” versus “IF2IF2” when declaring a filter, which could solve my problem.
For example, instead of using
filter = itk.GradientMagnitudeRecursiveGaussianImageFilter.New()
I should use
filter = itk.GradientMagnitudeRecursiveGaussianImageFilter.IF3IF3.New()
My first question is: whether this is the correct way to deal with 3D data?
My second question is: what is the meaning of “IF3IF3”/“IF2IF2” and “ISS3ISS3”/“ISS2ISS2”?
Thanks in advance,
Jianxu
Hi @Jianxu_Chen,
A good practice is to use:
filt = itk.GradientMagnitudeRecursiveGaussianImageFilter.New(image_or_filter)
And the filter type created will be the correct dimension for the input image
or filter
output. It will work for both 2D and 3D images.
This is the name mangling for the wrapped types. For example, IF3IF23
refers to itk::Image< float, 3 >, itk::Image< float, 3 >
. For more information on the naming scheme, see the Wrapping section of the ITK Software Guide.
Hope this helps,
Matt
For some reason, itk.GradientMagnitudeRecursiveGaussianImageFilter.New() does not work for me.
For example, I have an image, itk_img_smooth
type(itk_img_smooth)
returns itkImagePython.itkImageF3
itk_img_smooth.GetLargestPossibleRegion().GetSize()
returns itkSize3 ([149, 139, 60])
Then,
gradientMagnitude = itk.GradientMagnitudeRecursiveGaussianImageFilter.New()
gradientMagnitude.SetSigma(sigma)
gradientMagnitude.SetInput(itk_img_smooth)
gradientMagnitude.Update()
does not work. The error message is
Expecting argument of type itkImageSS2 or itkImageSourceISS2
But the following code works
gradientMagnitude = itk.GradientMagnitudeRecursiveGaussianImageFilter.IF3IF3.New()
gradientMagnitude.SetSigma(sigma)
gradientMagnitude.SetInput(itk_img_smooth)
gradientMagnitude.Update()
Oops … I know what you mean now.
I should use
gradientMagnitude = itk.GradientMagnitudeRecursiveGaussianImageFilter.New(itk_img_smooth)
gradientMagnitude.SetSigma(sigma)
gradientMagnitude.Update()
Great thanks!
Jianxu
2 Likes
Great!
Additionally, more information can be found in the Python quick start guide:
https://itkpythonpackage.readthedocs.io/en/latest/Quick_start_guide.html