Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize Image Edge extraction by Matlab

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces Matlab how to achieve image edge extraction, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

What is an image edge?

The so-called image edge (Edlge) refers to the discontinuity of the local characteristics of the image, such as the abrupt change of gray level, color, texture structure and so on. Edge widely exists between target and target, object and background, region and region (including different colors). It is an important feature of image segmentation.

Xiaobai today mainly introduces several typical edge detection methods of image gray value mutation, and its principle is also suitable for edge detection of other characteristic mutation. The edge of an image is usually related to the discontinuity of the first derivative of the image grayscale. The discontinuity of image grayscale can be divided into two categories: step discontinuity, that is, there is an obvious difference in the gray level of pixels on both sides of the discontinuity. The line is discontinuous, that is, the grayscale of the image suddenly changes from one value to another, keeping a small stroke and returning to the original value. But in practice, step and line edge images are rare, because of spatial resolution (scale space), image sensors and other reasons, the step edge will become a slope edge, and the line edge will become a roof edge. Their grayscale changes are not instantaneous but span a certain distance. Several types of edges can be understood more clearly through the pictures below.

Sobel operator

In the previous explanation on image filtering, Xiaobai introduced the sobel operator template, but did not explain its specific role. In this lecture, Xiaobai will explain what the sobel operator is.

Sobel operator is a first-order gradient operator, that is, to obtain the first-order derivative of the signal, which has a smoothing effect on noise and provides more accurate edge direction information, but the edge location accuracy is not high enough; but this method is relatively simple, easy to implement and easy to understand.

It is easy to derive a continuous function, but the data in the image is digitized and discrete, so it is necessary to use the difference method for derivation: the gray value of the front pixel minus the gray value of the back pixel, and the result greater than a certain threshold is set as the edge, otherwise it is not the edge. We use a mathematical formula to express it: I (x ~ m y)-I (x ~ m m n ~ y). The formula gives that two pixels are in the same row, two pixels can also be in the same column, and the direction can be changed.

According to the previous template, the derivation of only one dimension can be expressed as follows:

The horizontal and vertical edges of the original image can be obtained by using the above two templates, and then the union of the two is the edge of the image as a whole. But a careful partner will surely find that which of the two elements after the template is the center of the template? To solve this problem, the researchers extended it into the following template:

The problem that the template has no "center" can be solved by changing the length of the template to an odd number. After a variety of evolution, it eventually becomes the template mentioned in the previous lectures. Partners can directly use their templates in the process of use, and Matlab is also a function with sobel edge extraction, so there is no need for partners to write complex programs themselves.

Commonly used sobel Edge extraction template

Roberts operator

In fact, many operators draw lessons from the idea of sobel method, Roberts operator detection method for steep low-noise image processing effect is better, but using roberts operator to extract the edge of the result is relatively thick, so the edge location is not very accurate. We directly give the template of the Roberts operator:

Through the template, we can also see that the algorithm is to detect the gradient change of the oblique direction to determine the edge of the image.

Canny operator

Canny operator is the most commonly used algorithm for edge detection at present, and the effect is the most ideal. But Canny edge detection algorithm is not a simple template convolution, through the gradient direction and double threshold method to detect edge points, the specific algorithm to explain, you can click "original text to read" to learn more:

The Canny method is not easily disturbed by noise and can detect the real weak edge. The advantage is that two different thresholds are used to detect the strong edge and the weak edge respectively, and when the weak edge and the strong edge are connected, the weak edge is included in the output image.

Matlab edge extraction

Matlab provides a variety of edge detection methods, through the function edge (image,'method') to achieve image edge extraction, by modifying the parameter 'method' to achieve different filtering methods. The specific edge detection code is as follows:

I=imread ('lena.bmp');% extract image

I=rgb2gray (I);% convert color image to grayscale image

BW1=edge (I ~ 2);% use SOBEL operator for edge detection

BW2=edge (I recall roberts); use Roberts operator for edge detection

BW3=edge (I recall prewitt);% use prewitt operator for edge detection

BW4=edge (I recorder log');% use log operator for edge detection

BW5=edge: canny operator is used for edge detection.

Subplot (2, 3, 1), imshow (BW1)

Title ('sobel edge check')

Subplot (2 and 3), imshow (BW2)

Title ('roberts edge check')

Subplot (2, 3, 3), imshow (BW3)

Title ('prewitt edge check')

Subplot (2, 3, 4), imshow (BW4)

Title ('log edge check')

Subplot (2, 3, 5), imshow (BW5)

Title ('canny edge check')

Copy the above code to Matalb, change the image address to the image you want to extract the edge of the image, run to get the edge of the image. The result of Xiaobai running the program on his computer is as follows. In the program, other operators are also used to extract edges to facilitate the comparison of small partners.

Thank you for reading this article carefully. I hope the article "how to achieve Image Edge extraction in Matlab" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report