0% found this document useful (0 votes)
3 views12 pages

Dip PDF (1) (AutoRecovered)

This project focuses on implementing the Canny edge detection algorithm to accurately identify edges in digital images, addressing challenges such as noise and varying illumination. The methodology includes Gaussian smoothing, gradient computation, and edge tracking, demonstrating superior performance compared to traditional methods like the Sobel operator. Future improvements suggested include adaptive thresholding, machine learning integration, and applications in medical imaging and real-time video processing.

Uploaded by

Lucifer
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)
3 views12 pages

Dip PDF (1) (AutoRecovered)

This project focuses on implementing the Canny edge detection algorithm to accurately identify edges in digital images, addressing challenges such as noise and varying illumination. The methodology includes Gaussian smoothing, gradient computation, and edge tracking, demonstrating superior performance compared to traditional methods like the Sobel operator. Future improvements suggested include adaptive thresholding, machine learning integration, and applications in medical imaging and real-time video processing.

Uploaded by

Lucifer
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

Title

Edge Detection in Digital Images Using the Canny Edge Detection Algorithm

B. TECH MINI PROJECT

Submitted By :

Mayank Kumar (21106059)

Supervised by:
Dr. Roop Pahuja
(Associate Professor)

Department of Instrumentation and Control Engineering

5 MAY, 2025
Problem Statement

Digital images often contain critical structural information, such as edges, which are essential for applications
like object recognition, image segmentation, and computer vision. However, detecting edges accurately in the
presence of noise, varying illumination, and complex backgrounds poses a significant challenge. Traditional
edge detection methods, such as Sobel or Prewitt operators, often produce noisy or incomplete edges, leading to
poor performance in real-world applications.

The problem addressed in this project is to develop an effective edge detection system using the Canny edge
detection algorithm, which is known for its robustness in identifying true edges while minimizing noise. The
goal is to implement this algorithm on a sample grayscale image, analyze its performance, and evaluate its
suitability for practical applications. Key challenges include handling noise, optimizing threshold values, and
ensuring the algorithm detects continuous and well-localized edges. This project aims to provide a clear
understanding of edge detection principles and demonstrate their application using a standard DIP technique.
Abstract

Edge detection is a fundamental technique in digital image processing, enabling the identification of boundaries
within an image for further analysis. This project focuses on the implementation of the Canny edge detection
algorithm, a widely used method known for its accuracy and noise suppression capabilities. The algorithm
involves multiple stages, including Gaussian smoothing, gradient computation, non-maximum suppression, and
double thresholding, to detect edges in a grayscale image.

We implemented the algorithm using Python and OpenCV, processing a sample image to highlight object
boundaries. The methodology includes a detailed block diagram of the process, theoretical foundations of edge
detection, and practical coding steps. Results show that the Canny algorithm successfully identifies prominent
edges with minimal noise, outperforming simpler methods like the Sobel operator. The project also explores
future improvements, such as adaptive thresholding and integration with machine learning for enhanced edge
detection. In conclusion, the Canny algorithm proves to be a reliable tool for edge detection, with potential
applications in medical imaging, autonomous vehicles, and facial recognition systems.
Block Diagram

The Canny edge detection process involves a series of steps, which can be represented in a block diagram:

1. Input Image: Start with a grayscale image to simplify processing.

2. Gaussian Blur: Apply a Gaussian filter to reduce noise, using a 5x5 kernel.

3. Gradient Computation: Calculate the intensity gradient using Sobel operators to find edge strength and
direction.

4. Non-Maximum Suppression: Suppress non-maximum gradient values to thin out edges.

5. Double Thresholding: Apply low and high thresholds to classify edges as strong, weak, or non-edges.

6. Edge Tracking by Hysteresis: Connect weak edges to strong ones, discarding others.

7. Output Image: Produce a binary image with detected edges.

You can create a block diagram using tools like [Link] or PowerPoint and insert it into your document
manually.
Theory

Edge detection identifies significant changes in pixel intensity, which typically correspond to object boundaries
in an image. The Canny edge detection algorithm, proposed by John Canny in 1986, is considered optimal due
to its three main criteria: good detection (low error rate), good localization (edges detected close to true
positions), and minimal response (one response per edge).

The process begins with noise reduction using a Gaussian blur, which smooths the image by convolving it with
a Gaussian kernel. Next, the gradient magnitude and direction are computed using Sobel filters, highlighting
areas of rapid intensity change. Non-maximum suppression thins the edges by retaining only the maximum
gradient values along the gradient direction. Double thresholding then classifies edges into strong, weak, and
non-edges based on user-defined thresholds. Finally, edge tracking by hysteresis connects weak edges to strong
ones, ensuring continuity. This multi-stage approach makes the Canny algorithm robust against noise and
effective for various applications, including object detection and image segmentation.
Program Code

Below is a Python implementation of the Canny edge detection algorithm using OpenCV:

import cv2
import [Link] as plt
from pathlib import Path
def canny_edge_detection(image_path: str, low_threshold: int = 50, high_threshold: int = 150,
kernel_size: tuple = (5, 5), output_path: str = 'canny_edges_output.jpg') -> tuple
"""
Perform Canny edge detection on a grayscale image.
Args:
image_path (str): Path to the input image.
low_threshold (int): Lower threshold for Canny edge detection.
high_threshold (int): Upper threshold for Canny edge detection.
kernel_size (tuple): Size of the Gaussian blur kernel.
output_path (str): Path to save the edge-detected image.

Returns:
tuple: Original image and edge-detected image (or None if an error occurs).
"""
# Validate input path
if not Path(image_path).is_file():
print(f"Error: Image file '{image_path}' not found.")
return None, None

# Load image in grayscale (memory-efficient by avoiding color channel conversion later)


img = [Link](image_path, cv2.IMREAD_GRAYSCALE)
if img is None:
print(f"Error: Failed to load image from '{image_path}'.")
return None, None

# Apply Gaussian blur and Canny edge detection in a single pipeline


try:
blurred = [Link](img, kernel_size, 0)
edges = [Link](blurred, low_threshold, high_threshold)

# Save the edge-detected image


[Link](output_path, edges)
print(f"Edge-detected image saved as '{output_path}'")
return img, edges

except Exception as e:
print(f"Error during edge detection: {str(e)}")
return None, None

def display_images(original: any, edges: any) -> None:


"""
Display the original and edge-detected images side by side.

Args:
original: Original grayscale image.
edges: Edge-detected image.
"""
if original is None or edges is None:
print("Cannot display images due to previous errors.")
return

# Use a minimalistic plot setup for efficiency


[Link](figsize=(10, 4), dpi=100) # Reduced DPI for faster rendering
[Link](121), [Link](original, cmap='gray'), [Link]('Original'), [Link]('off')
[Link](122), [Link](edges, cmap='gray'), [Link]('Canny Edges'), [Link]('off')
plt.tight_layout()
[Link]()

def main():
"""Main function to execute the edge detection process."""
# Configuration
image_path = 'sample_image.jpg'
config = {
'low_threshold': 50,
'high_threshold': 150,
'kernel_size': (5, 5),
'output_path': 'canny_edges_output.jpg'
}

# Perform edge detection


original_img, edge_img = canny_edge_detection(
image_path, **config
)

# Display results
display_images(original_img, edge_img)

if _name_ == "_main_":
main()
Results

The implementation was tested on a sample grayscale image of a simple object (e.g., a car). After applying the
Canny edge detection algorithm, the following observations were made:

- Edge Detection Quality: The algorithm successfully detected the main edges of the object, such as the
car's outline, windows, and wheels, with clear and continuous lines.

- Noise Suppression: The Gaussian blur effectively reduced noise, ensuring that minor intensity variations
( e.g., texture on the car's surface) did not result in false edges.

- Threshold Impact: Using a low threshold of 50 and a high threshold of 150 provided a good balance
between detecting true edges and suppressing noise.

- Comparison: Compared to the Sobel operator, the Canny algorithm produced thinner and more precise
edges, making it more suitable for applications requiring accurate boundary detection.
Future Scope

The Canny edge detection algorithm, while effective, has several avenues for improvement and expansion:

- Adaptive Thresholding: Automatically adjusting thresholds based on image properties.

- Machine Learning Integration: Enhancing edge detection using convolutional neural networks.

- Real-Time Applications: Implementing the algorithm for video streams in autonomous driving or surveillance.

- Color Image Processing: Handling RGB or HSV images for improved accuracy.

- Medical Imaging: Detecting features in MRI or CT scans with domain-specific preprocessing.

These improvements could increase the robustness and versatility of edge detection in real-world applications.
Conclusion

This project successfully implemented the Canny edge detection algorithm to identify edges in a grayscale
image, demonstrating its effectiveness in digital image processing. The algorithm's multi-stage approach-
Gaussian smoothing, gradient computation, non-maximum suppression, double thresholding, and hysteresis-
ensured accurate edge detection with minimal noise.

The Python implementation using OpenCV provided clear results, highlighting the algorithm's ability to detect
continuous and well-localized edges in a sample image. Compared to simpler methods like the Sobel operator,
the Canny algorithm showed superior performance. This project underscores the importance of parameter tuning
and opens the door to future enhancements for practical applications.
References

1. Canny, J. (1986). A Computational Approach to Edge Detection. IEEE Transactions on PAMI, 8(6) , 679-
698.

2. Gonzalez, R. C., & Woods, R. E. (2018). Digital Image Processing. Pearson.

3. OpenCV Documentation. [Link]

4. Szeliski, R. (2022). Computer Vision: Algorithms and Applications. Springer.

5. Pratt, W. K. (2007). Digital Image Processing. Wiley.

6. Forsyth, D. A., & Ponce, J. (2012). Computer Vision: A Modern Approach. Pearson.

7. Shapiro, L. G., & Stockman, G. C. (2001). Computer Vision. Prentice Hall.

8. Bradski, G., & Kaehler, A. (2008). Learning OpenCV. O'Reilly Media.

9. Jain, A. K. (1989). Fundamentals of Digital Image Processing. Prentice Hall.

10. Sonka, M., Hlavac, V., & Boyle, R. (2014). Image Processing, Analysis, and Machine Vision. Cengage
Learning.

You might also like