A Colour filter error: ITK Montage Module

I encountered a similar problem like before mentioned in this thread (Stacking Z dimension images using SimpleITK - #22 by sleepingcat4) I tried to wrap and the error were persistent. Any help would be amazing : )

CODE:

print("Producing the mosaic")
resampleF = itk.TileMergeImageFilter[type(color_images[0]), itk.D].New() #  line creating the problem
resampleF.SetMontageSize(stage_tiles.GetAxisSizes())
for t in range(stage_tiles.LinearSize()):
    resampleF.SetInputTile(t, color_images[t])
    index = stage_tiles.LinearIndexToNDIndex(t)
    resampleF.SetTileTransform(index, montage.GetOutputTransform(index))
resampleF.Update()
itk.imwrite(resampleF.GetOutput(), str(output_file))
print("Resampling complete")

Error produced:

KeyError                                  Traceback (most recent call last)
File ~\AppData\Roaming\Python\Python38\site-packages\itk\support\template_class.py:525, in itkTemplate.__getitem__(self, parameters)
    524 try:
--> 525     this_item = self.__template__[key]
    526 except KeyError:

KeyError: (<class 'itk.itkImagePython.itkImageRGBUC2'>, <itkCType double>)

During handling of the above exception, another exception occurred:

TemplateTypeError                         Traceback (most recent call last)
Cell In [11], line 2
      1 print("Producing the mosaic")
----> 2 resampleF = itk.TileMergeImageFilter[type(color_images[0]), itk.D].New() #  line creating the problem
      3 resampleF.SetMontageSize(stage_tiles.GetAxisSizes())
      4 for t in range(stage_tiles.LinearSize()):

File ~\AppData\Roaming\Python\Python38\site-packages\itk\support\template_class.py:529, in itkTemplate.__getitem__(self, parameters)
    526 except KeyError:
    527     import itk
--> 529     raise itk.TemplateTypeError(self, key)
    530 return this_item

TemplateTypeError: itk.TileMergeImageFilter is not wrapped for input type `itk.Image[itk.RGBPixel[itk.UC],2], itk.D`.
...
itk.Image[itk.F,4]
itk.Image[itk.D,4]
itk.Image[itk.RGBPixel[itk.UC],4]
itk.Image[itk.RGBAPixel[itk.UC],4]

@dzenanz @zivy

What happens if you turn this into:
resampleF = itk.TileMergeImageFilter[type(color_images[0])].New()

I receive almost the same error

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
File ~\AppData\Roaming\Python\Python38\site-packages\itk\support\template_class.py:525, in itkTemplate.__getitem__(self, parameters)
    524 try:
--> 525     this_item = self.__template__[key]
    526 except KeyError:

KeyError: (<class 'itk.itkImagePython.itkImageRGBUC2'>,)

During handling of the above exception, another exception occurred:

TemplateTypeError                         Traceback (most recent call last)
Cell In [14], line 2
      1 print("Producing the mosaic")
----> 2 resampleF = itk.TileMergeImageFilter[type(color_images[0])].New() #  line creating the problem
      3 resampleF.SetMontageSize(stage_tiles.GetAxisSizes())
      4 for t in range(stage_tiles.LinearSize()):

File ~\AppData\Roaming\Python\Python38\site-packages\itk\support\template_class.py:529, in itkTemplate.__getitem__(self, parameters)
    526 except KeyError:
    527     import itk
--> 529     raise itk.TemplateTypeError(self, key)
    530 return this_item

TemplateTypeError: itk.TileMergeImageFilter is not wrapped for input type `itk.Image[itk.RGBPixel[itk.UC],2]`.
...
itk.Image[itk.F,4]
itk.Image[itk.D,4]
itk.Image[itk.RGBPixel[itk.UC],4]
itk.Image[itk.RGBAPixel[itk.UC],4]

Code

print("Producing the mosaic")
resampleF = itk.TileMergeImageFilter[type(color_images[0])].New() #  line creating the problem
resampleF.SetMontageSize(stage_tiles.GetAxisSizes())
for t in range(stage_tiles.LinearSize()):
    resampleF.SetInputTile(t, color_images[t])
    index = stage_tiles.LinearIndexToNDIndex(t)
    resampleF.SetTileTransform(index, montage.GetOutputTransform(index))
resampleF.Update()
itk.imwrite(resampleF.GetOutput(), str(output_file))
print("Resampling complete")

That filter should be wrapped for 2D images too:

Can you try this:

1 Like

thank you this works perfectly.

2 Likes