Edge Detection in Image Processing (Implementation in Matlab)

👨🎓 Personal Homepage

💥💥💞💞 Welcome to this blog ❤️❤️💥💥

🏆 Blogger’s Advantage: 🌞🌞🌞 The blog content aims to be logically clear and coherent for the convenience of readers.

⛳️ Motto: A journey of a hundred miles begins with a single step.

💥1 Overview

Detecting edges and object boundaries in natural images has always been a fundamental problem in computer vision. Edge detection plays a crucial role in various visual fields, such as image segmentation, object detection/recognition, tracking and motion analysis, medical imaging, 3D reconstruction, and modern applications like autonomous driving. Over the years, many researchers have focused on improving edge detection evaluation standards: optimal image scale (OIS), optimal dataset scale (ODS), and average precision (AP). With the rapid development of neural networks, edge detection has diverged into two camps: traditional detection methods and deep learning-based detection methods. Figure 1 shows the general process of performing edge detection tasks using both methods.

Some edge detection methods [1] are based solely on color, texture, or other low-level features to predict boundaries:

1) Early gradient operator methods, such as first-order edge detection operators like the Sobel operator [2], Roberts operator [3], second-order edge detection operator Laplacian operator [4], and the commonly used Canny operator [5] in the industry.

2) Methods based on manually designed features, such as statistical edges [6], probability boundary (Pb), PMI (pointwise mutual information), and structured edge detection algorithms like SE (structured forests edge detection) algorithm [9], etc. Traditional edge detection methods have made significant progress in edge extraction, but improvements in noise suppression, edge localization, and fine edge handling are still needed.

Edge Detection in Image Processing (Implementation in Matlab)Edge Detection in Image Processing (Implementation in Matlab)

Edge detection is a classic problem in computer vision that requires identifying edges in images to establish object boundaries and separate regions of interest. A grayscale image of size M × N is represented as a two-dimensional matrix composed of binary functions:

Edge Detection in Image Processing (Implementation in Matlab)Edge Detection in Image Processing (Implementation in Matlab)

In a color image, each pixel contains three channels: RGB, with intensity values ranging from 0 to 255. Plotting all pixels in a certain row can yield a waveform graph representing pixel intensity, as shown in Figure 2.

Edge Detection in Image Processing (Implementation in Matlab)Edge Detection in Image Processing (Implementation in Matlab)

The fluctuations in the curves in the figure represent the degree of change in color and other features, with significant changes in the sampling area (e.g., at pixel coordinates 130, indicated by the white grid box in Figure 2(a)). This indicates that areas with significant changes may contain edges, further illustrating the close relationship between waves and images, where the essence of an image is the superposition of various color waves. By using image filters to remove low frequencies and retain areas with significant changes, we can identify edges in the image. Edges are generally defined as regions where pixel intensity changes sharply. The intensity changes can be categorized into two types:

1) Step changes, indicating a gradual transition from dark to bright;

2) Roof changes, indicating a transition from dark to bright and then back to dark. The goal of edge detection can be summarized as finding a set of pixels that exhibit step or roof changes. By calculating the derivatives of a pixel and its neighborhood, we can identify pixels with significant changes. For pixels with step changes, the first derivative is maximized or the second derivative is zero, indicating an edge point; for pixels with roof changes, the first derivative is zero or the second derivative is maximized, indicating an edge point. This leads to traditional edge detection methods based on gradients (first and second derivatives), such as classic algorithms like Sobel [2] and Canny [5].

Research on Edge Detection in Images

Abstract

Edge detection is a key technology in image processing and computer vision, aimed at identifying pixels in an image where brightness or color changes sharply, which typically correspond to object boundaries. This article reviews the basic principles, classic algorithms, application fields, and research trends in edge detection, providing references for researchers in related fields.

  1. Introduction

Edge detection is fundamental to image analysis tasks such as image segmentation, object recognition, and region shape extraction. By detecting edges, we can significantly reduce the amount of data for subsequent image analysis and processing while retaining important structural information in the image. Research on edge detection holds significant importance in machine vision, medical image processing, and industrial inspection.

  1. Basic Principles of Edge Detection

The core idea of edge detection is to determine whether a pixel is an edge by calculating the brightness or color differences between that pixel and its surrounding pixels. This is typically achieved through the following steps:

Image filtering: Using filters to reduce noise and improve the accuracy of edge detection.

Image enhancement: The basis of edge enhancement is to determine the change values of intensity in the neighborhood of each point in the image, highlighting points with significant changes in neighborhood intensity values.

Image detection: Using gradient magnitude thresholds or other methods to determine which points are edge points.

Image localization: Estimating the position and direction of edges at sub-pixel resolution.

  1. Classic Edge Detection Algorithms

3.1 First-order Differential Operators

First-order differential operators are based on the calculation of image gradients, locating edges by detecting the maxima of gradient magnitudes. Common first-order differential operators include:

Roberts operator: Utilizes local differences to compute edges, responding best to images with steep gradients and low noise, but is sensitive to noise.

Sobel operator: Finds edges by calculating gradients in horizontal and vertical directions, providing some smoothing effect against noise but may detect spurious edges.

Prewitt operator: Similar to the Sobel operator but uses different convolution kernels.

3.2 Second-order Differential Operators

Second-order differential operators locate edges by detecting zero-crossings of the second derivative of the image. Common second-order differential operators include:

Laplacian operator: Has rotational invariance but is sensitive to noise and does not provide edge direction information.

LoG (Laplacian of Gaussian) operator: Combines Gaussian filtering and the Laplacian operator, first smoothing the image to reduce noise before detecting edges.

3.3 Canny Operator

The Canny operator is a multi-stage optimized hybrid method that includes the following steps:

Gaussian filtering for noise reduction: Using a Gaussian filter to smooth the image.

Calculating gradient magnitudes and directions: Using the Sobel operator to compute gradients.

Non-maximum suppression: Refining edges by retaining only local maxima in the gradient direction.

Double threshold detection and edge linking: Using high and low thresholds to distinguish strong and weak edges, and linking weak edges to form complete edges.

The Canny operator performs excellently in edge detection, exhibiting high localization accuracy and noise resistance, but has high computational complexity.

  1. Application Fields of Edge Detection

Edge detection has wide applications in various fields, including but not limited to:

Medical image processing: Such as organ contour extraction from CT images, classification of red blood cells in microscopic images, etc.

Industrial inspection: Such as part size detection, defect detection, etc.

Computer vision: Such as object recognition, scene understanding, etc.

Remote sensing image processing: Such as geological resource detection, crop yield estimation, etc.

  1. Research Trends and Challenges

5.1 Research Trends

Optimization of traditional algorithms: Improving the performance of existing algorithms, such as enhancing noise resistance and reducing computational complexity.

Interdisciplinary method integration: Combining new technologies like wavelet transforms and deep learning to enhance the accuracy and robustness of edge detection.

3D edge detection: Developing edge detection algorithms suitable for 3D medical images to address the issue of projection information loss.

5.2 Challenges

Noise resistance optimization: How to effectively suppress noise while preserving edge details.

Algorithm universality: Developing general edge detection algorithms applicable to different scenes and image types.

Real-time requirements: Meeting the high real-time demands of applications like industrial inspection.

📚2 Running Results

Edge Detection in Image Processing (Implementation in Matlab)Edge Detection in Image Processing (Implementation in Matlab)

Edge Detection in Image Processing (Implementation in Matlab)Edge Detection in Image Processing (Implementation in Matlab)

Edge Detection in Image Processing (Implementation in Matlab)Edge Detection in Image Processing (Implementation in Matlab)

Edge Detection in Image Processing (Implementation in Matlab)Edge Detection in Image Processing (Implementation in Matlab)

Edge Detection in Image Processing (Implementation in Matlab)Edge Detection in Image Processing (Implementation in Matlab)

Edge Detection in Image Processing (Implementation in Matlab)Edge Detection in Image Processing (Implementation in Matlab)

Edge Detection in Image Processing (Implementation in Matlab)Edge Detection in Image Processing (Implementation in Matlab)

Edge Detection in Image Processing (Implementation in Matlab)Edge Detection in Image Processing (Implementation in Matlab)Edge Detection in Image Processing (Implementation in Matlab)Edge Detection in Image Processing (Implementation in Matlab)

Partial Code:

function idxLocalMax=cannyFindLocalMaxima(direction,ix,iy,mag)% Function: Implement non-maximum suppression% Input: direction – 4 directions% ix – image filtering result in x direction% iy – image filtering result in y direction% mag – filtering magnitude

[m,n,o]=size(mag);% Determine the direction of the gradient at each point based on the gradient magnitude and find the coordinates of possible edge points in four directions.switch direction case 1 idx=find((iy<=0&ix>-iy)|(iy>=0&ix<-iy)); case 2 idx=find((ix>0&-iy>=ix)|(ix<0&-iy<=ix)); case 3 idx=find((ix<=0&ix>iy)|(ix>=0&ix<-iy)); case 4 idx=find((iy<0&ix<=iy)|(iy>0&ix>=iy));end% Remove points outside the image boundaryif~isempty(idx) v=mod(idx,m); extIdx=find(v==1|v==0|idx<=m|idx>(n-1)*m); idx(extIdx)=[];end% Obtain the filtered values of possible boundary pointsixv=ix(idx);iyv=iy(idx);gradmag=mag(idx);% Calculate the gradient magnitudes in four directionsswitch direction case 1 d=abs(iyv./ixv); gradmag1=mag(idx+m).(i-d)+mag(idx+m-1).d; gradmag2=mag(idx-m).(i-d)+mag(idx-m+1).d; case 2 d=abs(ixv./iyv); gradmag1=mag(idx+1).(i-d)+mag(idx+m-1).d; gradmag2=mag(idx-1).(i-d)+mag(idx-m+1).d; case 3 d=abs(ixv./iyv); gradmag1=mag(idx-1).(i-d)+mag(idx-m-1).d; gradmag2=mag(idx+1).(i-d)+mag(idx+m+1).d; case 4 d=abs(iyv./ixv); gradmag1=mag(idx-m).(i-d)+mag(idx-m-1).d; gradmag2=mag(idx+m).(i-d)+mag(idx+m+1).d;end% Perform non-maximum suppressionidxLocalMax=idx(gradmag>=gradmag1&gradmag>=gradmag2);

🎉3 References

Some theories are sourced from the internet; please contact for removal if there is any infringement.

[1] Xiao Yang, Zhou Jun. Overview of Image Edge Detection [J]. Computer Engineering and Applications, 2023, 59(05): 40-54.

[2] Liu Zhongchi. Network Image Edge Detection Method Based on Fruit Fly Algorithm [J]. Automation Applications, 2022(11): 81-83+86. DOI:10.19769/j.zdhy.2022.11.020.

🌈4 Matlab Code Implementation

Leave a Comment