no itk.join_image_filter in ITK 5.1.2

It seems the itk::JoinImageFilter is not wrapped to python (yet). I could not find it in the 5.1.2 release.
Is there a list of filters which have been wrapped?

I would expect a class named itk.join_image_filter. The only filter in itk with join in the name, is join_series_image_filter. I think that filter results in a different ordering of the data though.

I am trying to join components of a tensor image (stored as scalar images) and thought it a good task to start using the python interface instead of c++.

Is there an alternative or way to join the image components?

  • I tried
    join_filter = itk.JoinImageFilter[type(components[0]), itk.Image[itk.F, 6]].New()
    but itk.JoinImageFilter also is not available.

  • I also tried to stack the images with numpy:
    tensor_image = np.stack([itk.array_view_from_image(c) for c in components], axis=3) but
    itk.image_view_from_array(tensor_image, is_vector=True) fails (error pasted below)

Should I create an issue on github?

Traceback (most recent call last):
File “E:\Develop\Scripts\MIDA_dti.venv\lib\site-packages\itkTemplate.py”, line 336, in getitem
return(self.template[tuple(cleanParameters)])
KeyError: (, 4)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “E:\Develop\Scripts\MIDA_dti.venv\lib\site-packages\itkTemplate.py”, line 340, in getitem
return(self.template[tuple(cleanParameters)])
KeyError: (, 4)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “make_tensor_image.py”, line 18, in
itk.image_view_from_array(tensor_image)
File “E:\Develop\Scripts\MIDA_dti.venv\lib\site-packages\itkExtras.py”, line 299, in GetImageViewFromArray
return _GetImageFromArray(arr, “GetImageViewFromArray”, is_vector)
File “E:\Develop\Scripts\MIDA_dti.venv\lib\site-packages\itkExtras.py”, line 272, in _GetImageFromArray
ImageType = itk.Image[PixelType, Dimension]
File “E:\Develop\Scripts\MIDA_dti.venv\lib\site-packages\itkTemplate.py”, line 342, in getitem
raise TemplateTypeError(self, tuple(cleanParameters))
itkTemplate.TemplateTypeError: itk.Image is not wrapped for input type itk.F, int.

To limit the size of the package, only a limited number of
types are available in ITK Python. To print the supported
types, run the following command in your python environment:

itk.Image.GetTypes()

Possible solutions:

  • If you are an application user:
    ** Convert your input image into a supported format (see below).
    ** Contact developer to report the issue.

  • If you are an application developer, force input images to be
    loaded in a supported pixel type.

    e.g.: instance = itk.Image[itk.RGBPixel[itk.UC], int].New(my_input)

  • (Advanced) If you are an application developer, build ITK Python yourself and
    turned to ON the corresponding CMake option to wrap the pixel type or image
    dimension you need. When configuring ITK with CMake, you can set
    ITK_WRAP_${type} (replace ${type} with appropriate pixel type such as
    double). If you need to support images with 4 or 5 dimensions, you can add
    these dimensions to the list of dimensions in the CMake variable
    ITK_WRAP_IMAGE_DIMS.

Supported input types:

itk.RGBPixel[itk.UC]
itk.RGBAPixel[itk.UC]
itk.Vector[itk.F,2]
itk.Vector[itk.F,3]
itk.Vector[itk.F,4]
itk.CovariantVector[itk.F,2]
itk.CovariantVector[itk.F,3]

btw. I see in the list of supported pixel types that vector with 6 components are not listed. I think the only pixel type in that list that has 6 values is the 3d symmetric second rank tensor.
However, the API of image_view_from_array and image_from_array doesn’t seem to allow to specify the pixel type explicitly.

it seems even if I get the components into a tensor image, the image writer is not wrapped for this type:

itkTemplate.TemplateTypeError: itk.ImageFileWriter is not wrapped for input type itk.Image[itk.SymmetricSecondRankTensor[itk.D,3],3].

While the pixel type is listed in the itk.Image.GetTypes(), it seems the image writer does not support the same set of image types.

Have you tried compiling ITK yourself? That way you can turn on extra wrapping options.

ITK 5.2, whose release candidate is coming up, has more support for vector pixel types in these functions and in an image.astype function.

While we can add more wrapping for join_image_filter, but combining scalar images into a multi-component image is already supported with itk.compose_image_filter. For example,

arrays = [component1, component2, component3]
together = itk.compose_image_filter(*arrays)

# or
images = [itk.image_view_from_array(a) for a in arrays]
together = itk.compose_image_filter(*images)