**Band Pass Filters in Image Preprocessing**

Assume you’re in your collage festival where various different artists perform at several different stages and each artist performs on different theme, there is mesh of sounds and music around you but you want to focus on energetic rock music coming from one specific stage, and filter other sounds which seems noise for you when you’re trying to focus is on particular type of music which is rock in our example, band pass acts as filter that keeps range of specific frequencies you want to hear clearly for better experience. Similarly in images whenever our objective is to highlight specific type of properties of image, band pass filter mask adjusts the settings, for attenuating frequencies outside the desired passband while allowing those within the passband to pass through with minimal change. With which we essentially “mute” the unwanted frequencies in the image, enhancing the details within the chosen frequency range.

**What is Band pass filter?**

As name suggests ‘band pass’ it means that it is type of filter in image preprocessing which pass only range (band) of frequencies within an image while attenuating frequencies outside that band. It is used for dropping certain frequency components from the image. For example, in aerial images it may use to highlight certain patterns from the image.

**Popular band pass filters**

**Gaussian Bandpass Filter**

*Use Case: Commonly used for noise reduction while preserving edges and fine details.*

**Butterworth Bandpass Filter**

*Use Case: Commonly used for motion analysis*

**Chebyshev Bandpass Filter**

*Use Case: Commonly used for sharper transition between passband and stopband is required*

**FIR (Finite Impulse Response) Bandpass Filter**

*Use Case: Commonly used for biomedical signal processing, and seismic data analysis.*

IIR (Infinite Impulse Response) Bandpass Filter:

*Use Case: Commonly used where low latency is crucial.*

**Types of Band pass filters**

Fourier Transform Based Filters

Wavelet Transform Based Filters

Spatial Domain Filters

Frequency Domain Filters

**Numerical Example**

This example demonstrates applying a Butterworth band-pass filter to a 3x3 image matrix.

**Image Matrix:**

[[50,60,70], [80,90,100], [110,120,130]]

Parameters: 0.3 to 0.6 (frequency) and filter order 2

**Steps:**

**Frequency Domain Representation:**

Apply the Discrete Fourier Transform (DFT) to the image matrix to obtain its frequency domain representation.

**Butterworth Band-Pass Filter Mask:**

The Butterworth filter response (H (u, v)) for frequency domain coordinates (u, v) is defined as:

H(u, v) = 1 / (1 + (D(u, v) / fc1)^n * (D(u, v) / fc2)^n)

where:

- D (u, v) is the distance from (u, v) to the center of the frequency domain (often normalized).
- fc1 and fc2 are the lower and upper cutoff frequencies of the passband, respectively.
- n is the filter order.

- Calculate D (u, v) for each frequency domain coordinate using the Euclidean distance formula.
- Calculate H (u, v) for each coordinate using the given filter parameters (passband frequencies and filter order). This will create a 3x3 filter mask representing the frequency response of the Butterworth band-pass filter.

**Applying the Filter:**

3. Multiply the image’s frequency domain representation (obtained in step 1) element-wise with the Butterworth band-pass filter mask created in step 2. This effectively applies the band-pass filter, attenuating frequencies outside the desired passband.

**Inverse Transform:**

- Apply the Inverse Discrete Fourier Transform (IDFT) to the filtered frequency domain representation obtained in step 3. This transforms the result back into the spatial domain, giving the filtered image matrix.

**Outcome:**

Matrix frequencies outside 0.3 to 0.6 are attenuated, which potentially suppress low-frequency background information and high-frequency noise while preserving mid-range details and edges in the image.

**Python implementation**

import numpy as np

import matplotlib.pyplot as plt

from scipy import signal

from skimage import data, img_as_float

from skimage.color import rgb2gray

def butterworth_bandpass_filter(image, low_cutoff, high_cutoff, order=5):

if len(image.shape) == 3:

image = rgb2gray(image)

rows, cols = image.shape

center_row, center_col = rows // 2, cols // 2

r, c = np.mgrid[:rows, :cols]

d = np.sqrt((r — center_row)**2 + (c — center_col)**2)

low_pass = 1 / (1 + (d / high_cutoff)**(2 * order))

high_pass = 1 / (1 + (low_cutoff / d)**(2 * order))

band_pass = high_pass * low_pass

image_fft = np.fft.fft2(image)

filtered_image_fft = image_fft * band_pass

filtered_image = np.fft.ifft2(filtered_image_fft).real

return filtered_image

image = img_as_float(data.camera())

low_cutoff = 0.1

high_cutoff = 0.5

order = 5

filtered_image = butterworth_bandpass_filter(image, low_cutoff, high_cutoff, order)

fig, axes = plt.subplots(1, 2, figsize=(10, 5))

axes[0].imshow(image, cmap=’gray’)

axes[0].set_title(‘Original Image’)

axes[0].axis(‘off’)

axes[1].imshow(filtered_image, cmap=’gray’)

axes[1].set_title(‘Filtered Image’)

axes[1].axis(‘off’)

plt.show()

**Advantages of Band-Pass Filters**

**Selective Filtering:**Offers to focus on the frequencies of interest while attenuating unwanted components.**Noise Reduction:**Dropping frequency components outside desired range reduces the noise.**Feature Extraction:**Focusing on certain ranges of frequency makes it suitable for extracting useful features in image processing.**Color Image Processing:**Individual channel of colors manipulation also possible by attenuating the frequencies.

**Disadvantages of Band-Pass Filters**

**Information Loss:**Some attenuating frequencies which are outside the certain range may introduce information loss.**Filter Design Complexity:**Designing a band-pass filter with a sharp transition between passband and stopband can be complex.**Computational Cost:**Applying band-pass filters, especially with high orders for sharp transitions, can be computationally expensive for real-time applications.

**Choosing the Right Band-Pass Filter**

Applying band filter includes important things to be taken care which are as follows:

**Passband Selection:**Range or band of frequency should be define properly based on desired use case.**Filter Type:**There are various types of filters such as Butterworth, Gaussian, or other types offer different trade-offs between sharpness and computational efficiency chose those wisely based on priority.**Filter Order:**Order values on higher side may introduce ringing effects in the result.

In conclusion, band-pass filters are powerful tools for selective filtering in various domains. However, understanding their advantages and limitations is essential for choosing the right filter for your specific application and ensuring optimal results.

Thank you, readers!!