Band Reject Filter in Image Preprocessing

Sumitkrsharma
3 min readMay 20, 2024

--

Image enhancement and manipulation are crucial components in image preprocessing in this post we will explore about band reject filter image preprocessing with its mathematical working, python program implementation, applications and its certain limitations. Let’s start the post with definition of band reject filter.

What is Band Reject Filter?

Band Reject filter designed to block certain ranges of frequency while passing other specific range of frequencies. Band reject filters are characterized as notch as there is dip in the frequency response curve of band reject filters.

Popular band reject filters

Butterworth Band Reject Filter- Popularly used for medical imaging applications, such as MRI and CT scans, where removing noise without affecting image details is crucial for accurate diagnosis.

Gaussian Band Reject Filter- Populary used for elimiting unwanted things from the digital photographs to improve digital image without affecting sharpness of orginal image.

Notch Filter- Commonaly used to remove the fluorescent lighting from the microscopic images.

Elliptic Band Reject Filter- Generelly used for removing atmosphirc distribances from the seltellite areial images.

Numerical exmaple

Input image

[[100,150,200],

[80,120,180],

[60,90,130]]

Filter

[[-1,-1,-1],

[-1,2,-1],

[-1,-1,-1]]

This filter eliminate all the frequencies between 140–160.Convolute the filter over input image, then filtered image looks like.

Output image

[[110,100,190],

[90,120,170],

[70,110,120]]

Where each frequency is outoff specified ranges.

Note: mathematical computations are not perfomed for this numerical example as it is similair to other already discussed filters such as low pass filter ( https://medium.com/@sumit-kr-sharma/low-pass-filters-in-image-preprocessing-in-computer-vision-bbf9043b4191 ) , high pass filter ( https://medium.com/@sumit-kr-sharma/high-pass-filters-in-image-preprocessing-in-computer-vision-947cfb464968 ).

Libraries that uses band reject filters in their backend for any specific operations

SciPy : scipy.signal

MATLAB : Signal Processing Toolbox

GNU Radio : signal processing blocks

TensorFlow : signal Processing (TFSig)

PyTorch : torchaudio

Octave : Signal Package

Python implmentation for band reject filter

import cv2
import numpy as np

def apply_band_reject_filter(image, center, width):
rows, cols = image.shape
crow, ccol = rows // 2, cols // 2

# Creating a mask with ones everywhere except in the specified notch
mask = np.ones((rows, cols), np.uint8)
mask[crow — width//2 : crow + width//2, ccol — center//2 : ccol + center//2] = 0

# Applying Fourier Transform
f_transform = np.fft.fft2(image)
f_transform_shifted = np.fft.fftshift(f_transform)

# Applying the mask
f_transform_shifted = f_transform_shifted * mask

# Inverse Fourier Transform
f_ishift = np.fft.ifftshift(f_transform_shifted)
image_filtered = np.fft.ifft2(f_ishift)
image_filtered = np.abs(image_filtered)

return image_filtered

# Load the image
original_image = cv2.imread(‘input_image.jpg’, cv2.IMREAD_GRAYSCALE)

# Apply the band reject filter
filtered_image = apply_band_reject_filter(original_image, center=30, width=10)

# Display the original and filtered images
cv2.imshow(‘Original Image’, original_image)
cv2.imshow(‘Filtered Image’, filtered_image.astype(np.uint8))
cv2.waitKey(0)
cv2.destroyAllWindows()

Applications

Noise reduction

Interference in images

Contrast improvment

Image restoration

Image compression

Limiations

Balancing between bandwidth and attenuation

Sensitivity of filters paramters

Not able to compeltly eliminating defined frequencies

Not able to handle non linear distortion

Advantages

Image quality improvement

Handling complex image signals

Provides flexibility to control the frequency

Image preservation

Provides selective ranges of frequency form of image

Conclusion

In conclusion band reject offers various new approaches in image preprocessing for improving image, highlighting and extracting features from the image which are desirous for any particular use case. This gives brief overview over the definitions, applications and implementation point of view.

Thank you readers !!

--

--