Helper Function itk.tile_image_filter Correct Usage to Convert a 2D Slice to 3D Image

I have used itk::ImageFilter<itk::Image<unsigned char, 2>, itk::Image<unsigned char, 3>> in C++ to convert a 2D slice to 3D volume in the past.

I’m trying to achieve the same ends with itk.tile_image_filter with ITK Python wrapper like this:

img_moving3d = itk.tile_image_filter(
    img_moving,
    layout=[1,1,0],  # The docs say this is how we stack along the 3rd dim.
    default_pixel_value=0.0
)

Producing this:

  File "...\Lib\site-packages\itk\itkTileImageFilterPython.py", line 1957, in SetLayout
    return _itkTileImageFilterPython.itkTileImageFilterIUC2IUC2_SetLayout(self, _arg)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
TypeError: Expecting an itkFixedArrayUI2, an int, a float, a sequence of int or a sequence of float.
python-BaseException

Which is telling the wrong template is selected: itkTileImageFilterIUC2IUC2, where I’d want this template: itkTileImageFilterIUC2IUC3.

And when I pass a list of images, as documentation suggests:

img_moving3d = itk.tile_image_filter(
    [img_moving],
    layout=[1,1,0],  # The docs say this is how we stack along the 3rd dim.
    default_pixel_value=0.0
)

Further confusion ensures:

File "...\PhantomAs3_Displacements.py", line 99, in <module>
    img_moving3d = itk.tile_image_filter(
        [img_moving],
        layout=[1,1,0],
        default_pixel_value=0.0
    )
  File "...\Lib\site-packages\itk\support\helpers.py", line 194, in image_filter_wrapper
    return image_filter(*args, **kwargs)
  File "...\Lib\site-packages\itk\itkTileImageFilterPython.py", line 3153, in tile_image_filter
    instance = itk.TileImageFilter.New(*args, **kwargs)
  File "...\Lib\site-packages\itk\support\template_class.py", line 749, in New
    raise itk.TemplateTypeError(self, input_type)
itk.support.extras.TemplateTypeError: itk.TileImageFilter is not wrapped for input type `None`.

I know I could go about it like this:

tif = itk.TileImageFilter[itk.Image[itk.UC,2], itk.Image[itk.UC,2]].New(img_moving)...
tif.SetLayout([1,1,0])

But what is the correct way of calling itk.tile_image_filter for single 2D slice to 3D output?

With that interface, the wrapper plumbing picks first available match for the input, which is 2D->2D, and not 2D->3D (what you want). I am not sure that you can get that with procedural interface. Wrapper specification is here, a simple combination of all the wrapped dimensions.

Hi,

To specify the type of the filter with the procedural interface, the ttype kwarg can be used.

1 Like