# Is there a function for High and Lowpass filtering in SITK?

**URL:** <https://discourse.itk.org/t/is-there-a-function-for-high-and-lowpass-filtering-in-sitk/4541>\
**Category:** Beginner Questions\
**Tags:** simpleitk, python\
**Created:** [November 1, 2021, 6:41pm UTC](https://discourse.itk.org/t/is-there-a-function-for-high-and-lowpass-filtering-in-sitk/4541 "2021-11-01T18:41:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kolibril13](https://discourse.itk.org/user_avatar/discourse.itk.org/kolibril13/32/2326_2.png) [@kolibril13](https://discourse.itk.org/u/kolibril13)\
**Post date:** [November 1, 2021, 6:41pm UTC](https://discourse.itk.org/t/is-there-a-function-for-high-and-lowpass-filtering-in-sitk/4541/1 "2021-11-01T18:41:07Z")

</div>

Is there any Filter to manipulate the frequency domain of an image/stack in sitk?  
I could not find one here:  
[https://simpleitk.readthedocs.io/en/master/filters.html](https://simpleitk.readthedocs.io/en/master/filters.html)  
I am working with 3D data, and it would be amazing if there was a High-Pass Filter for 3d arrays.

---

<div class="post-metadata">

**Author:** ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)\
**Post date:** [November 1, 2021, 7:05pm UTC](https://discourse.itk.org/t/is-there-a-function-for-high-and-lowpass-filtering-in-sitk/4541/2 "2021-11-01T19:05:07Z")

</div>

Hello @kolibril13,

The [forward](https://simpleitk.org/doxygen/latest/html/classitk_1_1simple_1_1ForwardFFTImageFilter.html) and [inverse](https://simpleitk.org/doxygen/latest/html/classitk_1_1simple_1_1InverseFFTImageFilter.html) FFT filters are available in SimpleITK.

I suspect you want the ITK [FrequencyBandImageFilter](https://itk.org/Doxygen/html/classitk_1_1FrequencyBandImageFilter.html) which isn’t currently wrapped. If this is correct, please create a feature request on the [SimpleITK issue tracker](https://github.com/SimpleITK/SimpleITK/issues).

---

<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:** [November 1, 2021, 7:14pm UTC](https://discourse.itk.org/t/is-there-a-function-for-high-and-lowpass-filtering-in-sitk/4541/3 "2021-11-01T19:14:52Z")

</div>

You can find some non-trivial example code in [ITKMontage](https://github.com/InsightSoftwareConsortium/ITKMontage/blob/v0.7.3/include/itkPhaseCorrelationImageRegistrationMethod.hxx#L445-L458). And the general recipe is: do forward FFT, do bandpass filtering in frequency domain, then apply inverse FFT.

---

<div class="post-metadata">

**Author:** ![kolibril13](https://discourse.itk.org/user_avatar/discourse.itk.org/kolibril13/32/2326_2.png) [@kolibril13](https://discourse.itk.org/u/kolibril13)\
**Post date:** [November 1, 2021, 10:09pm UTC](https://discourse.itk.org/t/is-there-a-function-for-high-and-lowpass-filtering-in-sitk/4541/4 "2021-11-01T22:09:41Z")

</div>

Thanks for your fast feedback!  
Regarding the implementation, I will go to the Fourier domain, then apply a Gaussian mask, and filter back. But do you know if there is any way to do this without converting my image to float?

```auto
import SimpleITK as sitk
import matplotlib.pyplot as plt
from skimage import data
import numpy as np
image_sklearn = data.camera()
image_sklearn=image_sklearn.astype(float) # when this line is not there: sitk::ERROR: Pixel type: 8-bit unsigned integer is not supported in 2D by N3itk6simple21ForwardFFTImageFilterE.
img=sitk.GetImageFromArray(image_sklearn)
to_fourier=sitk.ForwardFFTImageFilter()
my_img = to_fourier.Execute(img)
plt.imshow(sitk.GetArrayFromImage(my_img).real)

```

---

<div class="post-metadata">

**Author:** ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)\
**Post date:** [November 2, 2021, 12:59pm UTC](https://discourse.itk.org/t/is-there-a-function-for-high-and-lowpass-filtering-in-sitk/4541/5 "2021-11-02T12:59:30Z")

</div>

Hello @kolibril13,

The ForwardFFT filter template uses the “[RealPixelIDTypeList](https://github.com/SimpleITK/SimpleITK/blob/f2a4d7303404bfd9b27a54a7f5fd2246ff92bdba/Code/BasicFilters/json/ForwardFFTImageFilter.json#L7)” as the input pixel type. This means that the filter is only created with float and double pixel types (see [RealPixelIDTypeList definition](https://github.com/SimpleITK/SimpleITK/blob/aff11ddc90bde4cc1669bb54a60dec52d50c0507/Code/Common/include/sitkPixelIDTypeLists.h#L98)).

Unfortunately, this means you will need to do the conversion. The Python float is actually the C++ double type (64bit), so if short on memory you may want to replace the current conversion with:

```auto
image_sklearn = data.camera()
img = sitk.Cast(sitk.GetImageFromArray(image_sklearn), sitk.sitkFloat32) 

```
