Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

University Visvesvaraya College of Engineering

Preliminary project report

Subject : DSP

Topic : DFT-Assisted Edge Detection Technique

Team : Akash S (20GAECE004)

Manjunath Hegde (20GAECE022)

Shrisha G Hegde (20GAECE048)

Vivek Hegde (20GAECE058)


Introduction:

The detection of edges in images plays a fundamental role in computer vision,


image processing, and various fields such as object recognition, medical imaging, and
robotics. Edges represent significant changes in intensity or color in an image and often
correspond to the boundaries of objects or regions of interest. Accurate edge detection is
a critical step in various image analysis tasks, enabling the extraction of meaningful
features and structures from visual data.

In this report, we explore the use of the Discrete Fourier Transform (DFT) as a
powerful tool for image edge detection. The DFT is a mathematical technique that allows
us to analyze the frequency components of an image. While it is traditionally used in
signal processing and frequency domain analysis, it has also found applications in image
processing. The central idea is to transform an image from the spatial domain to the
frequency domain using the DFT and identify edges based on variations in the spectral
content.

Motivation

Edge detection using the Discrete Fourier Transform (DFT) offers certain
advantages over other techniques, although it may not always be the best choice for
every scenario. Here are some of the advantages of using DFT-based edge detection:

1. Frequency Information: DFT analyzes the frequency components of an image.


This can be advantageous when edges have characteristic frequency patterns. It
allows for a global understanding of the spatial frequency distribution.
2. Rotation Invariance: DFT can be used to detect edges independently of their
orientation. Since it captures frequency information, it can identify edges at
different angles without the need for specific filters designed for those angles.
3. Low-Frequency Noise Suppression: DFT can effectively suppress low-frequency
noise, making it suitable for images with noise present in lower frequency
components.
4. Information Preservation: DFT-based edge detection can preserve the phase
information of the signal, which can be valuable in some applications like texture
analysis and pattern recognition.
5. Adaptability: DFT allows you to adjust the frequency domain representation to
emphasize certain frequency components. This adaptability can be useful in cases
where specific frequency components are of interest.
Goals:

This report aims to provide a comprehensive overview of DFT-based image edge


detection methods, including the underlying theory, implementation techniques, and
practical applications. We will discuss the basic concepts of the DFT and how it can be
applied to image processing tasks. Additionally, we will explore common challenges and
considerations associated with DFT-based edge detection, such as parameter tuning and
computational efficiency.

The report is organized as follows: in the following section, we will delve into the
theoretical foundation of the DFT and its relevance to image analysis. Subsequently, we
will discuss the practical implementation of DFT-based edge detection algorithms and
present examples to illustrate their effectiveness. We will also address the trade-offs and
limitations of these methods. Finally, we will conclude by highlighting the significance of
DFT-based image edge detection and its potential impact on various applications.

Through this report, we aim to shed light on the potential benefits of using the
Discrete Fourier Transform for image edge detection, providing researchers, engineers,
and practitioners with valuable insights into a powerful technique for image analysis and
computer vision tasks.
LITERATURE SURVEY

[1] In this paper author aimed to explain the general algorithms used for edge detection. We have used
Sobel algorithm for the implementation of edge detection using DFT.The Sobel operator is simple to
implement and computationally efficient, making it a popular choice for real-time edge detection in
various computer vision and image processing applications. It is part of the broader family of gradient-
based edge detection operators and is often used as a preprocessing step for more complex tasks, such
as object detection, feature extraction, or image segmentation.

[2] In this paper, Sobel edge detection operator and its improved algorithm are first discussed in term of
optimal thresholding. Then based on Genetic Algorithms and improved Sobel operator, a new automatic
threshold algorithm for images processing is proposed. Finally, the edge detection experiments of two
real images are conducted by means of two algorithms. The comparative experiment results show that
the new algorithm of automatic threshold is very effective. The results are also better than the classical
Otsu methods.

[3] In this paper authors explained about feature extraction by Fourier transform method which is found
to be fundamental essence in our project. Feature extraction using the Discrete Fourier Transform (DFT)
involves analyzing the frequency domain characteristics of signals or images to extract meaningful
information or features. The DFT is particularly useful for capturing frequency-related attributes in data.

[4] In this paper the procedure of reconstructing the suppressed edges are well taken care.In edge
detection, the suppression of edges can occur due to various reasons, including the application of filters
or thresholding. To reconstruct suppressed edges, post-processing techniques are employed. These
techniques often involve signal interpolation, such as using spline or polynomial functions, to
approximate the original edge shape. Additionally, morphological operations like dilation can help
recover some lost edge information by expanding the detected edge regions. Advanced algorithms, like
the Hysteresis thresholding in the Canny edge detector, are used to refine and reconnect fragmented
edges. The goal is to enhance the accuracy and continuity of edge information in the final output,
making it more suitable for subsequent image analysis tasks.
Methodology:

Formulas used:
Procedure:

Loading the Image:

Start by loading the input image, which is typically a grayscale image. We can use a library like
OpenCV to read the image file.

Preprocessing:

Convert the loaded image to grayscale. Grayscale images are simpler to work with for edge
detection because they have a single intensity channel.

DFT on the Grayscale Image:

The next step is to apply the DFT to the grayscale image. The DFT is applied to the image pixel by
pixel to transform it from the spatial domain to the frequency domain.
For a 2D image, you will apply the DFT separately to the rows and columns of the image. This means you
perform a 1D DFT on each row and a 1D DFT on each column, or equivalently, a 2D DFT on the entire
image.

Proposed code to compute fourier transform:

Complex DFT Result:

The result of the DFT is a complex matrix representing the frequency components of the image.
This matrix has real and imaginary parts, where each element corresponds to a specific frequency
component.
Shifting the DFT Output:

To make it easier to interpret the DFT result, typically shift the zero frequency component to the
center of the matrix. This is done using the np.fft.fftshift function. Shifting allows you to view the low-
frequency components in the center and the high-frequency components at the corners of the image.

Proposed code for Shifting the output:

import numpy as np

# Generate a sample signal


N = 256 # Number of samples
fs = 1000 # Sampling frequency (Hz)
t = np.arange(0, N) / fs # Time vector
frequency = 50 # Frequency of the component to be shifted (Hz)
signal = np.sin(2 * np.pi * frequency * t)

# Compute the DFT


dft = np.fft.fft(signal)

# Shift the phase of a specific component (e.g., the 10th component)


component_to_shift = 10
shifted_phase = np.angle(dft[component_to_shift]) + np.pi/4 # Shift phase by pi/4 radians

# Apply the phase shift


dft[component_to_shift] = np.abs(dft[component_to_shift]) * np.exp(1j * shifted_phase)

# Compute the inverse DFT to get the shifted signal


shifted_signal = np.fft.ifft(dft).real

Magnitude Spectrum:

To visualize the frequency components effectively, calculate the magnitude spectrum. This is
done by calculating the magnitude of the complex DFT result. The magnitude spectrum represents the
amplitude of the frequency components in the image.

Visualizing the DFT Output:

Creation of visualizations of the DFT output and magnitude spectrum, which will help us
understanding the frequency content of the image.
Edge Detection and Filtering:

Filters in image processing are just what the name suggests, Filter. They are typically a mask
array of the same size as the original image which when superimposed on the ordinal image, extracts
only the attributes that we are interested in. As mentioned earlier, in an DFT transformed image, low
frequencies are found in the center and high frequencies are scattered around, we can then create a
mask array which has a circle of zeros in the center and rest all ones. Now when this mask is applied to
the original image, the resultant image would only have high frequencies. This becomes quite useful as
low frequencies correspond to edges in spatial domain.

After the DFT analysis, perform edge detection using techniques like the Sobel operator. The
high-frequency components in the DFT result often correspond to edges in the spatial domain. By
filtering or enhancing these components, you can detect edges effectively.

Sobel algorithm : The Sobel operator is widely used in image processing, particularly within edge
detection algorithms. Technically, it is a discrete differentiation operator, computing an approximation
of the gradient of the image intensity function. At each point in the image, the result of the Sobel
operator is either the corresponding gradient vector or the norm of this vector. Sobel operator is the
partial derivative of f (x, y) as the central computing 3x3 neighbourhood at x, y direction. In order to
suppress noise, a certain weight is correspondingly increased on the centre point, and its digital gradient
approximation equations

Filtering is implemented by following code snippet:

Proposed code for Edge detection in Python :

import cv2
from matplotlib import pyplot as plt
import numpy as np

img = cv2 . imread ('image.jpg', 0 )


dft = cv2 . dft ( np . float32(img) , flags=cv2 .DFT_COMPLEX_OUTPUT)
dft_shift= np .fft .fftshift ( dft )

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

rows , cols = img . shape


crow , ccol = int( rows / 2 ) , int( cols / 2 )

mask = np . ones(( rows , cols , 2 ) , np.uint8 )


r = 90
center= [ crow , ccol ]
x , y = np.ogrid[ : rows , : cols ]
mask_area = ( x - center[ 0 ] ) * 2 + ( y - center[ 1 ] ) * 2 <= r * r
mask [ mask_area ] = 0

fshift = dft_shift* mask


fshift_mask_mag = 2000 * np . log( cv2 . magnitude ( fshift [ : , : , 0 ] ,
fshift [ : , : , 1 ] ) + 1 )
f_ishift = np .fft . ifftshift ( fshift )
img_back = cv2 . idft( f_ishift )
img_back = cv2 . magnitude ( img_back [ : , : , 0 ] , img_back [ : , : , 1 ] )

m = -1
for i in range (len( img_back )):
x = img_back [ i ]
for j in range (len( x )):
m = max( img_back [ i ] [ j ] , m)
img_back = m - img_back

fig= plt.figure(figsize=(12,12))
ax1 = fig.add_subplot(2,2,1)
ax1.imshow ( img , cmap='gray')
ax1.title.set_text('Inpu Image')
ax2 = fig.add_subplot(2,2,2)

ax2.imshow(magnitude_spectrum , cmap='gray')
ax2.title.set_text('FT ofimage')
ax3 = fig.add_subplot(2,2,3)
ax3.imshow(fshift_mask_mag , cmap='gray')
ax3.title.set_text('FT + ask')
ax4 = fig.add_subplot(2,2,4)
ax4.imshow(img_back , cmap='gray')
ax4.title.set_text('After inverse FFT')
plt.show ( )

Ringing artifacts:

Ringing artifacts in digital image processing result from spurious signals near sharp transitions in
the input signal. In the FED procedure, they are primarily caused by unnatural suppression of low-
frequency waveforms during Butterworth high-pass filtering. To mitigate these artifacts, a ratio
threshold (γ) is used to eliminate minor lobes, typically containing noise, given their energy is usually
15% to 20% of the main lobe's energy.
Inverse DFT:

Once you've enhanced or filtered the DFT result to highlight edges, you can apply the inverse
DFT to convert the frequency domain representation back to the spatial domain. This will result in an
image where the edges are emphasized.

Software used:

Python

Modules used:

 Numpy

 Matplotlib

 openCv
References:

[1] “A Descriptive Algorithm for Sobel Image Edge Detection” by O. R. Vincent,Clausthal University of
Technology, Germany and University of Agriculture, Abeokuta, Nigeria and O. Folorunso
Department of Computer Science, University of Agriculture, Abeokuta, Nigeria.
https://proceedings.informingscience.org/InSITE2009/InSITE09p097-107Vincent613.pdf

[2] “Edge detection of images based on improved Sobel operator and genetic algorithms” by Zhang Jin-
Yu Chen Yan Huang Xian-Xiang
https://ieeexplore.ieee.org/document/5054605

[3] “DFT domain Feature Extraction using Edge-based Scale Normalization for Enhanced Face
Recognition” by K Manikantan1, S Ramachandran
https://www.sciencepubco.com/index.php/jacst/article/download/212/207

[4] “A New Edge Detection Algorithm Using FFT Procedure” by Tongfeng Yang
https://www.researchgate.net/scientific-contributions/Jun-Ma-2098951355

You might also like