Datatype error

Hello,

I try to implement several filters in SITK for 3D images, but I do get an error with the Anisotropic diffusion image filter. (The Gaussian, median and curvature flow are working :slight_smile: )

def calc_anisotropicdiff(img, iterations=5, step=0.125, conductance=3):
""" The Gradient Anisotropic diffusion image filter. """
blurFilter = sitk.GradientAnisotropicDiffusionImageFilter()
blurFilter.SetNumberOfIterations(iterations)
blurFilter.SetTimeStep(step)
blurFilter.SetConductanceParameter(conductance)
imgSmooth = blurFilter.Execute(img)
return imgSmooth

The error is:

RuntimeError: Exception thrown in SimpleITK GradientAnisotropicDiffusionImageFilter_Execute: d:\a\1\sitk\code\common\include\sitkMemberFunctionFactory.hxx:196:

sitk::ERROR: Pixel type: 8-bit unsigned integer is not supported in 3D byclass itk::simple::GradientAnisotropicDiffusionImageFilter

So I tried to change my pixeltypes from uint8 to sitk.sitkFloat64, but now my image is completely black (instead of grayscale image).

Is it possible to change the datatype from unit8 to float64?

Hello @Romy_Meester,

Not sure how you are changing the pixel type, are you using the Cast filter:

img = sitk.ReadImage(file_name)
sitk.Show(img)
sitk.Show(sitk.Cast(img,sitk.sitkFloat64))

or you can force a type on read:

img = sitk.ReadImage(file_name, sitk.sitkFloat64)

Also, I noticed from your other post that you are creating functions and using the object oriented interface inside of them. SimpleITK supports a procedural interface for most, if not all, filters. So you don’t need to do this. For example, the WienerDeconvolutionImageFilter class and the WienerDeconvolutionImageFilter function, the GradientAnisotropicDiffusionImageFilter class and the GradientAnisotropicDiffusionImageFilter function. The easiest way to find if there is a procedural interface for a class is to go to the class documentation page and search for the word “procedural”.

1 Like

Yes,

sitk.Cast(img,sitk.sitkFloat64)

Solved the problem