Edge detection method and device based on gradient weighted fusion and adaptive threshold
By using gradient-weighted fusion and adaptive thresholding for edge detection, the problems of inaccurate gradient information and lack of adaptive thresholding in traditional edge detection are solved, achieving edge detection results with higher accuracy and completeness.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-10
- Publication Date
- 2026-03-17
AI Technical Summary
Traditional edge detection methods suffer from inaccurate gradient information extraction, lack of adaptive threshold selection, and broken edge results.
An edge detection method based on gradient weighted fusion and adaptive threshold is adopted. Gradient magnitude map and direction map are extracted by adaptive morphological operator and traditional difference operator. A weighted fusion function is constructed, and the threshold is adaptively determined by combining the principle of maximizing information entropy. The edge map is optimized by using dynamic structuring element.
It improves the accuracy, completeness, and purity of edge detection, reduces missed edge detections and false positives, and enhances noise resistance and the quality of gradient information.
Smart Images

Figure CN121685579A_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the fields of computer vision and digital image processing technology, and in particular to an edge detection method and apparatus based on gradient weighted fusion and adaptive threshold. Background Technology
[0002] Edge detection is a core technology in image processing and computer vision, widely used in medical image analysis (such as CT vessel segmentation), autonomous driving (lane detection), and industrial defect detection (such as surface crack recognition). The traditional Canny algorithm is widely adopted due to its high accuracy and low computational complexity. However, traditional Canny algorithms and conventional edge detection schemes have several limitations: Firstly, traditional differential operators (such as Sobel and Prewitt operators) are sensitive to image noise, while the structural elements of traditional morphological gradient operators are mostly fixed in shape, failing to adapt to the edge directions of different regions of the image, easily leading to inaccurate gradient information extraction. A single operator cannot simultaneously ensure both accuracy and noise resistance in edge detection. Secondly, the high and low thresholds of traditional Canny algorithms are mostly set manually based on experience or selected according to fixed statistical rules, failing to adaptively adjust according to the gradient distribution characteristics of the image, easily resulting in missed or false edge detections. Furthermore, its non-maximum suppression relies solely on a single gradient direction, and subsequent edge optimization often uses morphological operations with fixed structural elements, making it difficult to effectively complete broken edges and remove redundant isolated pixels in the initial edge map, ultimately affecting the integrity and purity of edge detection. Summary of the Invention
[0003] This disclosure provides an edge detection method and apparatus based on gradient weighted fusion and adaptive threshold, which solves the technical problems of imprecise gradient information extraction, lack of adaptive threshold selection, and broken edge results in traditional edge detection methods.
[0004] According to a first aspect of this disclosure, an edge detection method based on gradient-weighted fusion and adaptive thresholding is provided. The method includes: The input image is preprocessed to obtain a preprocessed image; The preprocessed image is processed based on an adaptive morphological operator to extract the first gradient magnitude map and the first gradient direction map; The preprocessed image is processed based on the traditional difference operator to extract the second gradient magnitude map and the second gradient direction map; Based on the consistency of the orientation at each pixel point of the first gradient direction map and the second gradient direction map, a weighted fusion function is constructed, and the first gradient magnitude map and the second gradient magnitude map are fused using the weighted fusion function to obtain a fused gradient magnitude map; Statistical analysis is performed on the fused gradient magnitude map, and high and low thresholds are adaptively determined based on the principle of maximizing information entropy. Based on the fused gradient magnitude map, the second gradient direction map, and the high and low thresholds, an improved Canny edge detection process is executed to obtain an initial edge map; The initial edge map is optimized based on dynamic structural elements, and the optimized edge detection results are output.
[0005] In addition to the aspects described above and any possible implementations, a further implementation is provided in which the input image is a single-frame static image or an image frame in a video stream; when the input image is an image frame in a video stream, the edge detection method is executed independently for each frame.
[0006] In addition to the aspects and any possible implementations described above, a further implementation is provided in which the processing of the preprocessed image based on the adaptive morphological operator includes: Based on the local grayscale change characteristics of the preprocessed image, structural elements that match the local edge direction are adaptively selected from a predefined set of structural elements. Morphological gradient operations are performed using the selected structuring elements to calculate the first gradient magnitude map and the first gradient direction map.
[0007] As described above, and in accordance with any possible implementation, a further implementation is provided, wherein the weighted fusion function is defined as: in, In pixel coordinates The magnitude of the fusion gradient at the location; This is the magnitude of the first gradient; This is the second gradient magnitude; These are weighting coefficients, whose values are determined by the intersection of the first gradient direction and the second gradient direction. The absolute value of the cosine of the angle at a point determines that the higher the consistency of the directions, the better. The larger the value, the better.
[0008] In addition to the aspects described above and any possible implementations, a further implementation is provided in which the weighting coefficients are calculated as follows: in, The first gradient direction; The second gradient direction is denoted by k; k is a constant greater than zero, used to adjust the sensitivity of the weights to the difference in direction.
[0009] In addition to the aspects and any possible implementations described above, a further implementation is provided in which the adaptive determination of the high and low thresholds for edge detection based on the principle of maximizing information entropy includes: Calculate the global mean and standard deviation of the fused gradient magnitude map; Based on the histogram of the fused gradient magnitude map, an initial global threshold is calculated by maximizing the inter-class information entropy. Based on the initial global threshold, the mean, and the standard deviation, the high threshold and the low threshold are calculated through a predefined functional relationship.
[0010] In addition to the aspects described above and any possible implementations, a further implementation is provided, wherein the predefined functional relationship is represented as: in, High threshold; Low threshold; α is the initial global threshold; μ is the mean; σ is the standard deviation; α, β, γ, and δ are coefficients preset based on image characteristics or experience, and α+β=1, 0<δ<1.
[0011] In addition to the aspects and any possible implementations described above, an implementation is further provided in which the execution of the improved Canny edge detection process includes: Guided by the second gradient direction pattern, non-maximum suppression is performed on the fused gradient magnitude pattern; The high and low thresholds are used to perform double threshold hysteresis processing on the suppressed gradient magnitude map to distinguish strong edge pixels from weak edge pixels. The portion of the weak edge pixels that is connected to the strong edge pixels within a preset connected region is retained as a valid edge, and an initial edge map is generated.
[0012] In addition to the aspects and any possible implementations described above, a further implementation is provided in which the optimization processing of the initial edge graph based on dynamic structural elements includes: Calculate the edge pixel density within a local region of the initial edge map; The size of the circular structuring element used for morphological operations is adaptively determined based on the edge pixel density. The initial edge map is morphologically dilated using a structuring element whose size is determined by the aforementioned dimensions. The dilated edge map is then refined, and isolated redundant edge pixels are removed to obtain the final edge detection result.
[0013] According to a second aspect of this disclosure, an edge detection apparatus based on gradient-weighted fusion and adaptive thresholding is provided. The apparatus includes: The preprocessing module is used to preprocess the input image to obtain a preprocessed image; The first gradient extraction module is used to process the preprocessed image based on an adaptive morphological operator to extract the first gradient magnitude map and the first gradient direction map. The second gradient extraction module is used to process the preprocessed image based on the traditional difference operator to extract the second gradient magnitude map and the second gradient direction map. The gradient fusion module is used to construct a weighted fusion function based on the consistency of the orientation at each pixel point of the first gradient direction map and the second gradient direction map, and to use the weighted fusion function to fuse the first gradient magnitude map and the second gradient magnitude map to obtain a fused gradient magnitude map. An adaptive threshold calculation module is used to perform statistical analysis on the fused gradient magnitude map and adaptively determine the high and low thresholds based on the principle of maximizing information entropy. The edge detection module is used to perform an improved Canny edge detection process based on the fused gradient magnitude map, the second gradient direction map, and the high threshold and low threshold to obtain an initial edge map; The edge optimization module is used to optimize the initial edge map based on dynamic structural elements and output the optimized edge detection results.
[0014] According to a third aspect of this disclosure, an electronic device is provided. The electronic device includes a memory and a processor, wherein the memory stores a computer program, and the processor executes the program to implement the method described above.
[0015] According to a fourth aspect of this disclosure, a computer-readable storage medium is provided having a computer program stored thereon that, when executed by a processor, implements the methods according to the first and / or second aspects of this disclosure.
[0016] In this disclosure, firstly, preprocessing the input image lays a solid foundation for subsequent gradient extraction, reducing interference from irrelevant noise. Secondly, both adaptive morphological operators and traditional difference operators are used simultaneously to extract two sets of gradient magnitude maps and direction maps, leveraging the advantage of adaptive morphological operators in adapting to local edge directions while retaining the gradient extraction efficiency of traditional difference operators, thus achieving multi-dimensional acquisition of gradient information. Thirdly, a weighted fusion function is constructed based on the consistency of the two sets of gradient directions, allowing regions with high directional consistency to highlight the advantages of the corresponding gradient operators, while regions with large directional differences can achieve complementary gradient information. The fused gradient magnitude map possesses both noise resistance and accuracy, effectively improving the quality of gradient information. Finally, based on the principle of maximizing information entropy, high and low thresholds are adaptively determined, overcoming the limitations of manually set thresholds. Overcoming the limitations of the standard threshold, this algorithm dynamically adjusts the threshold based on the statistical characteristics of the fused gradient magnitude map, making the double-threshold lag processing more closely match the actual gradient distribution of the image, reducing missed detections of strong edges and false positives of weak edges. Furthermore, the improved Canny process is executed guided by the second gradient direction, ensuring the directional accuracy of non-maximum suppression. At the same time, effective weak edges are retained through connected component judgment, effectively compensating for the edge breakage problem of the traditional Canny algorithm. Finally, the initial edge map is optimized using dynamic structuring elements, which can adaptively adjust the size of the structuring elements for morphological operations according to the local edge pixel density. This not only expands and completes broken edges but also removes redundant isolated pixels through thinning and culling operations. The final edge detection result has completeness, accuracy, and purity, thus improving the overall performance of image edge detection.
[0017] It should be understood that the description in the Summary of the Invention is not intended to limit the key or essential features of the embodiments of this disclosure, nor is it intended to restrict the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description
[0018] The above and other features, advantages, and aspects of the embodiments of this disclosure will become more apparent from the accompanying drawings and the following detailed description. The drawings are provided for a better understanding of the invention and are not intended to limit the scope of this disclosure. In the drawings, the same or similar reference numerals denote the same or similar elements, wherein: Figure 1 A flowchart of an edge detection method based on gradient weighted fusion and adaptive thresholding provided by an embodiment of this disclosure is shown; Figure 2 A structural diagram of an edge detection device based on gradient weighted fusion and adaptive threshold provided in an embodiment of this disclosure is shown. Figure 3 A structural diagram of an exemplary electronic device capable of implementing embodiments of the present disclosure is shown. Detailed Implementation
[0019] To make the objectives, technical solutions, and advantages of the embodiments of this disclosure clearer, the technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this disclosure, and not all embodiments. Based on the embodiments of this disclosure, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this disclosure.
[0020] Furthermore, the term "and / or" in this article is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone. Additionally, the character " / " in this article generally indicates that the preceding and following related objects have an "or" relationship.
[0021] In this disclosure, firstly, preprocessing the input image lays a solid foundation for subsequent gradient extraction, reducing interference from irrelevant noise. Secondly, both adaptive morphological operators and traditional difference operators are used simultaneously to extract two sets of gradient magnitude maps and direction maps, leveraging the advantage of adaptive morphological operators in adapting to local edge directions while retaining the gradient extraction efficiency of traditional difference operators, thus achieving multi-dimensional acquisition of gradient information. Thirdly, a weighted fusion function is constructed based on the consistency of the two sets of gradient directions, allowing regions with high directional consistency to highlight the advantages of the corresponding gradient operators, while regions with large directional differences can achieve complementary gradient information. The fused gradient magnitude map possesses both noise resistance and accuracy, effectively improving the quality of gradient information. Finally, based on the principle of maximizing information entropy, high and low thresholds are adaptively determined, overcoming the limitations of manually set thresholds. Overcoming the limitations of the standard threshold, this algorithm dynamically adjusts the threshold based on the statistical characteristics of the fused gradient magnitude map, making the double-threshold lag processing more closely match the actual gradient distribution of the image, reducing missed detections of strong edges and false positives of weak edges. Furthermore, the improved Canny process is executed guided by the second gradient direction, ensuring the directional accuracy of non-maximum suppression. At the same time, effective weak edges are retained through connected component judgment, effectively compensating for the edge breakage problem of the traditional Canny algorithm. Finally, the initial edge map is optimized using dynamic structuring elements, which can adaptively adjust the size of the structuring elements for morphological operations according to the local edge pixel density. This not only expands and completes broken edges but also removes redundant isolated pixels through thinning and culling operations. The final edge detection result has completeness, accuracy, and purity, thus improving the overall performance of image edge detection.
[0022] Figure 1 A flowchart of an edge detection method based on gradient-weighted fusion and adaptive thresholding provided by an embodiment of this disclosure is shown, as follows: Figure 1As shown, the edge detection method 100 based on gradient weighted fusion and adaptive threshold may include the following steps: S110, preprocess the input image to obtain a preprocessed image.
[0023] In some embodiments, the input image is a single-frame static image or an image frame in a video stream; when the input image is an image frame in a video stream, the edge detection method is performed independently for each frame.
[0024] Specifically, the input image can adopt common formats such as RGB and grayscale. It supports both single-frame static images (such as BMP, JPG, and PNG static images) and continuous image frames in video streams (such as real-time video frames captured by cameras and frame data after parsing video files). When the input is a video stream, in order to ensure the independence and timeliness of the edge detection results of each frame, the entire edge detection process is executed independently for each frame. The preprocessing stage also follows the principle of frame-level independent processing to avoid data interference between frames.
[0025] Specifically, to address issues such as noise interference, uneven grayscale distribution, and illumination changes that may exist in the input image and affect the accuracy of subsequent gradient extraction, the preprocessing process first performs adaptation processing according to the input image format: if the input is an RGB color image, it is first converted into a single-channel grayscale image using a weighted grayscale formula, preserving the core brightness information of the image while simplifying the computational complexity; if the input is already a grayscale image, it directly proceeds to the subsequent denoising stage.
[0026] To suppress noise (such as Gaussian noise and salt-and-pepper noise) while preserving edge details to the greatest extent possible (avoiding edge blurring caused by traditional filtering), an adaptive bilateral filtering algorithm is used for noise reduction. This algorithm dynamically adjusts the standard deviation of the spatial domain and the standard deviation of the grayscale value domain to enhance noise suppression in flat areas of the image and reduce the filtering intensity in edge areas to ensure that the edge structure is not destroyed. To address issues such as low local grayscale contrast and uneven illumination in some images, a contrast-limited adaptive histogram equalization (CLAHE) process is further introduced. This process divides the image into local blocks of a preset size (the block size can be adaptively adjusted according to the image resolution; smaller blocks can be used for static images to preserve details, while the block size can be appropriately increased for video frames to improve processing speed). The histogram of each local block is equalized, and a contrast limit threshold is set to avoid noise amplification caused by excessive enhancement, resulting in a more uniform grayscale distribution in the image and improving the ability of subsequent gradient operators to capture weak edges.
[0027] Specifically, the parameters of the entire preprocessing process (such as the standard deviation range of bilateral filtering, the block size of CLAHE, and the contrast threshold) can be dynamically adapted according to the type of input image: static images can use more refined parameter settings to pursue processing accuracy, while video stream image frames optimize the parameter calculation logic while ensuring processing effect, balancing detection accuracy and real-time performance, and finally outputting a preprocessed image with sufficient noise suppression, balanced grayscale distribution, and complete edge detail preservation, providing a high-quality input foundation for subsequent gradient extraction by adaptive morphological operators and traditional difference operators.
[0028] S120, the preprocessed image is processed based on an adaptive morphological operator to extract the first gradient magnitude map and the first gradient direction map.
[0029] In some embodiments, processing the preprocessed image based on an adaptive morphological operator includes: Based on the local grayscale change characteristics of the preprocessed image, structural elements that match the local edge direction are adaptively selected from a predefined set of structural elements. Morphological gradient operations are performed using the selected structuring elements to calculate the first gradient magnitude map and the first gradient direction map.
[0030] Specifically, to fully capture edge details of different directions and scales in the image, while avoiding the limitations of edge extraction caused by fixed structuring elements in traditional morphological operators, a predefined set of structuring elements with multiple directions, sizes, and types is first constructed. The directions cover the full range of angles such as 0°, 45°, 90°, 135°, and 180°, the sizes include odd-numbered size matrices such as 3×3, 5×5, and 7×7, and the types cover centrally symmetric structuring elements such as rectangles, rhombuses, and crosses. Structuring elements with different directions are used to adapt to edges with different directions such as horizontal, vertical, and diagonal. The multi-size design adapts to different scale features such as thin edges and wide edges, and the central symmetry ensures the symmetry and accuracy of gradient calculation.
[0031] An adaptive sliding window mechanism is used to analyze the local gray-level change characteristics of the preprocessed image. The size of the sliding window is dynamically adjusted according to the image resolution. For each pixel's local window, the gray-level variance, local gradient intensity, and gray-level change trend vector within the window are calculated. By statistically summing the absolute values of the gray-level differences in the four directions (horizontal, vertical, 45°, and 135°) within the window, the dominant edge direction of the local region is determined (e.g., if the sum of the differences in the horizontal direction is the largest, it is determined that the vertical edge is dominant). The gray-level variance is combined to determine the richness of detail (the larger the variance, the richer the detail; the smaller the variance, the flatter the region).
[0032] Specifically, based on the aforementioned local characteristics, the optimal structural element is adaptively selected from the predefined set: structural elements with matching directions are selected for regions with clear dominant edge directions; small-sized structural elements are prioritized for regions with rich details to accurately capture fine edges; and slightly larger-sized structural elements are selected for regions with wider edges and gentler grayscale changes to ensure gradient integrity. After selecting the structuring element, basic morphological gradient operations are performed. Specifically, the preprocessed image is subjected to dilation (preserving the maximum grayscale value within the window to expand the edges) and erosion (preserving the minimum grayscale value within the window to shrink the edges) using the structuring element. The grayscale values of corresponding pixels in the dilated and eroded images are subtracted to obtain the morphological gradient magnitude of each pixel. The gradient magnitudes of all pixels are then integrated into a first gradient magnitude map. Simultaneously, based on the inherent relationship between the structuring element direction and the gradient direction (the gradient direction is perpendicular to the edge direction, and the structuring element direction is consistent with the edge direction, therefore the gradient direction is the direction after rotating the structuring element direction by 90°), and combined with the specific trend of grayscale changes within the local window (such as the positional deviation of extreme pixels in the dilation and erosion operations), the gradient direction of each pixel is accurately calculated and uniformly quantized into angle values from 0° to 180°. The gradient directions of all pixels are then integrated to form a first gradient direction map. The final output is a first gradient magnitude map and a first gradient direction map that accurately reflect the edge scale and direction characteristics of the image, providing high-quality morphological gradient information for subsequent dual-gradient fusion.
[0033] S130, the preprocessed image is processed based on the traditional difference operator to extract the second gradient magnitude map and the second gradient direction map.
[0034] Specifically, to fully leverage the fast response advantage of traditional differential operators to step edges and complement the morphological gradient in S120, this step selects the classic Sobel operator as the core traditional differential operator, and uses a 3×3 standard convolution kernel to construct detection templates in the horizontal and vertical directions. The horizontal convolution kernel is used to capture the gradient information of vertical edges, and the vertical convolution kernel is used to capture the gradient information of horizontal edges. For high-resolution images or static images with rich edge details, the kernel can be adaptively expanded to 5×5 to improve the completeness of gradient capture, while the video stream image frames maintain a 3×3 kernel size to ensure real-time performance.
[0035] In the processing, the preprocessed single-channel grayscale image is first used as input. A sliding window iterates through each pixel of the image, performing pixel-wise weighted convolution operations with both horizontal and vertical convolution kernels to obtain the horizontal gradient component Gx and the vertical gradient component Gy for each pixel. Edge padding is used in the convolution operation to avoid losing gradient information from pixels at image boundaries, ensuring full coverage of gradient calculation. Subsequently, the second gradient magnitude is calculated based on the gradient components using the Euclidean distance formula. To achieve accurate solutions, the method preserves the quantization differences in gradient magnitudes while avoiding the loss of detail caused by the absolute value summation method. Furthermore, the calculation results are normalized to 0-255 gray levels to eliminate magnitude fluctuations caused by differences in grayscale ranges across different images. For the calculation of the gradient direction, the arctangent function is used. The original angle is solved and then quantized to a value range of 0°-180° (since the edge direction has bidirectional consistency, 180° and 0° are considered to be the same direction). In the quantization process, 8 levels of angle discretization are used (22.5° per level), which simplifies the complexity of subsequent direction consistency calculation and ensures the accuracy of direction positioning. At the same time, for the special case of Gx=0 (vertical edge), the gradient direction is directly determined to be 90° to avoid calculation anomalies.
[0036] Finally, by integrating the gradient magnitude and quantized gradient direction of all pixels, a second gradient magnitude map and a second gradient direction map are generated respectively. This gradient has a significant response to obvious step edges in the image and accurate direction localization. It complements the morphological gradient in S120 (which is good at capturing structural edges and has strong noise resistance), providing a reliable differential gradient data source for subsequent weighted fusion based on direction consistency.
[0037] S140, based on the consistency of the directions at each pixel point of the first gradient direction map and the second gradient direction map, a weighted fusion function is constructed, and the first gradient magnitude map and the second gradient magnitude map are fused using the weighted fusion function to obtain a fused gradient magnitude map.
[0038] In some embodiments, the weighted fusion function is defined as: in, In pixel coordinates The magnitude of the fusion gradient at the location; This is the magnitude of the first gradient; This is the second gradient magnitude; These are weighting coefficients, whose values are determined by the intersection of the first gradient direction and the second gradient direction. The absolute value of the cosine of the angle at a point determines that the higher the consistency of the directions, the better. The larger the value, the better.
[0039] In some embodiments, the weighting coefficient is calculated as follows: in, The first gradient direction; The second gradient direction is denoted by k; k is a constant greater than zero, used to adjust the sensitivity of the weights to the difference in direction.
[0040] Specifically, to ensure the accuracy of the orientation consistency determination and the rationality of the fusion result, the two gradient orientation maps are first preprocessed with angle calibration: since both the first gradient orientation map (morphological gradient) and the second gradient orientation map (differential gradient) have been quantized to the range of 0°-180°, the angle difference between the two gradient directions is calculated for each pixel (x,y). ,like If the angle is greater than 90°, then take the supplementary angle. As the final angle difference (due to the bidirectional equivalence of edge directions, the consistency of the actual direction is determined by the supplementary angle when the included angle exceeds 90°), the angle difference is ensured to always be within the 0°-90° range, providing accurate input for cosine value calculation. Weighting coefficients are then constructed based on the calibrated angle difference. Using formula The calculation is performed, where k is a sensitivity adjustment constant greater than zero. Its value needs to be adaptively set according to the input image type and application scenario: for static images (such as high-precision detection scenarios), k is set to 2-3 to strengthen the influence of directional consistency on the weights, ensuring complete directional consistency. =1, when the directional difference is large =0, to achieve more accurate gradient selection; for video stream image frames (such as real-time monitoring scenarios), k takes the value of 1-2, which reduces computational complexity while ensuring fusion effect, and balances real-time performance and detection accuracy.
[0041] Specifically, to avoid imbalance in the fusion weights due to differences in the original value ranges of the two gradient magnitude maps, the first gradient magnitude map needs to be adjusted before being substituted into the fusion function. With the second gradient magnitude map A unified normalization process is performed, using a linear normalization method to map the grayscale values of both to the 0-255 range, i.e. , ,in , These are the minimum and maximum values of the first gradient magnitude map, respectively. , These are the minimum and maximum values of the second gradient magnitude map, respectively, ensuring that the two are weighted and fused at the same order of magnitude. The fusion function adopts a linear weighting form. The core logic of this function is: when the two gradient directions are highly consistent, the weight coefficients... When the gradient approaches 1, the fusion result mainly relies on the morphological gradient (strong noise resistance and complete capture of structural edges); when the consistency of the two gradient directions is low, the weighting coefficients... Approaching 0, the fusion result mainly relies on the differential gradient (sensitive to step edge response and accurate detail capture); while in regions with moderate directional consistency, the complementary fusion of the two gradient information is achieved through weight allocation, which retains the noise resistance advantage of the morphological gradient while taking into account the detail perception capability of the differential gradient.
[0042] To address the potential extreme value overflow issue during the fusion process, the calculated values are... Grayscale values are clipped to 0 and 255 respectively to ensure the grayscale regularity of the fused gradient magnitude map. The final output is a fused gradient magnitude map that is both noise-resistant and detail-complete, laying a high-quality data foundation for subsequent adaptive threshold selection and edge extraction.
[0043] S150, perform statistical analysis on the fused gradient magnitude map, and adaptively determine the high threshold and low threshold based on the principle of maximizing information entropy.
[0044] In some embodiments, the adaptive determination of the high and low thresholds for edge detection based on the principle of maximizing information entropy includes: Calculate the global mean and standard deviation of the fused gradient magnitude map; Based on the histogram of the fused gradient magnitude map, an initial global threshold is calculated by maximizing the inter-class information entropy. Based on the initial global threshold, the mean, and the standard deviation, the high threshold and the low threshold are calculated through a predefined functional relationship.
[0045] In some embodiments, the predefined functional relationship is represented as: in, High threshold; Low threshold; α is the initial global threshold; μ is the mean; σ is the standard deviation; α, β, γ, and δ are coefficients preset based on image characteristics or experience, and α+β=1, 0<δ<1.
[0046] Specifically, to ensure the accuracy of threshold selection and image adaptability, a refined grayscale histogram is first constructed from the fused gradient magnitude map (grayscale range normalized to 0-255): 256 grayscale levels are divided with a grayscale interval of 1, and the pixel frequency corresponding to each grayscale level is counted. To eliminate local fluctuations in the gradient distribution, a Gaussian smoothing filter is used to preprocess the histogram, resulting in a smoothed gradient grayscale histogram, providing a stable data foundation for subsequent statistical analysis and threshold calculation. Next, global statistical parameters are calculated. By traversing all pixels in the fused gradient magnitude map, the global mean μ and global standard deviation σ are calculated: μ is the arithmetic mean of the gradient magnitudes of all pixels, reflecting the central tendency of the gradient distribution; σ is the square root of the mean of the sum of the squares of the differences between the gradient magnitude and μ, characterizing the dispersion of the gradient distribution. Both together quantify the overall distribution characteristics of the fused gradient, providing a basis for threshold correction.
[0047] Specifically, based on the smoothed gray-level histogram, the initial global threshold T is solved by maximizing the inter-class information entropy. The specific process is as follows: traverse all possible gray-level candidate thresholds t from 0 to 255, divide the image pixels into background (gradient magnitude ≤ t) and foreground (gradient magnitude > t), calculate the proportion of background pixels P0(t) and the proportion of foreground pixels P1(t) = 1 - P0(t), then calculate the gray-level mean μ0(t) and μ1(t) of the two classes respectively, and then use the formula... Calculate the inter-class information entropy (when P0(t)=0 or P1(t)=0, the corresponding term is counted as 0), and select the candidate threshold t that makes H(t) reach its maximum value as the initial global threshold T. This threshold can maximize the information distinction between the background and the foreground and adapt to the complex distribution characteristics of the fused gradient.
[0048] Specifically, to further optimize the adaptability of the threshold to different image scenes, a predefined functional relationship is constructed using the global mean μ and the standard deviation σ to calculate the high threshold. ,Right now The coefficients α, β, and γ are adaptively set according to the image type and scene characteristics: For static images (such as high-precision detection scenarios), α is 0.6-0.8, β is 0.4-0.2 (satisfying α+β=1), and γ is 0.7-1.0, strengthening the dominant role of the initial threshold T, while correcting the discreteness of the gradient distribution through μ+γσ; For video stream image frames (such as real-time monitoring scenarios), α is 0.7-0.9, β is 0.3-0.1, and γ is 0.5-0.8, simplifying the correction logic while ensuring the reliability of the threshold, balancing real-time performance and detection effect; For low-contrast, high-noise images, the value of γ can be appropriately increased to enhance the adjustment effect of the standard deviation on the threshold and avoid the loss of weak edges. Low threshold pass The fixed proportional relationship is determined, that is The value of δ ranges from 0.3 to 0.5, and is dynamically adjusted according to the noise level: a smaller δ is used for images with more noise to reduce noise-induced false edges; a larger δ is used for images with continuous edges and less noise to retain more effective weak edges and ensure... It can both filter out weak edges that are connected to strong edges and suppress isolated noise points.
[0049] The entire threshold determination process requires no manual intervention. By combining statistical analysis with the principle of maximizing information entropy, it achieves adaptive matching of high and low thresholds to the characteristics of the fused gradient magnitude map. This not only ensures the accurate extraction of strong edges but also provides a scientific basis for subsequent double-threshold hysteresis processing, effectively improving the robustness of edge detection.
[0050] S160, based on the fused gradient magnitude map, the second gradient direction map, and the high threshold and low threshold, an improved Canny edge detection process is executed to obtain an initial edge map.
[0051] In some embodiments, the improved Canny edge detection process includes: Guided by the second gradient direction pattern, non-maximum suppression is performed on the fused gradient magnitude pattern; The high and low thresholds are used to perform double threshold hysteresis processing on the suppressed gradient magnitude map to distinguish strong edge pixels from weak edge pixels. The portion of the weak edge pixels that is connected to the strong edge pixels within a preset connected region is retained as a valid edge, and an initial edge map is generated.
[0052] Specifically, guided by the more accurate second gradient direction map, and combined with the noise resistance and detail advantages of the fused gradient magnitude map, refined edge extraction and reliable screening are achieved. First, non-maximum suppression is performed: Considering that the fused gradient magnitude map has been normalized to grayscale and the second gradient direction map has been discretized by 8 levels of angles, the gradient direction of each pixel (x,y) is mapped to the neighborhood direction. The quantized angle is mapped to the four main direction groups (0° / 180°, 45° / 225°, 90° / 270°, 135° / 315°) within a 3×3 sliding window to ensure that the direction guidance matches the pixel distribution within the window. For cases where the gradient direction is not completely aligned with the adjacent pixels within the window, linear interpolation is used to calculate the gradient magnitude interpolation result of two adjacent pixels in the gradient direction to avoid suppression deviation caused by discrete pixels. Then, the fused gradient magnitude of the current pixel is compared with the magnitude of the two adjacent pixels obtained by interpolation. Only the magnitude when the current pixel is a local maximum is retained (the magnitudes of other pixels are set to 0). This method effectively refines the edge width, eliminates redundant gradient responses in non-edge areas, and ensures single-pixel-level refinement of the edges.
[0053] Specifically, after non-maximum suppression is completed, the process proceeds to the double-threshold hysteresis processing stage: a clear pixel classification rule is set, and pixels with a suppressed gradient magnitude greater than the high threshold are classified. Pixels marked as strong edge pixels (grayscale value set to 255) are directly identified as effective edge cores due to their significant gradient response and strong noise resistance; pixels with gradient magnitudes between a low threshold are also considered. With high threshold Pixels between these thresholds are marked as weak edge pixels (grayscale value set to 128). These pixels may be extensions of valid edges or noise-induced pseudo-edges, requiring further screening. Pixels with gradient magnitudes less than a low threshold are also considered weak edge pixels. Pixels that are not grayscale values are directly identified as background pixels (with grayscale values set to 0) and removed to simplify subsequent processing.
[0054] Finally, connectivity analysis is performed to filter effective weak edges: a preset connected component strategy is adopted, adaptively selecting 4-neighbor or 8-neighbor connectivity rules based on the image type (8-neighbor is preferred for static high-precision images to retain more edge branches; 4-neighbor is used for video stream images to improve processing efficiency). By traversing the weak edge region pixel by pixel, it is determined whether each weak edge pixel is directly or indirectly connected to a strong edge pixel within the preset connected component. If a connection exists, the weak edge pixel is determined to be an effective edge extension, and its grayscale value is updated to 255. If the weak edge pixel is isolated (no strong edge pixels within the connected component), it is determined to be a false edge, and its grayscale value is set to 0. Throughout the process, the accuracy of non-maximum suppression is improved by the precise guidance of the second gradient direction map, and the adaptive characteristics of dual thresholds are used to achieve preliminary edge screening. Then, connectivity analysis is used to remove false edges and complete effective edges, ultimately generating an initial edge map with clear edge contours, good continuity, and few false edges, laying the foundation for subsequent dynamic structural element optimization.
[0055] S170, The initial edge map is optimized based on dynamic structural elements, and the optimized edge detection result is output.
[0056] In some embodiments, the optimization process of the initial edge map based on dynamic structuring elements includes: Calculate the edge pixel density within a local region of the initial edge map; The size of the circular structuring element used for morphological operations is adaptively determined based on the edge pixel density. The initial edge map is morphologically dilated using a structuring element whose size is determined by the aforementioned dimensions. The dilated edge map is then refined, and isolated redundant edge pixels are removed to obtain the final edge detection result.
[0057] Specifically, the local edge pixel density is first calculated using an adaptive sliding window mechanism that traverses the initial edge map. The window size is dynamically adjusted based on the image resolution and type: a 5×5 window is used for static high-precision images to accurately capture local edge distribution, while a 3×3 window is used for video stream image frames to balance computational efficiency and detection performance. The window sliding step size is set to 1 to achieve full coverage without omissions. Pixels within each window are statistically analyzed. The edge pixel density ρ(x,y) is defined as the ratio of the number of edge pixels with a grayscale value of 255 within the window to the total number of pixels in the window. To eliminate random fluctuations in edge distribution within local windows, the density results of all windows are smoothed using mean filtering (the filtering window size is consistent with the sliding window), resulting in a smoothed local edge pixel density map, ensuring the stability of density determination.
[0058] Specifically, the size of circular structural elements is adaptively determined based on the density map. Because circular structural elements are isotropic, directional bias can be avoided in morphological operations. The size setting follows the "density adaptation" principle: a preset density threshold range is used. When the local density ρ(x,y) < When selecting larger structural elements, the connection effect at the fracture edges is strengthened; when ≤ρ(x,y)≤ When ρ(x,y) > 1, select medium-sized structural elements to balance the requirements of connection and edge refinement; When selecting structural elements, smaller sizes are chosen to avoid excessive expansion that could lead to edge adhesion or loss of detail. All structural elements are ensured to be centrally symmetrical to guarantee consistency in morphological operations.
[0059] Subsequently, a morphological dilation operation is performed, using adaptively determined dynamic structuring elements to dilate the initial edge map window by window. During the dilation process, only background pixels surrounding the edge pixels are filled, connecting broken weak edge fragments and filling small gaps. Simultaneously, because the size of the structuring element matches the local edge density, excessive expansion of dense edge regions is effectively avoided. After dilation, a thinning operation is needed to restore the single-pixel width of the edges. The Zhang-Suen thinning algorithm is used, which iterates through the image in two rounds: the first round retains pixels that meet the conditions of "non-isolated pixels," "non-boundary endpoints," and "the number of edge pixels in the neighborhood is within a reasonable range," while discarding redundant pixels; the second round applies the same judgment logic to the pixels not processed in the first round, iterating alternately until no pixels can be discarded in the image, ensuring that the thinned edges maintain connectivity and integrity, and that the width is uniformly a single pixel.
[0060] Finally, isolated and redundant edge pixels are removed. The isolation pixel determination rule is set as follows: A 3×3 window is used to traverse the thinned edge image. If an edge pixel has fewer than 1 edge pixels in its 4-neighborhood or fewer than 2 edge pixels in its 8-neighborhood, it is determined to be an isolated and redundant pixel, and its grayscale value is set to 0. Simultaneously, continuous edge segments with a length of less than 3 pixels are removed entirely to further refine the edge detection results. The entire optimization process achieves adaptive morphological operations through dynamic structuring elements. Combined with the thinning algorithm and isolated pixel removal, the final output is an optimized edge detection result with complete edge connectivity, uniform width, and minimal false edges. This preserves the core contour information of the initial edge image while solving common problems such as breaks and redundancy, making it suitable for diverse application scenarios of static images and video streams.
[0061] According to the embodiments of this disclosure, the following technical effects are achieved: (1) It realizes the complementary fusion and precise purification of gradient information, effectively solving the limitations of a single gradient operator. It preserves the integrity of structural edges in the image through adaptive morphological gradient, and enhances the response sensitivity of step edges by using traditional differential gradient. At the same time, based on the weighted fusion mechanism of gradient direction consistency, it realizes the intelligent allocation of different gradient information, so that the fused gradient magnitude map has both noise resistance and detail perception capabilities, laying a high-quality data foundation for subsequent edge extraction. Compared with the single operator detection scheme, the coverage of edge information is significantly improved, and the ability to capture weak edges is greatly enhanced.
[0062] (2) An information entropy-driven adaptive dual threshold selection mechanism was constructed, which broke through the adaptation bottleneck of traditional fixed threshold or manual threshold. The threshold was determined by integrating the global statistical characteristics of the gradient magnitude map and the principle of maximizing inter-class information entropy. The high and low thresholds can be dynamically adjusted according to the image gray distribution and noise level. This not only ensures the accurate identification of strong edges, but also provides a scientific basis for the screening of weak edges. It effectively reduces the problem of edge omission or false edge misdetection caused by threshold mismatch. The adaptability and robustness of the scheme to complex images with low contrast, high noise, and uneven illumination are greatly improved.
[0063] (3) The core steps of the Canny edge detection process were optimized. Non-maximum suppression guided by the second gradient direction map and combined with the linear interpolation compensation strategy were used to achieve high-precision single-pixel thinning of the edge, avoiding edge offset caused by directional dispersion in traditional suppression methods. The combination of double threshold hysteresis processing and connectivity analysis not only preserved the core contour of strong edges, but also accurately screened out effective weak edges connected to strong edges and eliminated isolated pseudo edges. The final generated initial edge map has a clear contour and good continuity. The edge positioning accuracy and purity are significantly better than the traditional Canny algorithm.
[0064] (4) The edge is refined and optimized by relying on dynamic structural elements. By adaptively matching the size of the circular structural elements with the local edge pixel density, the targeted repair and connection of broken edges is achieved, while avoiding excessive expansion and adhesion in dense edge areas. Combined with the Zhang-Suen thinning algorithm and the isolated redundant pixel removal strategy, the edge connectivity is repaired while maintaining the single pixel width of the edge, ensuring that the final edge detection result has both integrity and fineness, effectively solving the problems of edge breakage and redundant pseudo edges in the initial edge map.
[0065] (5) It has good scene compatibility and engineering practicality. This disclosure supports high-precision detection of single-frame static images and is also compatible with real-time processing of video stream image frames. The video frames adopt independent detection logic, which takes into account both detection accuracy and real-time performance. The parameters of each link can be dynamically adapted according to the image type. Fine parameters can be enabled for static images to ensure detection quality, and parameters can be optimized for video stream images to improve processing efficiency. It can meet the edge detection needs of multiple fields such as industrial inspection, machine vision, and video surveillance, and has high engineering implementation value.
[0066] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this disclosure is not limited to the described order of actions, because according to this disclosure, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily essential to this disclosure.
[0067] The above is an introduction to the method embodiments. The following describes the solution described in this disclosure further through device embodiments.
[0068] Figure 2 The diagram illustrates a structural representation of an edge detection device based on gradient-weighted fusion and adaptive thresholding, as provided in an embodiment of this disclosure. Figure 2 As shown, an edge detection device 200 based on gradient weighted fusion and adaptive thresholding may include: Preprocessing module 210 is used to preprocess the input image to obtain a preprocessed image; The first gradient extraction module 220 is used to process the preprocessed image based on an adaptive morphological operator to extract the first gradient magnitude map and the first gradient direction map. The second gradient extraction module 230 is used to process the preprocessed image based on the traditional difference operator to extract the second gradient magnitude map and the second gradient direction map. The gradient fusion module 240 is used to construct a weighted fusion function based on the consistency of the directions at each pixel point of the first gradient direction map and the second gradient direction map, and to use the weighted fusion function to fuse the first gradient magnitude map and the second gradient magnitude map to obtain a fused gradient magnitude map. The adaptive threshold calculation module 250 is used to perform statistical analysis on the fused gradient magnitude map and adaptively determine the high threshold and low threshold based on the principle of maximizing information entropy. The edge detection module 260 is used to perform an improved Canny edge detection process based on the fused gradient magnitude map, the second gradient direction map, and the high threshold and low threshold to obtain an initial edge map; The edge optimization module 270 is used to optimize the initial edge map based on dynamic structural elements and output the optimized edge detection results.
[0069] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the described module can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0070] The acquisition, storage, and application of user personal information involved in the technical solution disclosed herein comply with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0071] According to embodiments of this disclosure, this disclosure also provides an electronic device, a readable storage medium, and a computer program product.
[0072] Figure 3 A schematic block diagram of an electronic device 300 that can be used to implement embodiments of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present disclosure described and / or claimed herein.
[0073] Electronic device 300 includes a computing unit 301, which can perform various appropriate actions and processes according to a computer program stored in ROM 302 or a computer program loaded into RAM 303 from storage unit 308. RAM 303 can also store various programs and data required for the operation of electronic device 300. The computing unit 301, ROM 302, and RAM 303 are interconnected via bus 304. I / O interface 305 is also connected to bus 304.
[0074] Multiple components in electronic device 300 are connected to I / O interface 305, including: input unit 306, such as keyboard, mouse, etc.; output unit 307, such as various types of displays, speakers, etc.; storage unit 308, such as disk, optical disk, etc.; and communication unit 309, such as network card, modem, wireless transceiver, etc. Communication unit 309 allows electronic device 300 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0075] The computing unit 301 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 301 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 301 performs the various methods and processes described above, such as method 100. For example, in some embodiments, method 100 may be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 308. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 300 via ROM 302 and / or communication unit 309. When the computer program is loaded into RAM 303 and executed by the computing unit 301, one or more steps of method 100 described above may be performed. Alternatively, in other embodiments, the computing unit 301 may be configured to perform method 100 by any other suitable means (e.g., by means of firmware).
[0076] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0077] The program code used to implement the methods of this disclosure may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing apparatus, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0078] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0079] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including voice input, speech input, or tactile input).
[0080] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as a data server), or computing systems that include middleware components (e.g., an application server), or computing systems that include frontend components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., a communication network). Examples of communication networks include local area networks (LANs), wide area networks (WANs), and the Internet.
[0081] Computer systems can include clients and servers. Clients and servers are generally located far apart and typically interact via communication networks. Client-server relationships are created by computer programs running on the respective computers and having a client-server relationship with each other. Servers can be cloud servers, servers in distributed systems, or servers incorporating blockchain technology.
[0082] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this disclosure can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this disclosure can be achieved, and this is not limited herein.
[0083] The specific embodiments described above do not constitute a limitation on the scope of protection of this disclosure. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this disclosure should be included within the scope of protection of this disclosure.
Claims
1. A method for edge detection based on gradient-weighted fusion and adaptive thresholding, characterized in that, The method comprises the following steps: preprocessing an input image to obtain a preprocessed image; processing the preprocessed image based on an adaptive morphological operator to extract a first gradient magnitude map and a first gradient direction map; processing the preprocessed image based on a traditional difference operator to extract a second gradient magnitude map and a second gradient direction map; constructing a weighted fusion function based on the consistency of the directions of the pixels in the first gradient direction map and the second gradient direction map, and fusing the first gradient magnitude map and the second gradient magnitude map by using the weighted fusion function to obtain a fused gradient magnitude map; performing statistical analysis on the fused gradient magnitude map, and adaptively determining a high threshold value and a low threshold value based on the principle of maximum information entropy; performing an improved Canny edge detection process based on the fused gradient magnitude map, the second gradient direction map, and the high threshold value and the low threshold value to obtain an initial edge map; optimizing the initial edge map based on a dynamic structure element to output an optimized edge detection result.
2. The method of claim 1, wherein, The input image is a single static image or an image frame in a video stream; when the input image is an image frame in a video stream, the edge detection method is independently performed on each image frame.
3. The method of claim 1, wherein, The processing of the preprocessed image based on the adaptive morphological operator comprises the following steps: adaptively selecting a structure element matching the local edge direction from a pre-defined structure element set according to the local gray level variation characteristics of the preprocessed image; performing morphological gradient operation by using the selected structure element to calculate the first gradient magnitude map and the first gradient direction map.
4. The method of claim 1, wherein, The weighted fusion function is defined as: wherein, is a fusion gradient magnitude at pixel coordinate ; is a first gradient magnitude; is a second gradient magnitude; is a weight coefficient, whose value is determined by the absolute value of the cosine value of the included angle between the first gradient direction and the second gradient direction at point, the higher the direction consistency, the greater the value of .
5. The method of claim 4, wherein, The calculation method of the weight coefficient is: wherein, is a first gradient direction; is a second gradient direction; k is a constant greater than zero, for adjusting the sensitivity of the weight to the difference in directions.
6. The method of claim 1, wherein, The adaptive determination of the high threshold value and the low threshold value based on the principle of maximum information entropy comprises the following steps: calculating the global mean value and the standard deviation of the fused gradient magnitude map; calculating an initial global threshold value by maximizing the inter-class information entropy based on the histogram of the fused gradient magnitude map; calculating the high threshold value and the low threshold value by a pre-defined function relationship based on the initial global threshold value, the mean value, and the standard deviation.
7. The method of claim 6, wherein, The pre-defined function relationship is represented as: wherein, is a high threshold value; is a low threshold value; is an initial global threshold value; μ is a mean value; σ is a standard deviation; α, β, γ, δ are coefficients preset according to image characteristics or experience, and α + β = 1, 0 < δ < 1.
8. The method of claim 1, wherein, The performance of the improved Canny edge detection process comprises the following steps: performing non-maximum suppression on the fused gradient magnitude map guided by the second gradient direction map; performing double-threshold hysteresis processing on the suppressed gradient magnitude map by using the high threshold value and the low threshold value to distinguish strong edge pixels and weak edge pixels; retaining the part of the weak edge pixels connected to the strong edge pixels in a pre-set connected domain as valid edges to generate an initial edge map.
9. The method of claim 1, wherein, The optimization processing of the initial edge map based on the dynamic structure element comprises the following steps: calculating the edge pixel density in a local region of the initial edge map; adaptively determining the size of a circular structure element used for morphological operation according to the edge pixel density; performing morphological dilation operation on the initial edge map by using the structure element with the determined size; performing thinning processing on the dilated edge map, and removing isolated redundant edge pixels to obtain a final edge detection result.
10. An edge detection device based on gradient-weighted fusion and adaptive threshold, characterized by, The method comprises the following steps: A preprocessing module is configured to preprocess an input image to obtain a preprocessed image; A first gradient extraction module is configured to process the preprocessed image based on an adaptive morphological operator to extract a first gradient magnitude map and a first gradient direction map; A second gradient extraction module is configured to process the preprocessed image based on a traditional difference operator to extract a second gradient magnitude map and a second gradient direction map; A gradient fusion module is configured to construct a weighted fusion function based on the consistency of the directions of the pixels in the first gradient direction map and the second gradient direction map, and fuse the first gradient magnitude map and the second gradient magnitude map by using the weighted fusion function to obtain a fused gradient magnitude map; An adaptive threshold calculation module is configured to statistically analyze the fused gradient magnitude map, and adaptively determine a high threshold and a low threshold based on an information entropy maximization principle; An edge detection module is configured to perform an improved Canny edge detection process based on the fused gradient magnitude map, the second gradient direction map, and the high threshold and the low threshold to obtain an initial edge map; An edge optimization module is configured to perform optimization processing on the initial edge map based on a dynamic structure element to output an optimized edge detection result.
Citation Information
Cited By
Machine vision-based beef pie green body defect online detection method
CN121856271A
Industrial robot efficient communication method and system based on edge computing
CN121864918A
Automobile steel wire defect real-time detection system based on edge calculation
CN121904038A