SimpleFilter Image Error Type

Hello everyone,

I’d like to share a problem I am recurrently facing.
I load an image and try to use some simple filters inside ITKSImpleFilters modue.
I try to convert, rescale and many other transformations over the image, but I still get the same error.
What is worse is that the filters do not say what is the pixel type they expect.

Following some screenshots from an example, I try to use the gradientAnisotropicDuffusionFilter with a .tiff (0-255) image.

Any comments are welcomed.

Error:
error

Image Details by 3D Slicer:
info

Image used:

Firstly, if it is just the gradientAnisotropicDiffusionFilter you need try using the actual slicer module for this (not under the Simple Filters area). Click the Modules drop down box in the top left area of the slicer window, look under “Filtering” , then look under “Denoising”. Alternatively just search the for the module using the search function (little magnifying glass icon). This module does seem fussy about having an 8 bit integer input.

If you do need to use the Simple ITK filter for some reason, I think the problem is that Simple ITK filters need to do maths on the pixel values i.e. multiplication, division etc. I am not an expert in programming but I am pretty sure you can’t, for example, do division on integer numbers. For example, 3/2 = 1.5 (1.5 is no longer an integer number). So you need to convert your volume to have floating point pixel values. You can use the Cast Scalar Volume module to convert your volume to “Float” (or maybe “Double” I cant remember off the top of my head) before using other Simple ITK filters.

image

I am pretty sure there is a cast filter under “Simple Filters” as well

1 Like

@Juicy is right, the problem is the datatype, and casting or using the alternate filter implementation are good solutions.

The reason for all this is that when SimpleITK classes are wrapped for python, there’s extra code size and compilation time for each pixel type so only the ones that make sense for a filter are available.

As a general rule for SimpleFilters, I guess the expectation was that people who understood what the filter tries to do would get the idea about what data types are needed, but if you need to know the information is admittedly pretty obscure and as far as I know it’s never been exposed in the UI (probably it should, in case anyone wants to contribute a feature to inform the user or cast automatically).

The info itself is in the JSON files in this directory.

For this case it’s this line:

RealPixelIDTypeList and other keywords are defined here, so it’s float and double:

1 Like

Conversion from input voxel type to supported voxel type should be a low-level SimpleITK feature. If automatic conversion was implemented in SimpleFilters module, users would be inconvenienced when they try to use SimpleITK filters in Python scripts.

@blowekamp do you plan to address this issue in SimpleITK?