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

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
I am working with 3D data, and it would be amazing if there was a High-Pass Filter for 3d arrays.

Hello @kolibril13,

The forward and inverse FFT filters are available in SimpleITK.

I suspect you want the ITK FrequencyBandImageFilter which isn’t currently wrapped. If this is correct, please create a feature request on the SimpleITK issue tracker.

2 Likes

You can find some non-trivial example code in ITKMontage. And the general recipe is: do forward FFT, do bandpass filtering in frequency domain, then apply inverse FFT.

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?

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)

Hello @kolibril13,

The ForwardFFT filter template uses the “RealPixelIDTypeList” as the input pixel type. This means that the filter is only created with float and double pixel types (see RealPixelIDTypeList definition).

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:

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