Image edge extraction method based on Canny detection operator optimization
By optimizing the non-maximum suppression process of the Canny detection operator, setting selected extraction intervals, lagging edge tracking and adaptive threshold selection, the problems of the Canny algorithm's high computational complexity and noise sensitivity in image edge detection are solved, and more efficient and accurate edge detection is achieved.
Patent Information
- Application Number
- CN202411886713.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-20
- Publication Date
- 2025-04-11
AI Technical Summary
In image edge detection, the Canny algorithm has problems such as high computational complexity, slow processing speed, noise sensitive, difficult parameter setting, edge fracture and edge feature distortion under dark light source conditions.
Improve image edge extraction method by optimizing the non-maximum suppression process of the Canny detection operator, setting selected extraction intervals, lag edge tracking and adaptive threshold selection.
It significantly improves the accuracy and robustness of edge detection, reduces the generation of pseudo-edges, enhances the continuity and integrity of edges, and maintains good detection results under dark light source conditions.
Smart Images

Figure CN119810130A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of image detection, and in particular relates to an image edge extraction method based on Canny detection operator optimization. Background Art
[0002] The Canny detection operator mainly includes five steps: Gaussian filtering, pixel gradient calculation, non-maximum suppression, double threshold limiting, and hysteresis edge tracking. It is mainly used in image processing to identify and locate edges in images. The current problems of the Canny operator are: the Canny algorithm contains multiple steps, such as Gaussian filtering, calculating gradient amplitude, non-maximum suppression and double threshold processing, so the calculation process is relatively complex and the operation speed is slow, especially for high-resolution images, the processing time may be relatively long; when the Canny algorithm uses Gaussian filtering, although it can remove noise, it may also smooth out some edge information, resulting in weak edges and isolated edges being ignored; in addition, the calculation of gradient amplitude is very sensitive to noise, and it is easy to detect false edges or miss real edges; in the Canny algorithm, multiple parameters need to be manually set, such as the standard deviation of the Gaussian filter, high and low thresholds, etc. The selection of these parameters has a great influence on the edge detection results, and needs to be adjusted on different images, which increases the difficulty of using the algorithm; in the edge detection process, the Canny algorithm may produce edge breakage, especially when the edge connection is discontinuous, which will affect the final detection effect; under dark light conditions, the edge features extracted by the Canny operator may be distorted, resulting in missed recognition or wrong recognition; the Canny operator is sensitive to the width and shape of the edge, and may miss or misdetect some edges. Scholars at home and abroad have proposed many algorithms related to Canny edge detection. For example, an edge detection method based on the Canny algorithm first combines the improved adaptive median filter to reduce image noise, thereby better filtering out the interference of salt and pepper noise while retaining image details. Then, the image edge is detected using a local adaptive threshold segmentation algorithm, which is better at removing noise and runs faster, and the resulting image is clearer. However, since the invention focuses on reducing salt and pepper noise, it does not have a very amazing effect on detecting image boundaries. Summary of the invention
[0003] In order to solve the above problems existing in the prior art, the present invention provides a
[0004] The purpose of the present invention can be achieved through the following technical solutions:
[0005] An image edge extraction method based on Canny detection operator optimization, comprising:
[0006] Acquire a source image, convert the source image into a grayscale image and perform a downsampling operation on the grayscale image to obtain a downsampled image, filter the downsampled image, calculate the gradient amplitude and direction of the filtered image to obtain a gradient amplitude image; remove non-edge points from the gradient amplitude image by optimizing a non-maximum suppression process and save the candidate image edge;
[0007] By setting a selected extraction interval, the candidate image edge whose gradient value is higher than the upper limit of the selected extraction interval is defined as a true edge, the candidate image edge whose gradient value is between the selected extraction interval is defined as a weak edge, and the candidate image edge whose gradient value is lower than the lower limit of the selected extraction interval is set to 0;
[0008] The weak edge is subjected to delayed edge tracking to determine whether the weak edge is continuous with the strong edge. If so, the weak edge is set as a true edge; if not, the weak edge is removed.
[0009] Specifically, the filtering adopts a filter kernel to smooth the image, and modifies the filter kernel function by dynamically setting the filter window length and variance so that the convolution kernel size changes with the variance; the filter kernel function adopts a discretized Gaussian function to generate a set of normalized Gaussian kernels, and then performs a convolution operation on the grayscale matrix of the image based on the Gaussian kernel function to filter out high-frequency signals.
[0010] Specifically, the gradient amplitude and direction calculation method is calculated by gradient operators, and the gradient operators include median difference operator, Kirsch operator, Sobel operator, Prewitt operator, Scharr operator, and Robinson operator; the corresponding gradient operator is selected for amplitude and direction calculation according to the noise processing standard of the source image, edge positioning requirements, and system calculation complexity constraints.
[0011] Specifically, the optimization method of the non-maximum suppression process is: when searching for the local maximum value, the suppression is changed from when the center point is less than or equal to the points on both sides to when the center point is less than the points on both sides, and the suppression is exempted for the specific directions of 0°, 90°, and 180°.
[0012] Specifically, the upper and lower bounds of the selected extraction interval are calculated by the histogram of the grayscale image, and the upper and lower bounds of the selected extraction interval are defined according to the threshold corresponding to the area falling within the histogram proportion, and the threshold is obtained by an adaptive threshold selection method.
[0013] Specifically, the lagging edge tracking extracts structural information through morphological transformation to obtain a binary image, and performs connectivity determination on image coordinates corresponding to the weak edge and the strong edge based on the binary image.
[0014] Specifically, the morphological transformation method is: the weak edge point is marked to generate a marked image, the image area participating in the morphological transformation is constrained by a preset mask image; connectivity is defined by a structural element; the filtered image is initialized by the marked image, and the initialized image is iteratively reconstructed according to the structural element and the mask image to obtain the binary image, and the calculation formula is: Where k is the number of iterations, B is the structural element, G is the mask image, and when k=1, h k Represents the initialized image, and the termination condition of the iteration is h k+1 =h k , after the iteration is completed, h k+1 The corresponding image is used as the binary image.
[0015] Specifically, the adaptive threshold selection method is: calculate the local mean and local standard deviation of the filtered image, and then dynamically adjust the upper threshold of the selected extraction interval according to the ratio of the local mean and the local standard deviation, and the lower threshold of the selected extraction interval is 0.4 times the upper threshold.
[0016] The beneficial effects of the present invention are:
[0017] The accuracy and robustness of edge detection are significantly improved, especially in images with more noise. By optimizing the non-maximum suppression process, the generation of pseudo edges is effectively reduced while retaining the real edge information. By carefully selecting the setting of the extraction interval, the algorithm can adaptively process the edge features of different images, thereby improving the flexibility of edge detection. The introduction of lagging edge tracking enhances the continuity of the edge, reduces the edge breakage phenomenon, and improves the integrity of edge detection. The edge extraction method of the present invention significantly improves the edge detection effect of high-resolution images while maintaining a high processing speed. Through the adaptive threshold selection method, the algorithm can automatically adjust parameters according to the image content, reducing manual intervention and simplifying the operation process. The edge extraction method of the present invention can more accurately identify edge features under dark light conditions, avoiding the distortion problem of edge features. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to facilitate understanding by those skilled in the art, the present invention is further described below with reference to the accompanying drawings.
[0019] Figure 1 The figure is a flow chart of an image edge extraction method based on Canny detection operator optimization according to the present invention. DETAILED DESCRIPTION
[0020] In order to further explain the technical means and effects adopted by the present invention to achieve the predetermined invention purpose, the specific implementation methods, structures, features and effects of the present invention are described in detail below in conjunction with the accompanying drawings and preferred embodiments.
[0021] See also Figure 1 , an image edge extraction method based on Canny detection operator optimization, comprising:
[0022] Acquire a source image, convert the source image into a grayscale image and perform a downsampling operation on the grayscale image to obtain a downsampled image, filter the downsampled image, calculate the gradient amplitude and direction of the filtered image to obtain a gradient amplitude image; remove non-edge points from the gradient amplitude image by optimizing a non-maximum suppression process and save the candidate image edge;
[0023] By setting a selected extraction interval, the candidate image edge whose gradient value is higher than the upper limit of the selected extraction interval is defined as a true edge, the candidate image edge whose gradient value is between the selected extraction interval is defined as a weak edge, and the candidate image edge whose gradient value is lower than the lower limit of the selected extraction interval is set to 0;
[0024] The weak edge is subjected to delayed edge tracking to determine whether the weak edge is continuous with the strong edge. If so, the weak edge is set as a true edge; if not, the weak edge is removed.
[0025] In this embodiment, the source image is first converted into a grayscale image, and then the image is downsampled by 2:2, and the downsampled image is Gaussian filtered; then the gradient amplitude and direction of the filtered image are calculated; then the gradient amplitude image is non-maximum suppressed, so as to remove most of the non-edge points and save the candidate image edge. In order to further accurately extract the edge, it is necessary to calculate the high and low thresholds of the image. For the gradient values above the high threshold, it is directly defined as the edge; for the gradient values below the low threshold, it is directly set to 0. For the gradient values between the high and low thresholds, it is temporarily defined as a weak edge, and delayed edge tracking is required. Since the edge is continuous, it can be considered that if the weak edge and the strong edge are connected, the weak edge is the real edge, otherwise it needs to be eliminated; the image reconstruction uses the imreconstruct (marker, mask, conn) function. The marker image (marker) marks the points where the morphological transformation starts, and the mask image (mask) constrains the area involved in the morphological transformation. The structural element is used to define connectivity. By default, 8-connectivity is used, that is, a 3*3 matrix is used with the center at (2,2).
[0026] Specifically, the filtering adopts a filter kernel to smooth the image, and modifies the filter kernel function by dynamically setting the filter window length and variance so that the convolution kernel size changes with the variance; the filter kernel function adopts a discretized Gaussian function to generate a set of normalized Gaussian kernels, and then performs a convolution operation on the grayscale matrix of the image based on the Gaussian kernel function to filter out high-frequency signals.
[0027] In this embodiment, high-frequency information in the image refers to rapid color changes, and low-frequency information refers to gentle color changes. The image edge that needs to be detected during edge detection belongs to high-frequency information. The noise part in the image also belongs to high-frequency information, so the image needs to be denoised. The purpose is to smooth some non-edge areas with weak texture to obtain more accurate edges.
[0028] Specifically, the gradient amplitude and direction calculation method is calculated by gradient operators, and the gradient operators include median difference operator, Kirsch operator, Sobel operator, Prewitt operator, Scharr operator, and Robinson operator; the corresponding gradient operator is selected for amplitude and direction calculation according to the noise processing standard of the source image, edge positioning requirements, and system calculation complexity constraints.
[0029] Specifically, the optimization method of the non-maximum suppression process is: when searching for the local maximum value, the suppression is changed from when the center point is less than or equal to the points on both sides to when the center point is less than the points on both sides, and the suppression is exempted for the specific directions of 0°, 90°, and 180°.
[0030] Specifically, the upper and lower bounds of the selected extraction interval are calculated by the histogram of the grayscale image, and the upper and lower bounds of the selected extraction interval are defined according to the threshold corresponding to the area falling within the histogram proportion, and the threshold is obtained by an adaptive threshold selection method.
[0031] Specifically, the lagging edge tracking extracts structural information through morphological transformation to obtain a binary image, and performs connectivity determination on image coordinates corresponding to the weak edge and the strong edge based on the binary image.
[0032] Specifically, the morphological transformation method is: the weak edge point is marked to generate a marked image, the image area participating in the morphological transformation is constrained by a preset mask image; connectivity is defined by a structural element; the filtered image is initialized by the marked image, and the initialized image is iteratively reconstructed according to the structural element and the mask image to obtain the binary image, and the calculation formula is: Where k is the number of iterations, B is the structural element, G is the mask image, and when k=1, h k Represents the initialized image, and the termination condition of the iteration is h k+1 =h k , after the iteration is completed, hk+1 The corresponding image is used as the binary image.
[0033] Specifically, the adaptive threshold selection method is: calculate the local mean and local standard deviation of the filtered image, and then dynamically adjust the upper threshold of the selected extraction interval according to the ratio of the local mean and the local standard deviation, and the lower threshold of the selected extraction interval is 0.4 times the upper threshold.
[0034] The computer storage medium of the embodiment of the present invention may adopt any combination of one or more computer-readable media. The computer-readable medium may be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, device or device.
[0035] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, which carry computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0036] The program code included on the computer readable medium can be transmitted with any appropriate medium, including but not limited to wireless, electric wire, optical cable, RF, etc., or any suitable combination of the above. The computer program code for performing the operation of the present invention can be written in one or more programming languages or their combinations, and the programming language includes object-oriented programming languages-such as Java, Smalltalk, C++, and also includes conventional procedural programming languages-such as "C" language or similar programming languages. The program code can be executed completely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer and partially on the remote computer, or completely on the remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computer (for example, using an Internet service provider to connect through the Internet).
[0037] The above description is only a preferred embodiment of the present invention and does not limit the present invention in any form. Although the present invention has been disclosed as a preferred embodiment as above, it is not used to limit the present invention. Any technical personnel in this field can make some changes or modify the technical contents disclosed above into equivalent embodiments without departing from the scope of the technical solution of the present invention. However, any simple modification, equivalent change and modification made to the above embodiments according to the technical essence of the present invention without departing from the content of the technical solution of the present invention still fall within the scope of the technical solution of the present invention.
Claims
1. An image edge extraction method based on Canny detection operator optimization, characterized in that: include: Acquire a source image, convert the source image into a grayscale image and perform a downsampling operation on the grayscale image to obtain a downsampled image, filter the downsampled image, calculate the gradient amplitude and direction of the filtered image to obtain a gradient amplitude image; remove non-edge points from the gradient amplitude image by optimizing a non-maximum suppression process and save the candidate image edge; By setting a selected extraction interval, the candidate image edge whose gradient value is higher than the upper limit of the selected extraction interval is defined as a true edge, the candidate image edge whose gradient value is between the selected extraction interval is defined as a weak edge, and the candidate image edge whose gradient value is lower than the lower limit of the selected extraction interval is set to 0; The weak edge is subjected to delayed edge tracking to determine whether the weak edge is continuous with the strong edge. If so, the weak edge is set as a true edge; if not, the weak edge is removed.
2. The method according to claim 1, characterized in that: The filtering adopts a filter kernel to smooth the image, and modifies the filter kernel function by dynamically setting the filter window length and variance so that the convolution kernel size changes with the variance; the filter kernel function adopts a discretized Gaussian function to generate a set of normalized Gaussian kernels, and then performs a convolution operation on the grayscale matrix of the image based on the Gaussian kernel function to filter out high-frequency signals.
3. The method according to claim 1, characterized in that The gradient amplitude and direction calculation method is calculated by gradient operators, and the gradient operators include median difference operator, Kirsch operator, Sobel operator, Prewitt operator, Scharr operator, and Robinson operator; the corresponding gradient operator is selected for amplitude and direction calculation according to the noise processing standard of the source image, edge positioning requirements, and system calculation complexity constraints.
4. The method according to claim 1, characterized in that: The optimization method of the non-maximum suppression process is: when searching for the local maximum value, the suppression is changed from when the center point is less than or equal to the points on both sides to when the center point is less than the points on both sides, and the suppression is exempted for the specific directions of 0°, 90°, and 180°.
5. The method according to claim 1, characterized in that The upper and lower bounds of the selected extraction interval are calculated by the histogram of the grayscale image, and the upper and lower bounds of the selected extraction interval are defined according to the threshold corresponding to the area falling within the histogram proportion, and the threshold is obtained by an adaptive threshold selection method.
6. The method according to claim 1, characterized in that The lagging edge tracking extracts structural information through morphological transformation to obtain a binary image, and performs connectivity determination on image coordinates corresponding to the weak edge and the strong edge based on the binary image.
7. The method according to claim 6, characterized in that The morphological transformation method is: the weak edge points are marked to generate a marked image, the image area participating in the morphological transformation is constrained by a preset mask image; connectivity is defined by a structural element; the filtered image is initialized by the marked image, and the initialized image is iteratively reconstructed according to the structural element and the mask image to obtain the binary image. The calculation formula is: Where k is the number of iterations, B is the structural element, G is the mask image, and when k=1, h k Represents the initialized image, and the termination condition of the iteration is h k+1 =h k , after the iteration is completed, h k+1 The corresponding image is used as the binary image.
8. The method according to claim 5, characterized in that The adaptive threshold selection method is: calculating the local mean and local standard deviation of the filtered image, and then dynamically adjusting the upper threshold of the selected extraction interval according to the ratio of the local mean and the local standard deviation, and the lower threshold of the selected extraction interval is 0.4 times the upper threshold.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the image edge extraction method based on Canny detection operator optimization as described in any one of claims 1 to 8 is implemented.
10. A storage medium containing computer executable instructions, characterized in that: The computer executable instructions are used to execute the image edge extraction method based on Canny detection operator optimization as described in any one of claims 1 to 8 when executed by a computer processor.
Citation Information
Cited By
Intelligent detection and identification method for metal bent pipe based on image processing
CN120471889A
System for identifying candida albicans in pathological section image
CN121259812A