0% found this document useful (0 votes)
27 views17 pages

Edge Detection

This report details the implementation of various edge detection algorithms in image processing, including Gradient Operators (Robert, Prewitt, Sobel, Frei-Chen), Laplace Operator, Laplace of Gaussian, and Canny Method. It includes a comprehensive evaluation of datasets, preparation steps, and results display for comparing the effectiveness of each algorithm. The report concludes with findings and recommendations based on the performance of the algorithms.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views17 pages

Edge Detection

This report details the implementation of various edge detection algorithms in image processing, including Gradient Operators (Robert, Prewitt, Sobel, Frei-Chen), Laplace Operator, Laplace of Gaussian, and Canny Method. It includes a comprehensive evaluation of datasets, preparation steps, and results display for comparing the effectiveness of each algorithm. The report concludes with findings and recommendations based on the performance of the algorithms.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

TRƯỜNG ĐẠI HỌC KHOA HỌC TỰ NHIÊN

ĐẠI HỌC QUỐC GIA TP HỒ CHÍ MINH

REPORT
LAB 02 – EGDE DETECTION

Student’s name: Nguyễn Quốc Thắng


ID: 22127385
Subject: Video&Image Processing
Class: 22TGMT
Table of Contents

1. Table for the completion


2. Preparation
1.1. Dataset
1.2. Evaluation Algorithms
3. Main Algorithms
2.1. Gradient Operators
2.1.1. Robert Operator
2.1.2. Prewitt Operator
2.1.3. Sobel Operator
2.1.4. Frei-Chen Operator
2.2. Laplace Operator
2.3. Laplace of Gaussian
2.4. Canny Method
4. Results Display and Comparison
3.1. Function to Compare Images
3.2. Function to Display Evaluation Results
5. Conclusion
4.1. Summary of Findings
4.2. Recommendations
6. References
1. Table for the completion
ID Section Complete (%)
1 Preparation. Including: 100
- Data (Difference type of image).
- Evaluation algorithms.
2 Main algorithm - Gradient operator 100
3 Main algorithm – Laplace operator 100
4 Main algorithm – Laplace of Gaussian 100
5 Main algorithm – Canny method 100
5 Display and comparisons result 100
6 Summary 100

2. Preparation
1.1. Dataset
Category image Purpose
Synthetic Basic accuracy
Noise Noise resistance capability
Low contrast Sensitivity
High-detail accuracy on fine details
High- resolution processing time
Motion blur Sensitivity to motion blur
Satelite real-world applications

1.2. Evaluation Algorithms


- Precision-Recall Curve : F1-score
- Structural Similarity index (SSIM) for quality comparision
- Noise resistance evaluation
- Efficiency metrics: processing time and memory usage.
3. Main Algorithms
2.1. Gradient Operators
2.1.1. Robert Operator
Method: it works by applying two small convolution kernels to
compute the gradient in horizontal and vertical directions.
Utilizes two 2x2 kernels (kx and ky) for detecting changes in
pixel intensity. The result is the magnitude of these gradients,
representing the edges.
a. Based on algorithm (Self-Implemented):
• Steps:
1. Apply the kernel in the horizontal direction (kx) to detect vertical
edges.
2. Apply the kernel in the vertical direction (ky) to detect horizontal
edges.
3. Combine the gradients using weighted addition to produce the
final edge map.
b. Using cv2 library
• Steps:
1. Use OpenCV's filter2D function to apply the kernels.
2. Compute the edge maps in both directions.
3. Combine the results using weighted addition to achieve the
final edge-detected image.
2.1.2. Prewitt Operator
Method: It calculates the gradient of the image intensity using
two 3x3 convolution kernels, one for the horizontal direction and
one for the vertical direction.
Uses larger 3x3 kernels compared to the Robert operator,
making it more robust to noise. The magnitude of these gradients
identifies the edges.
a. Based on algorithm (Self-Implemented):
• Steps:

1. Apply the kernel in the horizontal direction (kx) to detect


vertical edges.

kx: A 3x3 kernel for vertical edge detection with values


emphasizing the difference between left and right regions.

2. Apply the kernel in the vertical direction (ky) to detect


horizontal edges.

ky: A 3x3 kernel for horizontal edge detection with


values emphasizing the difference between top and bottom
regions.

3. Combine the gradients using weighted addition to produce


the final edge map.

b. Using cv2 library:


• Steps:
1. Use OpenCV's filter2D function to apply the 3x3 kernels (kx
and ky).
2. The other steps as same as Robert operator.

2.1.3. Sobel Operator

Method: is an enhancement of the Prewitt operator, designed to


calculate the gradient of the image intensity in both horizontal and
vertical directions using 3x3 kernels.

It places a greater emphasis on pixels closer to the center of the


kernel, making it more accurate for detecting edges, especially in noisy
images.

a. Based on algorithm (Self-Implemented)


1. Define convolution kernels for the horizontal direction (kx) and
vertical direction (ky). The custom convolution function applies
the kernel using element-wise multiplication and sums up the
values.

2. Convolve the kernels with the input image using a custom


convolution function.
3. Compute the gradient magnitudes by combining the horizontal
and vertical gradients
4. Normalize and scale the results to produce the final edge map.
b. Using cv2 library
1. Apply OpenCV's Sobel function with the specified kernel size

2. Compute the gradients in the horizontal (kx) and vertical (ky)


directions.

3. Combine the gradients using weighted addition to generate the


final edge-detected image.

4. Convert the results to an absolute scale to ensure all pixel values


are positive.

2.1.4. Frei-Chen Operator

a. Based on algorithm (Self-Implemented)


1. Define the kernels:

2. Apply convolution: The kernels are applied to the image using a


custom convolution function (apply_kernel) that slides the kernels
over the image to compute the gradients in both horizontal and
vertical directions.
3. Combine gradients: The resulting gradients from both directions are
combined using weighted addition.
4. Scale and return: The final edge-detected image is scaled and
converted to absolute values for visualization.
b. Using cv2 library
Only different with apply convolution step, it use cv2.filter2D
function to apply Frei-chen kernel to the image.

2.2. Laplace Operator

Method: calculating the second derivative of an image. It highlights


areas of rapid intensity change, which are typically edges.
a. Based on algorithm (Self-Implemented)
1. Define the Kernel: 3x3

2. Apply Convolution (as same as above)


3. Return the Result.
b. Using cv2 library
1. Apply Laplace Operator: use function cv2.Lacplacian.
2. Convert and Return the Result: using cv2.convertScaleAbs,
which ensures that negative values are handled and the result
is in the valid range for image visualization.
2.3. Laplace of Gaussian
Method: first applies a Gaussian filter to smooth the image and
reduce noise, followed by the application of the Laplace operator to
detect edges.
This approach is effective for detecting edges in noisy images and
provides more accurate results in terms of localization.
a. Based on algorithm
1. Apply Gaussian Filter:
The Gaussian filter is defined by a kernel that is generated using the
following :

2. Apply Laplace Operator:

The Laplace operator detects areas where there is rapid intensity


change, which typically corresponds to edges.

b. Using cv2 library


1. Gaussian Filtering: using cv2.GaussianBlur
2. Laplace Operator: using cv2.Laplacian

2.4. Canny Method

Method: a multi-step process designed to detect edges in an image


by identifying areas with significant intensity changes. It involves
smoothing the image to reduce noise, computing gradients to
detect edges, suppressing non-maximum points, and using
thresholding to finalize edge detection.
a. Based on algorithm
1. Smooth the image by applying a Gaussian filter.
The self-implemented version uses a Gaussian kernel and
applies it to the image using a custom convolution function. This
function generates a Gaussian kernel, normalizes it, and then
applies it to the image using convolution.

2. Compute Gradients (Magnitude and Angle): using Sobel


operator to compute the gradient in both the x and y directions,
which helps in detecting edges by calculating the gradient
magnitude and angle.

▪ Magnitude: This represents the strength of the edge.


▪ Angle: This indicates the direction of the edge, which is
important for non-maximum suppression (Step 3).

3. Apply Non-Maximum Suppression: After calculating the gradient


magnitude and angle, non-maximum suppression is applied to
thin the edges by eliminating pixels that are not part of the edge.
This step keeps only the local maxima in the gradient direction.
The gradient angle is converted into one of four directions
(0, 45, 90, 135 degrees). For each pixel, the algorithm checks the
gradient direction and compares the current pixel’s magnitude
with its two neighboring pixels in that direction. If the current pixel
is not a local maximum, it is suppressed (set to 0).
4. Double Thresholding and Edge Tracking by Hysteresis:

Double Thresholding: Classifies pixels based on their gradient


magnitude. Pixels with high magnitudes are considered strong edges,
and pixels with lower magnitudes but above a low threshold are
considered weak edges.

Edge Tracking: Links weak edges to strong edges by checking the


connectivity of weak edges to strong edges.

5. Finally, edge tracking is applied to link weak edges to strong


edges, ensuring that only valid edges are detected and preserved.

b. Using cv2 library


Using edges = cv2.Canny(image, 100, 200)
4. Results Display and Comparison
3.1. Function to Compare Images
a. Synthetic image
b. Noisy image
c. Low contrast

d. High-detailed
e. High-resolution

f. Motion blur
g. Satelite

You might also like