Crack sub-pixel precision edge detection method and system based on improved Canny operator
By improving the Canny operator and combining it with weighted guided filtering, multi-directional Sobel operator, maximum inter-class variance method and Zernike orthogonal moments, the problem that the traditional Canny operator cannot achieve sub-pixel level crack detection is solved, and high-precision and fast crack edge detection is achieved.
Patent Information
- Application Number
- CN202511629074.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-07
- Publication Date
- 2026-02-10
Smart Images

Figure CN121504967A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of crack detection technology, specifically to a crack sub-pixel precision edge detection method and system based on an improved Canny operator. Background Technology
[0002] As engineering structures age, their structural safety becomes increasingly important, and cracks are closely related to structural safety. Currently, crack detection is divided into contact and non-contact methods; however, both measurement processes are susceptible to human error, leading to objectivity and insufficient detection accuracy. With the rapid development of computer vision and digital image processing technologies, their convenience and automation have enabled their rapid adoption in the field of engineering crack detection.
[0003] Traditional methods for detecting cracks in structural images typically involve first detecting the crack edges, then extracting the crack pixel image, and finally calculating the relevant crack parameters. However, traditional edge detection algorithms can only detect integer pixels; when the crack width is less than 2 pixels, the method cannot identify the crack, failing to achieve sub-pixel accuracy. To achieve sub-pixel accuracy, conventional edge detection algorithms must be improved. In image edge processing, the Canny operator is commonly used. While traditional Canny edge detection technology can achieve relatively good results in some detection areas, its accuracy is limited to the pixel level, failing to meet the 0.1mm accuracy requirement. Furthermore, the environment in which structural cracks are located often contains various interference factors, making it difficult for conventional algorithms to capture detailed crack edge information. These issues lead to problems such as false positives and false negatives in crack edge contour detection and weak edge connectivity when using the traditional Canny operator to detect structural cracks. Meanwhile, conventional image processing methods often require setting up calibration objects around the crack when calculating crack-related parameters to calculate the conversion coefficient between the actual physical size and image pixels. This often results in cumbersome and time-consuming operations in practical applications, making it impossible to quickly detect multiple targets. Summary of the Invention
[0004] To overcome the problem of insufficient crack detection accuracy in the existing technology, this invention provides a crack subpixel precision edge detection method and system based on the improved Canny operator. First, the improved Otsu's method is used to obtain the pixel-level coordinates of the edge points. Then, the improved Zernike orthogonal moments are used to further process the edge information, so as to improve the crack edge detection accuracy to the subpixel level.
[0005] According to one aspect of the present invention, a crack subpixel precision edge detection method based on an improved Canny operator is provided, comprising: acquiring a crack image corresponding to a crack on the surface of a structure; preprocessing the crack image; performing gradient calculation on the preprocessed crack image using an improved Sobel operator to obtain a gradient image containing gradient magnitude and gradient direction; performing nonmaximum suppression on the gradient image and adaptively obtaining an optimal threshold using an improved maximum inter-class variance method, so as to determine the crack edge according to the optimal threshold, thereby obtaining a coarse edge pixel-level image;
[0006] The edge information in the coarse-edge pixel-level image is processed using Zernike orthogonal moments to obtain the sub-pixel-level coordinates of the edge points; all edge points are connected to output the crack detection result image.
[0007] Furthermore, the crack image is preprocessed, including: converting the image to grayscale using a weighted average method; and performing edge-preserving smoothing and noise reduction using weighted guided filtering.
[0008] Furthermore, the preprocessed crack image is subjected to gradient calculation using an improved Sobel operator to obtain a gradient image containing gradient magnitude and gradient direction. This includes: traversing the preprocessed crack image through a matrix template in four directions to obtain gradient magnitudes in four directions; and using the gradient magnitudes in the four directions to calculate the final gradient magnitude and gradient direction, thereby obtaining a gradient image containing gradient magnitude and gradient direction.
[0009] Further, non-maximum suppression is performed on the gradient image, including: comparing the gradient magnitude of each pixel in the gradient image with the gradient magnitude of two adjacent pixels along the gradient direction of the pixel; if the gradient magnitude of the current pixel is greater than the gradient magnitude of two adjacent pixels along the same gradient direction, the current pixel is considered an edge point and its pixel value is retained; otherwise, the current pixel is suppressed.
[0010] Furthermore, an improved maximum inter-class variance (MOL) algorithm is used to adaptively determine the optimal threshold. The optimal threshold is then used to determine the crack edges, thereby obtaining a coarse-edge pixel-level image. This includes: dividing the gradient image into foreground and background based on the grayscale value of each pixel and the threshold; calculating the inter-class variance between the foreground and background corresponding to different thresholds; determining the threshold corresponding to the maximum inter-class variance as the optimal threshold, and determining a high threshold and a low threshold based on the optimal threshold; identifying pixels with grayscale values greater than the high threshold as strong edge points and retaining them; identifying pixels with grayscale values less than the low threshold as non-edge points and discarding them; identifying pixels with grayscale values between the high and low thresholds as weak edge points; retaining the pixel if a strong edge point exists within the 8-neighborhood of the weak edge point; and discarding the pixel if no strong edge point exists within the 8-neighborhood of the weak edge point, thereby obtaining the pixel-level coordinates of all edge points.
[0011] Edges are detected and connected by connected component analysis, thereby obtaining pixel-level images with coarse edges.
[0012] Furthermore, the edge information in the coarse-edge pixel-level image is processed using Zernike orthogonal moments to obtain the sub-pixel-level coordinates of the edge points, including: obtaining four integral kernel functions of the coarse-edge pixel-level image based on Zernike orthogonal moments; obtaining edge parameters based on the geometric relationship between the four integral kernel functions and the three-grayscale transition model; and calculating the sub-pixel-level coordinates of all edge points according to the edge parameters.
[0013] Furthermore, based on the geometric relationship between the four integral kernel functions and the three-grayscale transition model, the edge parameters are obtained, and the corresponding formulas are as follows:
[0014] ,
[0015] ,
[0016] ,
[0017] ,
[0018] ,
[0019] in, , , , Both are integral kernel functions; , , and All are edge parameters. This represents the step grayscale transition between the background and the target in the first stage. This represents the step grayscale transition between the background and the target in the second stage. , These are the distances between the center and the left and right boundaries of the transition area, respectively; d is the distance from the origin to the edge line; and a represents the distance of each pixel in the template.
[0020] Furthermore, the sub-pixel level coordinates of all edge points are calculated based on the edge parameters, and the corresponding edge point coordinate correction formula is as follows:
[0021] = ,
[0022] in, The pixel-level coordinates of the edge points The coordinates of the corrected edge points are subpixel level, where N is the template size. Rotation angle.
[0023] Furthermore, after connecting all edge points and outputting the crack detection result image, the detection method further includes:
[0024] Morphological operations are performed on the crack detection result image to extract the crack; crack-related parameters are obtained; the crack-related parameters include the total pixel length, maximum width pixel value, and average width of the crack; calibration coefficients are calculated, and the crack-related parameters are calibrated using the calibration coefficients.
[0025] Furthermore, a lens protective cover is used to fix the detection distance, thereby calculating the calibration coefficient using the linear calibration method, and using the calibration coefficient to calibrate the crack-related parameters.
[0026] According to one aspect of the present invention, a crack subpixel precision edge detection system based on an improved Canny operator is provided, comprising: an image acquisition module for acquiring a crack image corresponding to a crack on the surface of a structure; a preprocessing module for preprocessing the crack image; a gradient calculation module for calculating the gradient magnitude and gradient direction of the preprocessed crack image using an improved Sobel operator to obtain a gradient image containing the gradient magnitude and gradient direction; a coarse pixel-level edge detection module for performing nonmaximum suppression on the gradient image and adaptively obtaining an optimal threshold using an improved maximum inter-class variance method to determine the crack edge based on the optimal threshold, thereby obtaining a coarse edge pixel-level image; a subpixel-level edge detection module for processing the edge information in the coarse edge pixel-level image using Zernike orthogonal moments to obtain the subpixel-level coordinates of the edge points; and a detection result output module for connecting all edge points and outputting a crack detection result image.
[0027] The above technical solution can improve the accuracy of crack edge detection to the sub-pixel level. Specifically, weighted guided filtering is used to perform edge-preserving smoothing and noise reduction on the acquired crack image; an improved Sobel operator with four directions is used to calculate the gradient to obtain a gradient image containing gradient magnitude and gradient direction, thereby preserving more image edge information and ensuring edge continuity; then, the maximum inter-class variance method is used to adaptively obtain the optimal threshold, and the crack edge is judged based on the optimal threshold to obtain the pixel-level coordinates of the edge points, thus obtaining a coarse edge pixel-level image; finally, an improved Zernike orthogonal moment is used to further process the coarse edge pixel-level image to obtain the sub-pixel coordinates of the edge points, thereby achieving fast and high-precision edge detection.
[0028] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0029] (1) In view of the poor noise reduction effect of Gaussian filtering, the present invention uses an improved guided filtering: weighted guided filtering to reduce noise while preserving crack details, and avoids the filter from producing halo artifacts near the image edge.
[0030] (2) The present invention uses a multi-directional Sobel operator to retain more image edge information and solves the problem of poor edge continuity.
[0031] (3) The present invention achieves adaptive thresholding by using the maximum inter-class variance method, eliminating the need for manual threshold determination, avoiding interference from human factors, and ensuring the accuracy of image processing.
[0032] (4) This invention uses an improved Zernike orthogonal moment to further process the edge information in the coarse edge pixel-level image to obtain the coordinates of the sub-pixel edge points. At the same time, a three-grayscale transition model is used instead of the traditional step model to consider the influence of the edge transition area on the sub-pixel positioning accuracy, thereby avoiding the principle error caused by using the step model to calculate the edge parameters, achieving the detection accuracy to the sub-pixel level, meeting the needs of engineering detection, and also improving the calculation efficiency.
[0033] (5) The present invention uses a special lens cover to fix the detection distance, thereby simplifying the steps of setting the calibration object, improving detection efficiency, and making the operation convenient. Attached Figure Description
[0034] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the accompanying drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0035] Figure 1 The flowchart illustrates a crack subpixel precision edge detection method based on the improved Canny operator, provided as an embodiment of the present invention.
[0036] Figure 2 The image of the crack is captured by a camera according to an embodiment of the present invention.
[0037] Figure 3 This is a schematic diagram of the grayscale transformation result of a crack image provided in an embodiment of the present invention.
[0038] Figure 4 This is a schematic diagram illustrating the transformation of a crack image before and after weighted guided filtering processing, as provided in an embodiment of the present invention.
[0039] Figure 5 This is a schematic diagram of the results after processing by the Sobel operator in four directions according to an embodiment of the present invention.
[0040] Figure 6 This is a schematic diagram comparing the results of the traditional Sobel operator and the improved Sobel operator of this invention as provided in an embodiment of the invention.
[0041] Figure 7 This is a schematic diagram of the edge three-grayscale transition model provided in an embodiment of the present invention.
[0042] Figure 8 The image provided in this embodiment of the invention is a subpixel-level crack edge image processed by the improved Canny operator.
[0043] Figure 9 The image shows a crack after image morphology manipulation, as provided in an embodiment of the present invention.
[0044] Figure 10 The crack skeleton line diagram obtained from the extraction is provided in the embodiment of the present invention.
[0045] Figure 11 A schematic diagram of a specially designed camera lens cover provided for an embodiment of the present invention. Detailed Implementation
[0046] It should be noted that:
[0047] The terms “comprising” and “having”, and any variations thereof, in the specification, claims, and accompanying drawings of this invention are intended to cover a non-exclusive inclusion, such as a process, method, system, product, or apparatus that includes a series of steps or units, not necessarily limited to those explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0048] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities can be implemented in software, in one or more hardware modules or integrated circuits, or in different network and / or processor devices and / or microcontroller devices. The flowcharts shown in the accompanying drawings are merely illustrative and do not necessarily include all content and operations / steps, nor do they necessarily have to be performed in the described order. For example, some operations / steps can be decomposed, while others can be combined or partially combined; therefore, the actual execution order may change depending on the specific circumstances.
[0049] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention. In addition, the technical features of the various embodiments or individual embodiments provided by the present invention can be arbitrarily combined to form new technical solutions. Such combinations are not bound by the order of steps and / or structural composition patterns, but must be based on the ability of those skilled in the art to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection claimed by the present invention.
[0050] Please refer to Figure 1 This invention provides a crack sub-pixel precision edge detection method based on an improved Canny operator, specifically including the following steps (steps S1 to S6):
[0051] Step S1: Obtain the crack image corresponding to the crack on the structure surface. In this embodiment, an industrial camera is used to photograph the crack on the structure surface to obtain the required three-channel crack image. The resolution of the three-channel crack image is 1286*800 (as shown in the attached image). Figure 2 (As shown).
[0052] Step S2: Preprocess the crack image (including steps S21 to S22).
[0053] Step S21: Perform image grayscale conversion using a weighted average method (including steps S211 to S212).
[0054] Step S211: Read the pixel values of the crack image. Specifically, for a color image (such as an RGB image), the pixel value of each pixel is usually composed of the values of three components: red (R), green (G), and blue (B). The pixel value is used to define the color of a single pixel in the image. By reading the pixel values of the crack image, the RGB components of each pixel in the crack image can be obtained.
[0055] Step S212: A weighted average of the RGB components of each pixel in the crack image is performed to obtain a grayscale value, which is then assigned to the corresponding pixel. It should be noted that this invention considers the need to enhance image contrast for crack detection and the shortcomings of other commonly used methods that are not conducive to high-precision edge detection. Therefore, a grayscale weighted average method is used to perform a weighted average of the RGB components of each pixel to obtain a grayscale value, which is then assigned to the corresponding pixel to achieve grayscale conversion of the crack image (results are shown in the appendix). Figure 3 This transforms the crack image from a three-channel image to a single-channel image, preserving image information while reducing data volume, thus facilitating further calculations and data processing. The corresponding calculation formula is as follows: , This represents the coordinates of a pixel in the crack image. Indicating cracks in the image The pixel value at that pixel. These represent the crack images respectively. The red, green, and blue components of each pixel.
[0056] Step S22: Use weighted guided filtering to perform edge-preserving smoothing and noise reduction.
[0057] In step S22, weighted guided filtering is used instead of traditional Gaussian filtering to perform edge-preserving smoothing and noise reduction on the crack image. Weighted guided filtering is an improvement on guided filtering, which is an image filter based on a local linear model. Guided filtering constructs a new filter by setting a guide image and utilizing the difference between the guide image and the image to be filtered. It should be noted that both the guide image and the image to be filtered in this step are grayscale images from step S21.
[0058] 1) The specific principle of guided filtering is as follows: Assume that the output image O is the guiding image G in a window centered on pixel p. The relationship between the output image O and the guiding image G under a linear transformation on the x-axis can be defined as follows:
[0059] ,
[0060] Where i is the value in the guiding image G The pixel number at the bottom of the window To guide the pixel value of image G at pixel position i, This is to output the pixel value at pixel position i in image O. , A window centered at pixel p The linear coefficients (constants) obtained from internal calculations are essentially what guided filtering is about solving for. The energy function. To determine the linear coefficients so that the filter output image... and filter input image The difference between them is the smallest, that is, within the window. Minimize the following cost constraint function:
[0061] ,
[0062] in, This represents the cost constraint function (i.e., the energy function). For regularization parameters, however, due to the regularization parameters The regularization parameter is a constant, which results in flat and edge regions of the image having the same weight. Edge regions are easily smoothed, leading to halo artifacts near the edges, which is detrimental to image detection. To solve this problem, this invention borrows the idea of weighted least squares filters and adapts the regularization parameter: using the ratio of the variance of the current window to the sum of the variances of all windows in the image as the edge-aware weight of the current pixel, the regularization parameter adapts to different image regions, significantly improving the processing effect at image edges.
[0063] 2) The specific principle of weighted guided filtering is as follows:
[0064] Edge-aware weights are defined as follows: ,
[0065] in, The pixel position in the guiding image G is Edge-aware weights is the index of the image pixel, and N is the total number of image pixels. This is a regularization constant used to prevent the denominator from being zero. It is a small constant with a value of , It represents the brightness difference of the input image. It is the variance of the image processing window. Therefore, the first The variance of a window centered on a pixel Therefore, the first The variance of a window centered on a pixel. To remove outliers, edge-aware weights are used. A Gaussian smoothing was applied. Therefore, the energy function can be written as:
[0066] ,
[0067] in, It is a constant. The partial derivative of the new energy function is used to solve for it. :
[0068] ),
[0069] Will Recorded as , Recorded as ,Right now , The input images for the filters are respectively and filter output image The window mean, i.e. .
[0070] Similarly, For window variance, Recorded as , Recorded as ,but:
[0071] ,
[0072] in, It is the number of pixels in the current window, further based on ( These are the corresponding linear coefficients within the window. The output image is obtained by calculating the mean of the values (see attached image). Figure 4 ).
[0073] To verify the effectiveness of the filtering, multiple noise reduction filters were applied to the same grayscale image (using the image used in the example). At the same time, two popular metrics in image segmentation were used to evaluate the quality of the segmented image: Peak Signal-to-Noise Ratio (PSNR) and Structural Similarity Index (SSIM). As shown in Table 1, the PSNR and SSIM values of the same crack image after median filtering, Gaussian filtering, bilateral filtering, and weighted guided filtering are displayed.
[0074] Table 1. PSNR and SSIM values of the same crack image processed by median, Gaussian, bilateral, and weighted guided filters.
[0075] Filtering index Median Gauss bilateral guide Weighted guidance PSNR 26.31 28.46 27.07 30.29 31.25 SSIM 0.17 0.22 0.18 0.27 0.28
[0076] The analysis in the table above shows that the weighted guided filter is more effective and superior to other filters.
[0077] Step S3: Perform gradient calculation on the preprocessed crack image using the improved Sobel operator to obtain a gradient image containing gradient magnitude and gradient direction.
[0078] In step S3, the traditional Sobel operator only considers the x (0°) and y (90°) directions when calculating gradients, which cannot retain more image edge information or ensure edge continuity. The improved Sobel operator in this invention adds two more directions, 45° and 135°, and uses a four-directional Sobel operator to calculate the gradient magnitude and gradient direction of the crack image (specifically including steps S31 to S32).
[0079] Step S31: Traverse the preprocessed crack image using matrix templates in four directions to obtain gradient magnitudes in the four directions.
[0080] In step S31, the matrix templates in the four directions are used to traverse the original crack image, which is equivalent to recalculating the pixel values of the original crack image, thereby traversing the entire crack image. In this embodiment, the convolution templates (i.e., matrix templates) in the four directions all adopt a 3*3 size, and the improved Sobel operator is shown below:
[0081] , ,
[0082] , .
[0083] The crack image is convolved in the x, y, 45°, and 135° directions using the four matrix templates mentioned above. This allows for the calculation of the gradient magnitude of each pixel in the crack image in these four directions, which is then used to... The results are attached. Figure 5 .
[0084] Step S32: Calculate the final gradient magnitude and gradient direction using the gradient magnitudes in the four directions, and then obtain a gradient image containing the gradient magnitude and gradient direction.
[0085] In step S32, the gradient magnitudes in four directions are used. The formulas for calculating the final gradient magnitude and gradient direction are as follows:
[0086] ,
[0087] ,
[0088] ,
[0089] ,
[0090] in, These are the pixel coordinates in the crack image. These are the gradient magnitude components of the pixel in the x and y directions, respectively. This represents the gradient direction at that pixel. (See attached image) Figure 6 A comparison of the results of the traditional Sobel operator and the improved Sobel operator of this invention shows that the four-directional Sobel operator obtains more details.
[0091] Step S4: Perform non-maximum suppression on the gradient image and use an improved maximum inter-class variance method to adaptively obtain the optimal threshold. Based on the optimal threshold, the crack edge is determined, thereby obtaining a coarse edge pixel-level image.
[0092] In step S4, the present invention first performs non-maximum suppression. Next, the present invention uses the maximum inter-class variance method to adaptively obtain the optimal threshold, eliminating the need for manual determination of the optimal threshold, avoiding interference from human factors, and ensuring the accuracy of image processing (specifically including steps S41 to S42). Edge points are further filtered using the obtained optimal threshold.
[0093] Step S41: Perform non-maximum suppression on the gradient image. Specifically, compare the gradient magnitude of each pixel in the gradient image with the gradient magnitudes of two adjacent pixels along the gradient direction of that pixel. If the gradient magnitude of the current pixel is greater than the gradient magnitudes of two adjacent pixels along the same gradient direction, then the current pixel is considered an edge point, and its pixel value is retained. Otherwise, the current pixel is suppressed, and its pixel value is marked as 0.
[0094] Step S42: Adaptively determine the optimal threshold using the improved Otsu's method to judge the crack edge based on the optimal threshold, thereby obtaining a coarse edge pixel-level image.
[0095] In step S42, the improved Otsu's algorithm adaptively determines the optimal threshold, increasing the algorithm's adaptability and resulting in more complete and accurate edges. This algorithm divides the gradient image into foreground and background based on the grayscale values of each pixel. If the target gradient image is M×N in size and contains L different grayscale levels, the Otsu's algorithm calculates the variance of the corresponding pixel grayscale values from 0 to L-1. Through continuous comparison, the maximum class variance of the foreground and background is finally obtained; the larger the variance, the more accurate the classification. In M×N images containing L different grayscale levels, the total number of pixels corresponding to a certain grayscale value is... The probability of a certain pixel I is ,but:
[0096] .
[0097] Assuming the threshold is k, The image pixel grayscale is divided into two categories: foreground and background. and background The grayscale ranges for these two levels are as follows: Therefore, a certain pixel falls on and The probability of it being on is , ,but:
[0098] ,
[0099] .
[0100] prospect and background The average gray values are respectively and As shown below:
[0101] ,
[0102] .
[0103] The average gray level of the entire image is ,but: .
[0104] Gain prospects and background Maximum inter-class variance:
[0105] ,
[0106] in, This represents the between-group variance (i.e., the between-class variance). We calculate the between-group variance for different k values, and the k value corresponding to the largest between-class variance is the optimal threshold. This optimal threshold is then set as the high threshold. The corresponding low threshold is For example, when image processing yields a high threshold... The corresponding low threshold is 26. Then, based on the obtained dual thresholds, pixels with grayscale values greater than the high threshold are identified as strong edge points, which are always edge points and are retained. Pixels with grayscale values less than the low threshold are identified as non-edge points and discarded. Pixels with grayscale values between the high and low thresholds are identified as weak edge points. The retention of weak edge points is determined by whether there is a strong edge point within their 8-neighborhood (i.e., the eight adjacent pixels above, below, left, right, upper left, upper right, lower left, and lower right). If a strong edge point exists within the 8-neighborhood, the pixel is retained; otherwise, it is discarded. This yields the pixel-level coordinates of all edge points. Finally, connected component analysis is used to detect and connect edges, thus obtaining a coarse-edge pixel-level image.
[0107] Step S5: Use Zernike orthogonal moments to process the edge information in the coarse-edge pixel-level image to obtain the coordinates of the sub-pixel edge points.
[0108] In step S5, this invention further processes the edge information of the coarse-edge pixel-level image obtained in step S4 by employing an improved Zernike orthogonal moment (ZOM) with a 7*7 template. Simultaneously, a three-grayscale transition model is used instead of the traditional step model to account for the impact of the edge transition zone on sub-pixel positioning accuracy. This avoids the fundamental errors caused by calculating edge parameters using the step model, achieving sub-pixel level detection accuracy and improving crack detection accuracy to the 0.01mm level, meeting the needs of engineering inspection while also improving computational efficiency. Specifically:
[0109] Step S51: Obtain four integral kernel functions for coarse edge pixel-level images based on Zernike orthogonal moments.
[0110] In step S51, the Zernike orthogonal moments of order m of the nth order of the grayscale image are defined as follows:
[0111] ,
[0112] in, It is the grayscale value of a specific pixel in a pixel-level image with coarse edges. It is a Zernike polynomial The complex conjugate of . n is the radial order, representing the Zernike polynomial in the radial direction ( The highest frequency in the angular direction. m is the azimuthal frequency, representing the azimuthal direction ( The frequency of the sine / cosine term of ) must satisfy: n ≥ |m|, where n−m is an even number. This invention derives the required ZOM expression (i.e., the four integral kernel functions) based on the above definition of Zernike orthogonal moments: , , , .
[0113] Furthermore, this invention utilizes the rotation invariance of Zernike orthogonal moments (i.e., the magnitude of the ZOM image remains unchanged before and after rotation, only the phase angle changes) to obtain the rotation angle. The rotational invariance of Zernike moments lies in the fact that if the image is rotated counterclockwise... Images before and after rotation and The relationship is , It is the imaginary unit, based on the four integral kernel functions calculated earlier. , , , It can be known that when hour , hour , To obtain the rotation angle ,according to The time characteristics give us the relationship before and after the rotation: We can obtain... Derivation:
[0114] ,
[0115] , , Represent The real and imaginary parts, It is the Zernike moment after rotation. Represents the integral kernel function The corresponding rotation angles, including and It should be noted that, theoretically and These two angles are the same, but in reality, noise can cause them to differ. Therefore, this invention also needs to further refine the design. and Further processing (using existing techniques, such as weighted average, voting or consensus selection, maximum a posteriori probability estimation, etc., not limited here) is required to obtain the final rotation angle. .
[0116] Step S52: Obtain edge parameters based on the geometric relationship of the four integral kernel functions and the three grayscale transition model.
[0117] In step S52, due to the limitations of non-ideal discrete sampling and diffraction effects of optical systems in practice, a transition region exists near the edge of the area to be detected. To describe the grayscale that corresponds to the actual transition region, this invention employs an edge three-grayscale transition model, as shown in the appendix. Figure 7 The dashed line represents the ideal step model at the edge, and the solid line represents the three-grayscale transition model. It is the background grayscale value (known). It is the grayscale value of the transition zone. It is the target grayscale value. These are the distances between the center and the left and right boundaries of the transition zone, respectively.
[0118] Furthermore, this invention combines the four integral kernel functions calculated above. , , , Based on the geometric relationship of the three-grayscale transition model, sub-pixel level edge parameters are obtained. , , and The specific formula is as follows:
[0119] ,
[0120] ,
[0121] ,
[0122] ,
[0123] .
[0124] in, This represents the step grayscale transition between the background and the target in the first stage. This represents the step grayscale transition between the background and the target in the second stage. , These represent the distances from the center to the left and right boundaries of the transition zone, respectively; d is the distance from the origin to the edge line; and a represents the distance to each pixel in the template (i.e., the edge parameter). (distance difference), in this embodiment a 7*7 template is used, therefore a = 2 / 7.
[0125] It should be noted that the conventional algorithm utilizes three integral kernel functions. , , The edge parameters required for edge detection are derived (the conventional algorithm uses a step model, which includes four edge parameters: background gray value, step height, vertical distance from the center of the disk to the edge, and the angle between the vertical line and the x-axis). Used to describe the overall grayscale level within a local window in order to calculate edge contrast; Used to calculate horizontal and vertical offsets; Used with Combining the edge angle calculation, four parameters can be calculated using the three integration kernel functions mentioned above. However, relying solely on these three integration kernel functions is insufficient for precise localization and lacks overall robustness. Furthermore, due to... Integral kernel functions can improve the ability to model blurred edges: the three-kernel model (i.e., the step model) assumes that the edge is an ideal step (a sudden change in gray level), but the actual edge is often sloping (such as optical defocus). By introducing third-order derivative information, the gray-scale gradation process can be described more accurately, and the positioning error of the slope edge can be greatly reduced. It can suppress false edges: By combining the Otsu algorithm with an adaptive threshold, it can distinguish between real edges and false edges caused by noise. (The noise response is weaker than that of lower-order moments). Therefore, this invention adds a... The integral kernel function describes the non-uniform distribution of gradients, such as the gray-level gradation characteristics of blurred edge regions, corresponding to "coma" in optical aberrations, and characterizing asymmetric higher-order distortions. While adding more integral kernel functions can indeed further improve the algorithm's detection accuracy, the improvement is small and significantly increases computational complexity. Therefore, this invention adds only one integral kernel function, which not only improves the algorithm's accuracy and robustness but also avoids excessively increasing computational complexity.
[0126] It should also be noted that when using Zernike orthogonal moments for sub-pixel edge detection with different neighborhood sizes (commonly 5*5, 7*7, and 9*9), the choice of neighborhood size directly affects edge accuracy, noise resistance, computational efficiency, and edge continuity. Larger neighborhood sizes result in stronger information capture, better Gaussian noise suppression, higher tolerance for edge blurring, and easier maintenance of edge continuity, but also higher computational complexity. Verification shows that the detection accuracy for a 5*5 neighborhood is around 0.35 pixels, for a 7*7 neighborhood around 0.12 pixels, and for a 9*9 neighborhood around 0.08 pixels. Clearly, the detection accuracy of a 5*5 neighborhood is insufficient, but the detection time (per single image) for a 9*9 neighborhood is three times that of a 7*7 neighborhood. To ensure the algorithm's accuracy, robustness, and real-time performance, this invention uses a 7*7 neighborhood size, which guarantees accuracy within 0.15 pixels and ensures real-time detection.
[0127] Step S53: Calculate the sub-pixel level coordinates of all edge points based on the edge parameters.
[0128] In step S53, all the required parameters (rotation angles) are calculated through steps S51 and S52. And edge parameter d), import the edge point coordinate correction formula, which further corrects the pixel-level coordinates of the edge points obtained in step S4 to obtain the sub-pixel-level coordinates of the edge points. The edge point coordinate correction formula is as follows:
[0129] = ,
[0130] in, These are pixel-level coordinates (i.e., the pixel-level coordinates of the edge points obtained in step S4). These are the corrected subpixel coordinates. N is the template size; this example uses a 7x7 template. d is the distance from the origin to the edge line. Rotation angle.
[0131] Step S6: Connect all sub-pixel edge points and output the crack detection result image.
[0132] In step S6, based on the coordinates of the sub-pixel edge points obtained in step S5, all sub-pixel edge points are connected, and the crack detection result image is then output (see appendix). Figure 8 ).
[0133] In some feasible embodiments, after connecting all edge points and outputting the crack detection result image, the detection method further includes step S7:
[0134] Step S71: Perform morphological operations on the crack detection result image to extract the cracks (see Appendix). Figure 9 ).
[0135] Step S72: Obtain crack-related parameters. Crack-related parameters include, but are not limited to, the total pixel length of the crack, the maximum width in pixels, and the average width. The specific steps are as follows:
[0136] Step S721: Extract the crack skeleton line based on the coordinates of the sub-pixel edge points, and calculate the total pixel length of the crack using a piecewise summation method.
[0137] In step S721, as shown in the appendix Figure 10 As shown, due to the complex and irregular shape of the crack, the number of pixels in the extracted skeleton lines is not the total pixel length of the crack. Therefore, a piecewise summation method is used to calculate the total pixel length of the crack: assuming the coordinates of two adjacent pixels on the crack skeleton line are ( , )and( , If ), then the pixel distance ∆L between the two points is:
[0138] ∆L= ,
[0139] Repeat this step to obtain the total pixel length of the crack. .
[0140] Step S722: Traverse the crack skeleton line to obtain the maximum width pixel value of the crack. Specifically, select a point on the crack skeleton line as the center and start drawing a circle until the circle is tangent to the crack edge line. Connect the point and the tangent point and extend them to intersect at another edge. Calculate the length of the two edge points as the width at that point. Traverse the skeleton line to obtain the maximum width pixel value of the crack.
[0141] Step S723: Calculate the average width of the crack based on the total pixel area and total pixel length of the crack. The calculation formula is as follows:
[0142] =A / ,
[0143] in, Let A be the average width of the crack, and A be the total pixel area of the crack. This represents the total pixel length of the crack.
[0144] Step S73: Calculate the calibration coefficients and use the calibration coefficients to calibrate the crack-related parameters.
[0145] Understandably, since the crack-related parameters calculated from the image are in pixels, not centimeters or millimeters in the usual sense, the result needs to be multiplied by a calibration coefficient to obtain the final result. The conventional approach is to set markers at known distances on both sides of the crack to calculate the calibration coefficient, but this requires reconfiguration for each inspection, making the operation cumbersome and inconvenient.
[0146] In this embodiment, a special lens hood, namely a special lens cover (see attached image), is installed in front of the camera lens. Figure 11 When the straight-line distance between the lens and the crack area being measured is fixed, and the focal length and pixel size of the camera lens are known, the calibration coefficient can be calculated using the straight-line calibration method, as shown in the following formula:
[0147] ,
[0148] In the formula: is the calibration factor (mm / pixel); L is the distance from the camera optical center to the measurement point (m); f is the lens focal length (mm). The pixel size is (μm / pixel). This method avoids the need for multiple calibration setups, allowing for rapid and continuous image capture of cracks, simplifying the detection process and accelerating its speed. Understandably, in some feasible embodiments, other calibration methods can be used to calibrate crack-related parameters; this is not limited here.
[0149] Based on the same technical concept as the foregoing embodiments, the present invention also provides a crack sub-pixel precision edge detection system based on an improved Canny operator, comprising: an image acquisition module for acquiring crack images corresponding to cracks on the surface of a structure; a preprocessing module for preprocessing the crack images; a gradient calculation module for calculating the gradient magnitude and gradient direction of the preprocessed crack images using an improved Sobel operator to obtain a gradient image containing the gradient magnitude and gradient direction; a coarse pixel-level edge detection module for performing non-maximum suppression on the gradient image and adaptively obtaining an optimal threshold using an improved maximum inter-class variance method to determine crack edges based on the optimal threshold, thereby obtaining a coarse edge pixel-level image; a sub-pixel-level edge detection module for processing edge information in the coarse edge pixel-level image using Zernike orthogonal moments to obtain sub-pixel-level coordinates of edge points; and a detection result output module for connecting all edge points and outputting a crack detection result image.
[0150] In summary, this invention discloses a fast crack edge detection method with sub-pixel accuracy based on an improved Canny operator and without the need for calibration. The method includes acquiring images of cracks in a structure and performing image preprocessing: effectively removing noise from the crack images using a weighted guided filter to reduce noise interference with edge detection results while preserving edge details, effectively solving the problems of blurred edges and halo artifacts; addressing the issue of poor edge preservation and edge continuity in traditional Sobel operators; achieving optimal adaptive threshold acquisition through the maximum inter-class variance method, avoiding the need for manual threshold setting in traditional Canny operators, which affects the results; achieving sub-pixel accuracy by utilizing the Zernike orthogonal moments of a 7*7 template, solving the problem of insufficient crack detection accuracy; and implementing a markerless fast calibration method using a specially designed camera cover to accelerate detection speed. This provides new ideas for subsequent research and engineering applications of crack image edge detection in structures.
[0151] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the technical solutions of the embodiments of the present invention.
Claims
1. A crack sub-pixel precision edge detection method based on an improved Canny operator, characterized in that, include: Obtain crack images corresponding to cracks on the surface of the structure; The crack image is preprocessed; The preprocessed crack image is subjected to gradient calculation using the improved Sobel operator to obtain a gradient image containing gradient magnitude and gradient direction; Non-maximum suppression is applied to the gradient image, and an improved maximum inter-class variance method is used to adaptively obtain the optimal threshold. The crack edge is then determined based on the optimal threshold, thereby obtaining a coarse edge pixel-level image. The edge information in the coarse-edge pixel-level image is processed using Zernike orthogonal moments to obtain the sub-pixel-level coordinates of the edge points; Connect all edge points and output the crack detection result image.
2. The crack sub-pixel precision edge detection method based on the improved Canny operator as described in claim 1, characterized in that, Preprocessing the crack image includes: Image grayscale conversion is performed using a weighted average method; Weighted guided filtering is used for edge-preserving smoothing and noise reduction.
3. The crack sub-pixel precision edge detection method based on the improved Canny operator as described in claim 1, characterized in that, The preprocessed crack image is subjected to gradient calculation using the improved Sobel operator to obtain a gradient image containing gradient magnitude and gradient direction, including: The preprocessed crack image is traversed by a matrix template in four directions to obtain the gradient magnitude in four directions. The final gradient magnitude and gradient direction are calculated using the gradient magnitudes in the four directions, thereby obtaining a gradient image containing the gradient magnitude and gradient direction.
4. The crack sub-pixel precision edge detection method based on the improved Canny operator as described in claim 1, characterized in that, Non-maximum suppression of the gradient image includes: Compare the gradient magnitude of each pixel in the gradient image with the gradient magnitude of two adjacent pixels along the gradient direction of the pixel. If the gradient magnitude of the current pixel is greater than the gradient magnitudes of two adjacent pixels in the same gradient direction, the current pixel is considered an edge point and its pixel value is retained; otherwise, the current pixel is suppressed.
5. The crack sub-pixel precision edge detection method based on the improved Canny operator as described in claim 1, characterized in that, An improved maximum inter-class variance algorithm is used to adaptively determine an optimal threshold, and the crack edge is judged based on the optimal threshold to obtain a coarse edge pixel-level image, including: The gradient image is divided into foreground and background based on the grayscale value and threshold of each pixel; Calculate the inter-class variance between the foreground and background for different thresholds; The threshold corresponding to the maximum inter-class variance is determined as the optimal threshold, and the high threshold and low threshold are determined based on the optimal threshold; Pixels with grayscale values greater than a high threshold are identified as strong edge points and retained. Pixels with gray values less than a low threshold are identified as non-edge points and discarded. Pixels with grayscale values between the high and low thresholds are identified as weak edge points; if a strong edge point exists within an 8-neighborhood of a weak edge point, the pixel is retained; if no strong edge point exists within an 8-neighborhood of a weak edge point, the pixel is discarded, thereby obtaining the pixel-level coordinates of all edge points. Edges are detected and connected by connected component analysis, thereby obtaining pixel-level images with coarse edges.
6. The crack sub-pixel precision edge detection method based on the improved Canny operator as described in claim 1, characterized in that, The edge information in the coarse-edge pixel-level image is processed using Zernike orthogonal moments to obtain the sub-pixel-level coordinates of the edge points, including: Four integral kernel functions for obtaining the coarse-edge pixel-level image are obtained based on Zernike orthogonal moments; Based on the geometric relationship between the four integral kernel functions and the three-grayscale transition model, the edge parameters are obtained; The sub-pixel coordinates of all edge points are calculated based on the edge parameters.
7. The crack sub-pixel precision edge detection method based on the improved Canny operator as described in claim 6, characterized in that, Based on the geometric relationship between the four integral kernel functions and the three-grayscale transition model, the edge parameters are obtained, and the corresponding formulas are as follows: , , , , , in, , , , Both are integral kernel functions; , , and All are edge parameters. This represents the step grayscale transition between the background and the target in the first stage. This represents the step grayscale transition between the background and the target in the second stage. , These are the distances between the center and the left and right boundaries of the transition area, respectively; d is the distance from the origin to the edge line; and a represents the distance of each pixel in the template.
8. The crack sub-pixel precision edge detection method based on the improved Canny operator as described in claim 7, characterized in that, The sub-pixel level coordinates of all edge points are calculated based on the edge parameters, and the corresponding edge point coordinate correction formula is as follows: = , in, The pixel-level coordinates of the edge points The coordinates of the corrected edge points are subpixel level, where N is the template size. Rotation angle.
9. The crack sub-pixel precision edge detection method based on the improved Canny operator as described in claim 1, characterized in that, After connecting all edge points and outputting the crack detection result image, the detection method further includes: Morphological operations are performed on the crack detection result image to extract the crack; Obtain crack-related parameters; the crack-related parameters include the total pixel length of the crack, the maximum width pixel value, and the average width; Calculate the calibration coefficients and use them to calibrate crack-related parameters.
10. A crack sub-pixel precision edge detection system based on an improved Canny operator, characterized in that, include: The image acquisition module is used to acquire crack images corresponding to cracks on the surface of the structure. A preprocessing module is used to preprocess the crack image; The gradient calculation module is used to calculate the gradient magnitude and gradient direction of the preprocessed crack image using the improved Sobel operator, so as to obtain a gradient image containing the gradient magnitude and gradient direction. A coarse pixel-level edge detection module is used to perform non-maximum suppression on the gradient image and adaptively obtain the optimal threshold using an improved maximum inter-class variance method, so as to determine the crack edge based on the optimal threshold and thus obtain a coarse edge pixel-level image. The subpixel-level edge detection module is used to process the edge information in the coarse-edge pixel-level image using Zernike orthogonal moments to obtain the subpixel-level coordinates of the edge points; The detection result output module is used to connect all edge points and output the crack detection result image.
Citation Information
Patent Citations
Improved image edge detection method
CN108470343A
Self-adaptive canny method for crack detection
CN116485719A
Vision-based workpiece edge detection algorithm
CN117788499A
Coal mine ventilation well wall crack extraction method based on image processing
CN119168979A
Cited By
Cable insulation thickness detection method and system based on sub-pixel edge enhancement
CN122199529A
