How To Use Ideal Lowpass Filter With FFT – C# Guide
Ideal lowpass filter is a filter used to modify frequency values in the frequency domain, and for transforming an image into a frequency domain, we have to use Fourier transform....
Filter by Category
Ideal lowpass filter is a filter used to modify frequency values in the frequency domain, and for transforming an image into a frequency domain, we have to use Fourier transform....
Fourier transform is an equation that turns normal pixel values into complex numbers. But to know what these complex numbers mean, we should give a little more context to them by...
C# tutorial on how to achieve histogram equalization on an image.
In this tutorial we will be talking about intensity level slicing in image processing. What is Intensity Level Slicing It’s a process that highlights pixels in an arbitrary...
This post is a short revision of Contrast Stretch post we already worked on in the past. Where we talked about histogram equalization, which is a little more complex method than...
What is Log Transformation Anyway? Log transformation in image processing is a part of gray level transformations. It works by transforming each pixel individually. It is usually...
Where Do We Start? There are numerous ways you can flip an image horizontally. It’s pretty basic functionality in image processing. I wanted to challenge myself and not just...
Let’s Get Started A very basic problem that we face in image processing is how to scale images without making them look deformed when we want to make it of an arbitrary...
List of contents: Short intro First Method – Google Opinion Rewards Second Method – Taking & Fortifying Gyms Third Method – Answer a Few Questions List of...
Zero padding an image is useful when we’re convolving it with a filter of certain size. How much padding should we use depends on how big our filter is. What is the purpose...
Ideal lowpass filter is a filter used to modify frequency values in the frequency domain, and for transforming an image into a frequency domain, we have to use Fourier transform.
We can also use inverse of the transform to get back the values in spatial domain. Images as we see them everyday on the internet are in the spatial domain.
Once we transform an image into frequency domain, we get complex number values. To be more precise, we get a map of values, which is the same size as the image we transformed.
In the example where I showed how to use Fourier transform, the code processes only one color channel. And for Fast Fourier Transform (FFT) algorithm, you can only pass through square images.
So to make the program process images of all sizes, I’ve created a function that creates zero padding around the image to make it square. The dimensions must also be of size 2n for the algorithm to work. These are the constraints that come with the calculation speed of the FFT algorithm.
Because the FFT processes only one channel at a time I’ve grayscaled the image beforehand. In this new example I’ve added to it a little bit.
For one, I’ve written a function that removes zero padding from the image once it’s transformed back to spatial domain. Another thing was to make the program use FFT function three times per image, once per color channel.
We’ve talked about how transformation works, now let’s get into how processing data in frequency domain does.
There’s a correlation between processing data in spatial domain and frequency domain, we call it convolutional theorem. Sounds familiar right?
We used convolution for processing images in the previous tutorials before. It’s basically multiplication of filter and pixel channel values. Because filter is much smaller in size than the image, we need to slide it across the entire image.
How does this theory connect with processing in frequency domain?
As it turns out, convolution in spatial domain yields the same results as element wise multiplication in the frequency domain.
Filters in the frequency domain are not the same as in spatial domain as they span the whole image in size.
Ideal lowpass filter is one of the most basic filters we can use in frequency domain. We need to set a diameter of a circle located in the middle and use it to pass frequencies that fall inside the circle, while setting freqiencies outside to 0.
If we delete the lower frequencies as ideal lowpass filter does, we will get a blurred image and the smaller the circle in the middle is, the bigger the blurring of our image will be.
public static Complex[][][] Ideal_Lowpass_Filter(Complex[][][] frequencies, double diameter)
{
int channels = 3;
Complex[][][] filtered = frequencies;
for (int c = 0; c < channels; c++)
{
for (int u = 0; u < Size; u++)
{
for (int v = 0; v < Size; v++)
{
double d = Math.Sqrt(Math.Pow(u - Size / 2, 2) + Math.Pow(v - Size / 2, 2));
if (d <= diameter)
{
filtered[c][u][v] = frequencies[c][u][v];
}
else
{
filtered[c][u][v] = new Complex(0, 0);
}
}
}
}
return filtered;
}
Function above takes a jagged array of complex numbers which, in our case, are all frequency values from an image.
This tutorial was an introduction into filtering images in frequency domain. Hopefully you found it understandable and you’re looking forward for the next one. You can download the entire project for free and try it out for yourself.