Edge Detection Using Convolution
Department:
BSc Electronic Engineering
Project Supervisor By:
Dr.Dileep Kumar
Group Member:
Khadija Noor.
Abdullah Shaheer.
Zohaib Azziz.
Implementation of filters and linear behaviour
Introduction & Problem Statement :
In the realm of image processing, edge detection plays a crucial role in identifying structural
features within an image. The core problem addressed in this project involves analyzing an
image as a two-dimensional signal to study how various convolution-based filters respond and to
assess their system properties. Specifically, the objective is to convert a given image to grayscale
and then apply convolution using Sobel, Prewitt, and Gaussian kernels. These filters help in
highlighting intensity changes and smoothing the image, allowing us to examine the system’s
linearity and time-invariance based on their convolutional behavior. The solution path adopted
involves implementing and comparing the convolution outputs of these filters to evaluate how
each influences the image features and satisfies key signal system properties.
Theoretical Background :
Our project involve some of the basic concept as describe below.
Grayscale Image:
A grayscale image is a 2D signal where each pixel carries intensity information, with values
typically ranging from black (0) to white (255), simplifying the analysis compared to color
images.
Convolution:
Convolution is a mathematical operation that combines an image with a filter (kernel) to extract
features like edges, smoothing, or patterns by emphasizing specific spatial characteristics.
Differentiation (Edge Detection):
Applying kernels like Sobel and Prewitt approximates the differentiation of the image,
highlighting regions where the pixel intensity changes rapidly — these are perceived as edges.
Linearity:
A system is linear if it satisfies the properties of additivity and homogeneity; meaning the
system's response to a weighted sum of inputs is the same as the weighted sum of the individual
responses.
Time-Invariance (Shift-Invariance):
A system is time-invariant (or shift-invariant in images) if shifting the input results in an equally
shifted output, without altering the system's behavior.
In image processing, convolution filters are applied to detect features such as edges or to smooth
images. In this work, Sobel, Prewitt, and Gaussian filters are utilized, each with specific
mathematical models and purposes.
Sobel Filter
The Sobel filter is used to detect edges by calculating an approximation of the gradient of image
intensity. It emphasizes edges in the horizontal and vertical directions.
Prewitt Filter
The Prewitt filter is another edge detection operator similar to Sobel but with simpler weighting.
It also estimates the gradient but with a uniform difference across neighboring pixels.
Gaussian Filter:
The Gaussian filter is used for image smoothing (blurring) to reduce noise and detail
before edge detection. It applies a weighted average around each pixel based on the
Gaussian distribution.
Methodology:
● The input color image was loaded and converted to a grayscale image to treat it as a 2D
signal suitable for filtering operations.
● The grayscale image was converted to double precision to enhance the accuracy of
convolution computations.
● Sobel filters (horizontal and vertical) were defined and applied using 2D convolution to
detect edges by measuring intensity gradients.
● Similarly, Prewitt filters were applied for edge detection using horizontal and vertical
masks.
● For both Sobel and Prewitt methods, gradient magnitudes were computed to obtain the
final edge maps.
● A Gaussian smoothing filter was applied to the grayscale image to reduce noise and
observe its impact on image quality and edge detection clarity.
● A thresholding method was used to count the number of significant edge pixels detected
by both Sobel and Prewitt filters, aiding in a quantitative comparison.
● Visual comparison was made by displaying the original image, edge maps (Sobel and
Prewitt), and the Gaussian-smoothed image.
● A bar graph was plotted to compare the number of edge pixels detected by Sobel and
Prewitt methods.
● To evaluate linearity, the response of the Sobel filter to a linear combination of two input
images was compared with the linear combination of individual filter responses.
● A graph was plotted showing the difference between the two responses to assess any
deviation from ideal linearity.
● To test time invariance, the input image was spatially shifted, and the filtered result was
compared with a spatially shifted version of the original filtered output.
● The difference between these outputs was visualized to determine if the system behaves
in a time-invariant manner.
Results:
The first section of the code performs edge detection on an input image using Sobel and Prewitt
operators. It loads the image, converts it to grayscale and double precision, and then applies the
Sobel and Prewitt filters to calculate the gradient magnitudes. A Gaussian filter is also applied
for smoothing. By thresholding the gradient magnitudes, the code counts the number of detected
edge pixels for both methods and visualizes the original image, the edge detection results from
Sobel and Prewitt, and the smoothed image. A bar chart compares the total number of edges
detected by each operator, and the results indicate that for the given image and threshold, the
Sobel operator identified a greater number of edge pixels than the Prewitt operator,
suggesting potentially higher sensitivity to edges.Figure 1a,1b,1c,1d and 1e shows the results.
The figure illustrates the edge density obtained by applying three different edge detection filters:
Sobel, Prewitt, and Gaussian. Each filter highlights edges by computing intensity gradients in
the image, but they differ in sensitivity and noise handling. The Sobel filter produces sharper
and more defined edges, indicating a higher edge density, especially in regions with strong
contrast. The Prewitt filter yields similar results but with slightly less intensity and edge
precision, reflecting its simpler gradient approximation. The Gaussian filter, on the other hand,
shows significantly lower edge density due to its smoothing effect, which reduces noise but also
softens fine edges. This comparison reveals that while Sobel and Prewitt are effective for
detecting prominent edges, Gaussian filtering is more suitable for noise-sensitive applications
where edge sharpness is less critical.
To evaluate the fundamental properties of linearity and time invariance of the convolution
operation using the Sobel kernel, two separate experiments were conducted. For linearity, we
tested whether the convolution of a linear combination of two images equals the linear
combination of their individual convolutions. The difference between the left-hand side (LHS)
and right-hand side (RHS) of this condition was plotted and the figure2a and figure2b, showing
values near zero, which confirms that the convolution operation with the Sobel filter satisfies
linearity. In the time invariance test, we applied a horizontal shift to the input image and
compared the result of filtering the shifted image with the shifted result of the original
convolution. The error plot between these two outputs also exhibited negligible values,
indicating that the convolution operation is time-invariant under circular shift conditions. Thus,
both experiments confirm that the Sobel filtering operation exhibits linearity and time invariance
in practice.
Discussion and Interpretation:
Our results clearly shows that sobel filter perform too well as compare to the prewitt filter as
well as the system that is under convolution is always linear and time invariant because
convolution doesnot hold on the time invariant and non linear system.We also observe that how
convolution help us to find the different filters in image processing and other fields like edge
detection etc.
Conclusion and Future Scope:
After performing the above experiment we have clearly absorve the linear behaviour of both
filters and we also learn how to deal with the basic filters and plotting techniques in the matlab.
This project can be extended to more advanced image processing applications such as real-time
edge detection, object recognition, and feature extraction. Future work can involve implementing
adaptive filtering methods that adjust parameters like kernel size and orientation based on the
image content