SWIG TypeError when using the python version of ITKIsotropicWavelets


I am trying to reproduce the example runRieszWaveletAnalysis from the ITKIsotropicWavelets repository using Python. I installed the package using the pip command. I ran into an error when trying to generate a monogenic signal from an analysis wavelet.

# Forward Wavelet
ForwardWaveletType = itk.WaveletFrequencyForward[ComplexImageType, ComplexImageType, WaveletFilterBankType]

forwardWavelet = ForwardWaveletType.New(fftForwardFilter.GetOutput())

analysisWavelets = forwardWavelet.GetOutputs()

# Perform the monogenic signal frequency analysis
monoFilter = itk.MonogenicSignalFrequencyImageFilter[ComplexImageType].New()

TypeError                                 Traceback (most recent call last)
<ipython-input-192-f125def2e1c0> in <module>
      7     # Perform the monogenic signal frequency analysis
      8     monoFilter = itk.MonogenicSignalFrequencyImageFilter[ComplexImageType].New()
----> 9     monoFilter.SetInput(analysisWavelets[0])

TypeError: in method 'itkImageToImageFilterICF2VICF2_SetInput', argument 2 of type 'itkImageCF2 const *'

I suspect that the problem is due to the output type obtained from the WaveletFrequencyForward decomposition. When using GetOutputs(), a tuple is returned containing the decomposition at each level. These are of type : *<Swig Object of type 'itkImageCF2_Pointer ’ at 0x0000025CE7F568D0>
but the MonogenicSignalFrequencyFilter expects an input type of either [<class ‘itkImagePython.itkImageCF2’>,] or [<class ‘itkImagePython.itkImageCF3’>,].

How can I access the wavelet components within the Swig Object to be able to be used by the monoFilter?


@phcerdan can best answer this question.

I think GetOutputs might be a helper method for C++, try to directly use GetOutput() in the filter, that should be of the right type. There are helper functions to get a level/band pair from the linear index, and vice versa. For example:

# analysisWavelets = forwardWavelet.GetOutputs()
max_coeff = bands * levels + 1
for coeff_index in range(0, max_coeff):
  level_band = forwardWavelet.OutputIndexToLevelBand(coeff_index)
  print('level, band: ' , level_band )
  wavelet_coeff = forwardWavelet.GetOutput(coeff_index)
  # ...

Thank you, that solved the problem. I used the same indexing approach for the inverseWavelet part of the example, and I was able to reproduce the result shown in the ITK paper using Python.


That’s great, thanks for taking the effort to reproduce it in python @joe-from-mtl. If you keep that python code sweet and simple, it could be the starting point for adding some python examples to the module :slight_smile:

1 Like