# SWIG TypeError when using the python version of ITKIsotropicWavelets

**URL:** https://discourse.itk.org/t/swig-typeerror-when-using-the-python-version-of-itkisotropicwavelets/2791
**Category:** Beginner Questions
**Tags:** python
**Created:** [March 5, 2020, 4:16pm UTC](https://discourse.itk.org/t/swig-typeerror-when-using-the-python-version-of-itkisotropicwavelets/2791 "2020-03-05T16:16:55Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![joe-from-mtl](https://discourse.itk.org/user_avatar/discourse.itk.org/joe-from-mtl/32/1277_2.png) [@joe-from-mtl](https://discourse.itk.org/u/joe-from-mtl)
#### Post date: [March 5, 2020, 4:16pm UTC](https://discourse.itk.org/t/swig-typeerror-when-using-the-python-version-of-itkisotropicwavelets/2791/1 "2020-03-05T16:16:55Z")

</div>

Hi,

I am trying to reproduce the example **runRieszWaveletAnalysis** from the [ITKIsotropicWavelets repository](https://github.com/phcerdan/ITKIsotropicWavelets) 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())
forwardWavelet.SetHighPassSubBands(2)
forwardWavelet.SetLevels(2)
forwardWavelet.Update()

analysisWavelets = forwardWavelet.GetOutputs()

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

---------------------------------------------------------------------------
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])
     10 

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?

Thanks

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [March 5, 2020, 4:24pm UTC](https://discourse.itk.org/t/swig-typeerror-when-using-the-python-version-of-itkisotropicwavelets/2791/2 "2020-03-05T16:24:45Z")

</div>

@phcerdan can best answer this question.

---

<div class="post-metadata">

### Author: ![phcerdan](https://discourse.itk.org/user_avatar/discourse.itk.org/phcerdan/32/286_2.png) [@phcerdan](https://discourse.itk.org/u/phcerdan)
#### Post date: [March 5, 2020, 5:13pm UTC](https://discourse.itk.org/t/swig-typeerror-when-using-the-python-version-of-itkisotropicwavelets/2791/3 "2020-03-05T17:13:28Z")

</div>

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:

```python
# 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)
  # ...
  monoFilter.SetInput(wavelet_coeff)

```

---

<div class="post-metadata">

### Author: ![joe-from-mtl](https://discourse.itk.org/user_avatar/discourse.itk.org/joe-from-mtl/32/1277_2.png) [@joe-from-mtl](https://discourse.itk.org/u/joe-from-mtl)
#### Post date: [March 5, 2020, 7:46pm UTC](https://discourse.itk.org/t/swig-typeerror-when-using-the-python-version-of-itkisotropicwavelets/2791/4 "2020-03-05T19:46:34Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![phcerdan](https://discourse.itk.org/user_avatar/discourse.itk.org/phcerdan/32/286_2.png) [@phcerdan](https://discourse.itk.org/u/phcerdan)
#### Post date: [March 5, 2020, 11:45pm UTC](https://discourse.itk.org/t/swig-typeerror-when-using-the-python-version-of-itkisotropicwavelets/2791/5 "2020-03-05T23:45:41Z")

</div>

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](https://github.com/InsightSoftwareConsortium/ITKIsotropicWavelets) 🙂
