0% found this document useful (0 votes)
21 views

Digital Image Processing

The document discusses Fourier transforms and frequency domain filtering of images. It begins by explaining how the Fourier transform allows isolating and processing particular image frequencies to perform filtering. It then provides steps to compute the 2D Fourier transform of an image using OpenCV and describes various frequency domain filters like low-pass, high-pass, bandpass, notch filters. Implementation examples in Python are given for Butterworth and Gaussian filters for both low-pass and high-pass filtering. Other techniques like image sharpening, Laplacian, unsharp masking are also covered in the frequency domain.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Digital Image Processing

The document discusses Fourier transforms and frequency domain filtering of images. It begins by explaining how the Fourier transform allows isolating and processing particular image frequencies to perform filtering. It then provides steps to compute the 2D Fourier transform of an image using OpenCV and describes various frequency domain filters like low-pass, high-pass, bandpass, notch filters. Implementation examples in Python are given for Butterworth and Gaussian filters for both low-pass and high-pass filtering. Other techniques like image sharpening, Laplacian, unsharp masking are also covered in the frequency domain.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

Two-dimensional Fourier Transform and Frequency domain

filtering

 The Fourier Transform allows us to isolate and process particular image frequencies,
and so perform low-pass and high-pass filtering with a great degree of precision.

One dimensional DFT


The two-dimensional DFT
Some properties of the two dimensional Fourier transform
All the properties of the one-dimensional DFT transfer into two dimensions. But there are some
further properties not previously mentioned, which are of particular use for image processing.
Steps to find the Fourier Transform of an image using OpenCV

Step 1: Load the image using the cv2.imread() function. This function takes in the path to
the image file as an argument and returns the image as a NumPy array.
Step 2: Convert the image to grayscale using the cv2.cvtColor() function. This is optional,
but it is generally easier to work with grayscale images when performing image processing
tasks.
Step 3: Use the cv2.dft() function to compute the discrete Fourier Transform of the image.
This function takes in the image as an argument and returns the Fourier Transform as a
NumPy array.
Step 4: Shift the zero-frequency component of the Fourier Transform to the center of the
array using the numpy.fft.fftshift() function. This step is necessary because the cv2.dft()
function returns the Fourier Transform with the zero-frequency component at the top-left
corner of the array.
Step 5: Compute the magnitude of the Fourier Transform using the numpy.abs() function.
This step is optional, but it is generally easier to visualize the frequency content of an image
by looking at the magnitude of the Fourier Transform rather than the complex values.
Step 6: Scale the magnitude of the Fourier Transform using the cv2.normalize() function.
This step is also optional, but it can be useful for improving the contrast of the resulting
image.
Step 7: Use the cv2.imshow() function to display the magnitude of the Fourier Transform.

import cv2
import numpy as np

# now we will be loading the image and converting it to grayscale


image = cv2.imread(r"Dhoni-dive_165121_730x419-m.jpg")

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# Compute the discrete Fourier Transform of the image


fourier = cv2.dft(np.float32(gray), flags=cv2.DFT_COMPLEX_OUTPUT)

# Shift the zero-frequency component to the center of the spectrum


fourier_shift = np.fft.fftshift(fourier)

# calculate the magnitude of the Fourier Transform


magnitude =
20*np.log(cv2.magnitude(fourier_shift[:,:,0],fourier_shift[:,:,1]))

# Scale the magnitude for display


magnitude = cv2.normalize(magnitude, None, 0, 255, cv2.NORM_MINMAX,
cv2.CV_8UC1)

# Display the magnitude of the Fourier Transform


cv2.imshow('Fourier Transform', magnitude)
Synthetic Images and Their 2D FFTs
Filtering in Frequency domain
IDEAL LOWPASS FILTERS
Implementation of low pass filtering in the Frequency domain

1. FFT and IFFT (No filtering)

2. Applying filter in the 2DFFT domain


Filter construction
Multiply filter with the Fourier transform of the cameraman image

Step 5: Apply inverse Fourier transform to obtain the filtered image


In your book notation, we can write the transfer function of Butterworth low-pass filter as
follows:
Python Implementation of Butterworth LPF for image filtering
Python Implementation of Gaussian filter
IMAGE SHARPENING USING HIGHPASS FILTERS

The high-pass filter transfer function is evaluated from the low-pass filter transfer function
and it is given as follows:

The ideal high-pass filter (IHPF) transfer function is given as follows:

The Gaussian highpass filter (GHPF) transfer function is given as follows:

The transfer function of Butterworth high-pass filter is given as follows:


Python Implementation of ideal high-pass filter (IHPF)
Python Implementation of Gaussian high-pass filter
Python Implementation of Butterworth high-pass filter
Fig 4.40. Original image

THE LAPLACIAN IN THE FREQUENCY DOMAIN

The Laplacian can be implemented in the frequency domain using the filter transfer function as,

with respect to the centre of the frequency rectangle, using the transfer function is evaluated as
follows:
For an image f(x,y), the Laplacian is evaluated as follows:

The enhanced image evaluated using Laplacian is given as the following equation:

Here, c=-1.

UNSHARP MASKING, HIGH-BOOST FILTERING, AND HIGHFREQUENCY-


EMPHASIS FILTERING

In this section, we discuss frequency domain formulations of the unsharp masking and high-
boost filtering image sharpening techniques.
The unshap masking is defined as follows:

In frequency domain, we can write unsharp masking as follows:

In terms of high-pass filter transfer function, we can write unsharp masking as follows:

HOMOMORPHIC FILTERING

The illumination-reflectance model can be used to develop a frequency domain procedure for
improving the appearance of an image by simultaneous intensity range compression and
contrast enhancement.
Taking the exponential of s(x, y), we have the filtered signal as follows:
The shape of the function can be approximated using a highpass filter transfer function. For
example, using a slightly modified form of the GHPF function yields the homomorphic
function.
Bandpass and Band-reject filters

 The bandpass and band-reject filter transfer functions in the frequency domain can be
constructed by combining low-pass and high-pass filter transfer functions.

 Furthermore, a bandpass filter transfer function is obtained from a band-reject function in the
same manner that we obtained a high-pass from a low-pass transfer function:

NOTCH FILTERS

 Notch filters are the most useful of the selective filters. A notch filter rejects (or passes)
frequencies in a predefined neighbourhood of the frequency rectangle.

 Notch reject filter transfer functions are constructed as products of high-pass filter transfer
functions whose centers have been translated to the centers of the notches.

You might also like