### How To Use Bandreject Filters – C# Guide

We use bandreject filters to attenuate a ring of frequencies around the center of a 2 dimensional frequency map. Now what does all that mean? We’re going to focus on...

Filter by Category

- C# Tutorial(41)
- C# Image Processing(26)
- Image Processing(16)
- Image Restoration and Reconstruction(15)
- Frequency Domain Filtering(8)
- Image Noise(6)
- Mean Filters(4)
- Order-Statistic Filters(4)
- Landing Pages(1)
- Social Games(1)
- Bandreject Filters(1)
- Bandpass filters(1)
- Notch Filters(1)
- Adaptive Filters(1)

Back to Latest Articles
###
How To Use Bandreject Filters – C# Guide

###
How To Use Laplacian Filter – C# Guide

###
How To Use Gaussian Highpass Filter – C# Guide

###
How To Use Butterworth Highpass Filter – C# Guide

###
How To Use Ideal Highpass Filter – C# Guide

###
How To Use Gaussian Lowpass Filter – C# Guide

###
How To Use Butterworth Lowpass Filter – C# Guide

###
How To Use Ideal Lowpass Filter With FFT – C# Guide

###
How To Use Fourier Transform On Images – C# Guide

###
Histogram Equalization And Magic Behind It

Frequency Domain Filtering

We use bandreject filters to attenuate a ring of frequencies around the center of a 2 dimensional frequency map. Now what does all that mean? We’re going to focus on...

Frequency Domain Filtering

We use Laplacian filter to sharpen images. We are going to talk about the details how exactly this filter works. In essence, it’s one of the highpass filters, which...

C# Tutorial

Gaussian highpass filter processes images in frequency domain. It attenuates low frequencies without creating ringing artifacts.

C# Tutorial

Butterworth highpass filter is used to filter images in frequency domain. We can control how smooth transition beyond cut off frequency.

C# Tutorial

Ideal highpass filter is used to filter images in the frequency domain. It attenuates low frequencies and keeps high frequencies.

C# Tutorial

We’ve talked about ideal lowpass filter and Butterworth lowpass filter already. And now, we shall get to know the last type of lowpass filters, which is Gaussian lowpass...

C# Image Processing

Butterworth lowpass filter is used to modify images in the frequency domain.

C# Image Processing

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....

C# Image Processing

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

C# tutorial on how to achieve histogram equalization on an image.

How To Use Bandreject Filters – C#...

We use bandreject filters to attenuate a ring of frequencies around the center of a 2 dimensional frequency map.

*Now what does all that mean?*

We’re going to focus on filtering images in the frequency domain. Firstly, we need to transform image data into frequency domain with Fourier transform. In case you’re not familiar with the transform, it takes a 2 dimensional map of image data and transforms it into a 2 dimensional map of frequency data the same size as the image. So we need to use it 3 times for each image to process all 3 color channel.

Secondly, any kind of filtering in the frequency domain works by multiplying filter formula with all of the values in the frequency map. These formulas contain parameters that set the location of the frequencies we want to attenuate.

There are three bandreject filters we can use, which differ in the transition between passed and attenuated frequencies. These three filters are Ideal, Butterworth and Gaussian bandreject filters.

Bandreject filters work similarly to lowpass filters. The Difference being that bandreject filters attenuate frequencies before cut off frequency as well.

This filter’s formula isn’t all that complicated. The transition between attenuated and passed frequencies is instant.

Let’s also take a look at the code that makes this work.

```
public static Complex[][][] IdealBandrejectFilter(Complex[][][] frequencies, double d0, double W)
{
Complex[][][] filtered = frequencies;
for (int i = 0; i < 3; i++)
{
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 >= (d0 - W/2) && d <= (d0 + W/2))
{
filtered[i][u][v] *= 0f;
}
}
}
}
```` return filtered; }`

To put this into words, the frequencies that are located in the ring are removed. We can control the width of the ring with parameter *W* and radius by parameter *d0*.

With this filter we’re able to control a little bit more. In addition, we can use an additional parameter which is the order of the filter. If we set order to be low, like 2 or 3, it will act more like a Gaussian filter. But if we set it high, like 20, it will act like an ideal filter. It controls how smooth the transition between attenuated and passed frequencies is.

Because of a larger cut off frequency and smooth transition between frequencies the effect looks faintly visible.

Butterworth bandreject filter also has its own formula.

As we mentioned before at the ideal bandreject filter, *W* and *D _{0} *stand for width of the ring and radius of cut off frequency, respectively.

Here M and N represent the dimensions of the frequency map, width and height.

Let’s take a look at the C# function that applies it.

```
public static Complex[][][] ButterworthBandrejectFilter(Complex[][][] frequencies, double d0, int n, double W)
{
Complex[][][] filtered = frequencies;
for (int i = 0; i < 3; i++)
{
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)));
filtered[i][u][v] *= (float)(1f / (1 + Math.Pow(d * W / (d
```*d - d0*d0), 2 * n)));
}
}
}
` return filtered;`

` }`

Gaussian bandreject filter lays on the other line of the spectrum where these three differ between each other. In other words the smoothness of the transition between attenuated and passed frequencies.

This filter has the smoothest transition and it can’t be controlled apart by setting the cut off frequency lower or higher. Therefore in that regard it’s a complete opposite from ideal bandreject filter we described earlier.

The parameters in the formula above, each stand for the same thing as in the Butterworth formula we described above.

Let’s take a look at the code that applies it as well.

```
public static Complex[][][] GaussianBandrejectFilter(Complex[][][] frequencies, double d0, double W)
{
Complex[][][] filtered = frequencies;
for (int i = 0; i < 3; i++)
{
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)));
filtered[i][u][v] *= (float)(1 - Math.Pow(Math.E, -(Math.Pow((Math.Pow(d, 2) - Math.Pow(d0, 2)) / d * W, 2))));
}
}
}
```` return filtered;`

` }`

Band reject filters are a stepping stone to band pass filters and notch filters. However, we will take a look at those in other posts. I hope this guide was helpful and instructive and I hope you’ll tune in on the next one.

You can **download the project** and try out the demonstration yourself.

## Comments