Assignment Chef icon Assignment Chef
All English tutorials

Programming lesson

Edge Detection and Digital Halftoning: A MATLAB Guide for EE569 Homework #2

Learn how to implement Sobel, Canny, and Structured Edge detectors, evaluate performance with F-measure, and apply dithering for digital halftoning in this comprehensive MATLAB tutorial.

EE569 homework 2 edge detection MATLAB Sobel edge detector Canny edge detector Structured Edge detector digital halftoning dithering algorithm F-measure edge detection precision recall edge image processing tutorial computer vision homework non-maximum suppression Random Forest edge detection Floyd-Steinberg error diffusion binary edge map MATLAB image processing

Introduction to Edge Detection and Halftoning

In computer vision and image processing, edge detection and digital halftoning are fundamental techniques. This tutorial guides you through implementing Sobel, Canny, and Structured Edge detectors, evaluating their performance using precision, recall, and F-measure, and applying dithering for halftoning. These skills are essential for assignments like EE569 Homework #2 and are widely used in AI, autonomous driving, and medical imaging.

Edge Detection Basics

Edge detection identifies boundaries within images. The gradient of intensity changes is used to locate edges. Common detectors include Sobel, Canny, and Structured Edge (SE). Each has strengths: Sobel is simple and fast; Canny uses non-maximum suppression and double thresholding for cleaner edges; SE uses machine learning for high-quality edge maps.

Sobel Edge Detector Implementation

The Sobel operator computes the gradient in x and y directions using convolution kernels. Convert RGB to grayscale using: gray = 0.2989*R + 0.5870*G + 0.1140*B. Then apply Sobel kernels to get Gx and Gy. Normalize each to 0-255. The gradient magnitude is sqrt(Gx^2 + Gy^2). Tune a threshold (e.g., 0.1 to 0.3) to binarize the magnitude map. For best visual performance, choose a threshold that balances edge detection with noise suppression.

Canny Edge Detector

Canny improves upon Sobel by adding non-maximum suppression (NMS) and double thresholding. NMS thins edges by keeping only local maxima in the gradient direction. High and low thresholds are used: pixels above high threshold are strong edges; those between are weak edges; those below are suppressed. Weak edges are kept only if connected to strong edges. Experiment with thresholds like [0.1 0.3] or [0.2 0.4] to see effects on edge maps.

Structured Edge (SE) Detector

SE uses a Random Forest classifier trained on structured labels to predict edge probability. The flow: input image -> feature extraction (e.g., color, gradient) -> Random Forest classification -> probability map -> binarization with threshold (e.g., 0.5). The Random Forest consists of decision trees; each tree splits data based on feature thresholds to minimize impurity. The final output averages tree predictions. SE often outperforms Canny on natural images like Elephants and Ski_person.

Performance Evaluation with F-Measure

Compare detectors using precision (P), recall (R), and F-measure: F = 2*P*R/(P+R). Precision measures accuracy of detected edges; recall measures how many true edges are found. For each ground truth (GT), compute P and R, then average across GTs. A higher F-measure indicates better performance. For example, SE may achieve F=0.75 vs Canny's 0.68. The F-measure is image-dependent; Ski_person may yield higher F due to clearer edges.

Digital Halftoning via Dithering

Halftoning converts grayscale images to binary for printing. Fixed thresholding: set output to 0 if pixel < T, else 255. Floyd-Steinberg error diffusion distributes quantization error to neighbors, producing better visual quality. Implement both and compare. For Bridge image, fixed threshold may lose details, while error diffusion preserves textures.

Conclusion

Mastering edge detection and halftoning is crucial for computer vision. By implementing Sobel, Canny, and SE detectors, and evaluating with F-measure, you gain insights into algorithm trade-offs. These techniques are used in AI applications like self-driving cars and photo editing. Practice with images like Elephants and Ski_person to build intuition.