Contour extraction method based on edge detection
By quantifying image complexity and building a contour extraction model based on edge detection, the problem of low contour extraction accuracy in complex image scenarios is solved, and efficient and accurate contour extraction in complex images is achieved.
Patent Information
- Application Number
- CN202510552471.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-29
- Publication Date
- 2025-08-12
AI Technical Summary
The prior art is difficult to accurately extract the object outline in complex image scenarios, especially in the segmentation of internal components of the building. When faced with complex backgrounds, light changes, low contrast and irregular component shapes, the recognition accuracy is low, which can easily lead to false detection and missed detection.
By obtaining the noise level and edge blur metric analysis of the image to be extracted, the image complexity level is calculated, and a contour extraction model based on edge detection is constructed. The feature extraction network, feature fusion module and generation adversarial network are used to generate candidate contours, and the profile is optimized in combination with the diffusion process, and the feature weight is dynamically adjusted to adapt to images of different complexity.
It improves the accuracy and efficiency of the model's contour extraction in complex image scenarios, enhances the learning of multi-scale texture feature of complex images and efficient feature fusion of simple images, and improves the generalization ability and training effect of the model.
Smart Images

Figure CN120471946A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of image processing, and in particular relates to a contour extraction method based on edge detection. Background Art
[0002] Traditional edge detection methods, such as Canny edge detection and Sobel operator, can obtain certain edge information in simple images. However, when segmenting internal components of buildings, they have low recognition accuracy when faced with complex backgrounds, lighting changes, low contrast, and irregular component shapes, which can easily lead to false detections and missed detections.
[0003] With the development of deep learning, some contour extraction methods based on deep learning have emerged, but there are still many shortcomings. Some methods do not fully consider the particularity of edge detection and contour generation in the design of network structure, and have poor adaptability to complex images. In terms of feature processing, there is also a lack of a mechanism to effectively integrate features of different levels and scales, which affects the integrity and robustness of feature expression. In terms of training strategies, there is a lack of optimization for image complexity, which makes it difficult to balance the accuracy and efficiency of contour extraction in different scenarios. Summary of the Invention
[0004] In view of the above-mentioned deficiencies in the prior art, the present invention provides a contour extraction method based on edge detection, which solves the problem that it is difficult to accurately extract the contour of an object in complex image scenes.
[0005] In order to achieve the above-mentioned object of the invention, the technical solution adopted by the present invention is:
[0006] The present invention provides a contour extraction method based on edge detection, comprising the following steps:
[0007] S1, obtaining a number of images to be contour-extracted and the true annotated contours corresponding to each of the images to be contour-extracted;
[0008] S2. performing noise level quantization and edge blur quantization analysis on each image to be contour extracted, and calculating the image complexity level of each image to be contour extracted;
[0009] S3, classifying the complexity levels of the images to be contour extracted according to their image complexity levels, and constructing a complexity classification image dataset;
[0010] S4. Constructing a contour extraction model based on edge detection;
[0011] S5. According to the real annotated contours corresponding to the images to be contour-extracted, a contour extraction model based on edge detection is trained using the complexity classification image dataset to obtain a trained contour extraction model;
[0012] S6. Obtain a new image to be contour extracted and an image complexity level, and input the image to be contour extracted into a trained contour extraction model for contour prediction to obtain a predicted image contour of the image as a contour extraction result.
[0013] The beneficial effects of the present invention are as follows: the present invention provides a contour extraction method based on edge detection, which quantifies the noise level and the edge blurriness of each image to be contoured, and calculates the image complexity level, thereby providing a basis for classifying a large amount of image data according to image complexity and conducting targeted training to construct a contour extraction model based on edge detection, which can make the model better adapt to the characteristics of images of different complexities, and can conduct targeted learning and optimization for images of different complexity levels, thereby avoiding the problem of poor model training effect due to excessive differences in image complexity, and effectively improving the training efficiency and effect of the model; the contour extraction method based on edge detection constructed by the present invention The model is taken, and according to the image complexity level and attention mechanism, the edge direction distribution features, contour shape features and multi-scale texture features are effectively integrated, which not only ensures the full learning and extraction of multi-scale texture features of complex images, but also realizes efficient feature fusion of simple images, ensuring the training efficiency of the model, and making the model have higher accuracy and efficiency in contour extraction tasks; the present invention uses complexity classification image dataset to train the model, so that the model is exposed to images of various complexity levels during the training process, thereby learning a wider range of image features and contour patterns, which helps to improve the generalization ability of the model and enables it to more accurately extract contours when facing new images.
[0014] Furthermore, the S2 includes the following steps:
[0015] S21, converting the image to be contour-extracted into a grayscale image;
[0016] S22, filtering the grayscale image using a Gaussian kernel to obtain a smoothed image;
[0017] S23, performing noise quantization on the smoothed image based on a noise level quantization model to obtain a quantized value of the image noise level;
[0018] The calculation expression of the noise level quantization model in S22 is as follows:
[0019]
[0020] Among them, σ noi Represents the quantized value of the image noise level, H represents the height of the image to be contoured, W represents the width of the image to be contoured, I(i,j) represents the intensity value at the pixel position (i,j) in the image to be contoured, and I smooth(i, j) represents the intensity value at the pixel position (i, j) in the smoothed image, where i represents the horizontal coordinate of the pixel and j represents the vertical coordinate of the pixel.
[0021] S23, extracting edges from the contour extraction image according to the Canny algorithm, and setting a binary edge mask accordingly to obtain an edge mask set;
[0022] The calculation expression of the edge mask set is as follows:
[0023] S={I(i,j)|E(i,j)=1},
[0024] Where S represents the edge mask set, E(i, j) represents the binary edge mask at position (i, j) in the image to be contoured, and E(i, j) = 1 means that position (i, j) in the image to be contoured is the edge pixel position of the image to be contoured;
[0025] S24, calculating the image edge blur quantization value based on the edge mask set and the edge blur quantization model;
[0026] The calculation expression of the edge blur quantization model is as follows:
[0027]
[0028]
[0029] Among them, σ edge Represents the quantized value of the image edge blur, |·| represents the modulus, v represents the edge pixel intensity value, ∈ represents belonging to, represents the average edge pixel intensity value;
[0030] S25. Calculating an image complexity level based on an image complexity model according to the quantized value of the image noise level and the quantized value of the image edge blurriness;
[0031] The calculation expression of the image complexity model is as follows:
[0032]
[0033] σ noimax =max(I(i,j)-I smooth (i,j)), w1+w2=1,
[0034] Where C represents the image complexity level, round(·) represents the rounding function, m represents the maximum image complexity level, w1 represents the noise level weight coefficient, σ noimax represents the maximum noise corresponding to the pixel position in the image to be contour extracted, w2 represents the image edge fuzziness weight coefficient, σedgemax represents the threshold of the image edge blur quantization value, max(·) represents the maximum value, where m is a positive integer greater than or equal to 3;
[0035] S26. Based on the methods of S21-S25, respectively obtain the image complexity level of each image to be contour extracted.
[0036] The beneficial effect of adopting the above-mentioned further scheme is as follows: the present invention considers the image complexity of the two dimensions of noise level and edge blur of the image to be contour extracted, and calculates the image complexity level of the image to be contour extracted based on the quantized value of the image noise level and the quantized value of the image edge blur, which provides a basis for complexity classification of a large amount of image data, and also helps to train and improve the ability of the contour extraction model based on edge detection to accurately extract the contour of the object in complex image scenes.
[0037] Furthermore, the edge detection-based contour extraction model in S4 includes a feature extraction network, a feature fusion module and an edge generation module connected in sequence;
[0038] The feature extraction network is used to extract edge direction distribution features, contour shape features and multi-scale texture features of the image to be contour extracted through multi-layer convolution operations;
[0039] The feature fusion module is used to dynamically assign feature weights to edge direction distribution features and contour shape features based on the semantic information and spatial distribution characteristics in the edge direction distribution features and contour shape features according to the self-attention mechanism, and combine the feature weights of multi-scale texture features to obtain fused features;
[0040] The edge generation module is used to generate candidate contours corresponding to the fusion features based on the generative adversarial network, and optimize the candidate contours through a diffusion process to obtain a predicted image contour.
[0041] The beneficial effects of adopting the above-mentioned further scheme are as follows: the present invention enables the model to more accurately capture the contour information in the image through multi-dimensional feature extraction, dynamic feature weight allocation and comprehensive feature utilization; by generating high-quality candidate contours and optimizing contour quality, the model can generate more accurate predicted image contours.
[0042] Furthermore, the S5 includes the following steps:
[0043] S51. Randomly select an image to be contour-extracted from the complexity classification image dataset as a sample image;
[0044] S52, inputting the sample image into a contour extraction model based on edge detection, and using a feature extraction network to extract edge direction distribution features, contour shape features, and multi-scale texture features of the sample image;
[0045] S53, adjusting the feature weight of the multi-scale texture feature according to the image complexity level of the sample image;
[0046] S54, using the feature fusion module to assign feature weights to the edge direction distribution features and the contour shape features based on the self-attention mechanism, and combining the feature weights of the multi-scale texture features to perform feature splicing on the edge direction distribution features, the contour shape features, and the multi-scale texture features to obtain a fused feature;
[0047] S55, generating candidate contours corresponding to the fusion features based on the generative adversarial network, and optimizing the candidate contours through a diffusion process to obtain a predicted image contour;
[0048] S56. Repeat S51 to S55 several times according to the contour extraction training loss function until the contour extraction training loss function converges to a preset expected value, thereby obtaining a trained contour extraction model.
[0049] The beneficial effects of adopting the above-mentioned further scheme are as follows: the present invention dynamically adjusts the weights of multi-scale texture features according to the image complexity level, so that the model can automatically optimize the feature expression for images of different complexities and improve the ability to capture complex contours; the present invention generates candidate contours based on a generative adversarial network, and utilizes the adversarial training mechanism of the generator and the discriminator to enable the model to learn a distribution that is closer to the real contour, thereby improving the diversity and realism of the generated contours; the present invention iteratively optimizes the candidate contours through a diffusion model, gradually eliminating noise and artifacts in the generation process, and obtaining smoother and more accurate predicted contours, which has obvious effects on images with blurred edges or rich details.
[0050] Furthermore, the weight of the multi-scale texture feature in S53 is the quotient of the image complexity level and the highest image complexity level.
[0051] The beneficial effect of adopting the above further scheme is: setting the weight of the multi-scale texture feature in the present invention to the quotient of the image complexity level and the highest image complexity level can enhance the model's processing ability for complex images, improve the accuracy and robustness of edge detection and object contour extraction, and also provide a basis for improving training efficiency for simple images.
[0052] Furthermore, the S55 includes the following steps:
[0053] S551, obtaining the real annotated contour of the image to be contour extracted corresponding to the fusion feature;
[0054] S552, inputting the fused features into a generative adversarial network, and generating candidate contours through the generator;
[0055] S553, adding noise to the candidate contour through a diffusion module and performing forward diffusion to obtain a high-noise contour;
[0056] S554, gradually predicting the contour from the high-noise contour through the diffusion module and reversely removing the noise to optimize the contour edge continuity to obtain the predicted image contour;
[0057] S555, inputting the predicted image contour and the true annotated contour into the discriminator for binary classification to obtain the contour discrimination probability;
[0058] S556, feeding back the contour discrimination probability to the generator to adjust the generator parameters;
[0059] S557. Repeat S551 to S556 several times according to the generator training loss function until the contour discrimination probability reaches the preset probability threshold and enter S56.
[0060] The beneficial effects of adopting the above-mentioned further scheme are as follows: the present invention uses the adversarial training mechanism of the generative adversarial network to enable the generator to learn the distribution characteristics of the real annotated contour, thereby generating candidate contours that are more realistic and closer to the real contour; adding noise to the candidate contour and performing forward diffusion through the diffusion module, and then optimizing the continuity of the contour edge through reverse denoising, can effectively eliminate artifacts and noise in the generation process, and improve the smoothness and accuracy of the candidate contour; the present invention uses the discriminator to perform binary classification of the predicted image contour and the real annotated contour, and outputs the contour discrimination probability. This probability is used as a feedback signal to guide the generator parameter adjustment, so that the generator can gradually approach the generation capability of the real contour.
[0061] Furthermore, the calculation expression of the generator training loss function in S557 is as follows:
[0062] L Gan =λ smooth L smooth +λ acc L acc ,
[0063]
[0064] Among them, L Gan represents the generator training loss function, λ smooth Represents the contour smoothness loss weight coefficient, L smooth represents the contour smoothness loss function, λ acc Represents the contour accuracy loss weight coefficient, L acc represents the contour accuracy loss function, represents the curvature of the p-th point on the candidate contour, ||·|| 2 Indicates the square of the norm, N represents the total number of contour points on the candidate contour, Pp represents the pth point on the candidate contour, G q represents the qth point on the true annotation contour, k represents the image complexity level, and ||·|| represents the norm.
[0065] The beneficial effects of adopting the above-mentioned further scheme are as follows: the present invention provides a calculation method for the generator training loss function, which fully considers the contour smoothness and contour accuracy, and during training, the contour smoothness loss weight coefficient and the contour accuracy loss weight coefficient in the generator training loss function are both related to the image complexity level, so as to guide the generator to pay more attention to the edge generation of complex images and generate higher quality candidate contours.
[0066] Furthermore, the calculation expression of the contour extraction training loss function in S56 is as follows:
[0067]
[0068] Among them, L represents the contour extraction training loss function, w ssim represents the structural similarity weight, SSIM(·) represents the structural similarity loss function, Represents the predicted image contour, y gtedge represents the true annotation contour, w iou represents the weight of the contour intersection over union, IoU(·) represents the contour intersection over union loss function, w ede represents the edge distance weight, and EDE(·) represents the edge distance loss function.
[0069] The beneficial effects of adopting the above further scheme are as follows: the present invention uses indicators such as structural similarity index, contour intersection-union ratio and edge distance error to comprehensively calculate the loss between the image contour predicted by the edge generation module and the true labeled contour, wherein the structural similarity index quantifies the similarity between the predicted contour and the true contour from three aspects of brightness, contrast and structure, which can capture the overall perceptual quality of the image and avoid the limitations of relying solely on pixel-level errors. The contour intersection-union ratio directly reflects the geometric accuracy of the prediction result by calculating the ratio of the intersection and union of the predicted contour and the true contour, and is particularly suitable for evaluating the spatial coverage ability of the contour. The edge distance error evaluates the local positioning accuracy of the contour by measuring the average distance or maximum distance between the predicted contour and the true contour, which makes up for the lack of sensitivity of the intersection-union ratio to the contour shape details; the contour extraction training loss function provided by the present invention can simultaneously optimize the global similarity, geometric coverage and local positioning accuracy of the predicted contour, so that the model can still generate high-quality contours in complex scenes and reduce the risk of overfitting in training.
[0070] Other advantages of the present invention will be analyzed in more detail in subsequent embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0071] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following is a brief introduction to the drawings required for use in the embodiments. It should be understood that the following drawings only illustrate certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can be obtained based on these drawings without paying any creative work.
[0072] Figure 1 The figure is a flowchart of the steps of a contour extraction method based on edge detection in an embodiment of the present invention. DETAILED DESCRIPTION
[0073] The technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, not all of the embodiments. The components of the embodiments of the present invention generally described and shown in the drawings herein can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present invention provided in the drawings is not intended to limit the scope of the claimed invention, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without making creative work are within the scope of protection of the present invention.
[0074] like Figure 1 As shown, in one embodiment of the present invention, the present invention provides a contour extraction method based on edge detection, comprising the following steps:
[0075] S1, obtaining a number of images to be contour-extracted and the true annotated contours corresponding to each of the images to be contour-extracted;
[0076] S2. performing noise level quantization and edge blur quantization analysis on each image to be contour extracted, and calculating the image complexity level of each image to be contour extracted;
[0077] The S2 comprises the following steps:
[0078] S21, converting the image to be contour-extracted into a grayscale image;
[0079] S22, filtering the grayscale image using a Gaussian kernel to obtain a smoothed image;
[0080] S23, performing noise quantization on the smoothed image based on a noise level quantization model to obtain a quantized value of the image noise level;
[0081] The calculation expression of the noise level quantization model in S22 is as follows:
[0082]
[0083] Among them, σ noi Represents the quantized value of the image noise level, H represents the height of the image to be contoured, W represents the width of the image to be contoured, I(i,j) represents the intensity value at the pixel position (i,j) in the image to be contoured, and I smooth (i, j) represents the intensity value at the pixel position (i, j) in the smoothed image, where i represents the horizontal coordinate of the pixel and j represents the vertical coordinate of the pixel.
[0084] S23, extracting edges from the contour extraction image according to the Canny algorithm, and setting a binary edge mask accordingly to obtain an edge mask set;
[0085] In this scheme, the binary edge mask value of the pixels at the edge position in the smoothed image is set to 1, and the binary edge mask value of the pixels at other positions is set to 0. That is, this scheme realizes the division of pixels at the edge and non-edge positions in the image by setting the binary edge mask value, thereby providing a basis for accurately dividing the image complexity level.
[0086] The calculation expression of the edge mask set is as follows:
[0087] S={I(i,j)|E(i,j)=1},
[0088] Where S represents the edge mask set, E(i, j) represents the binary edge mask at position (i, j) in the image to be contoured, and E(i, j) = 1 means that position (i, j) in the image to be contoured is the edge pixel position of the image to be contoured;
[0089] S24, calculating the image edge blur quantization value based on the edge mask set and the edge blur quantization model;
[0090] The calculation expression of the edge blur quantization model is as follows:
[0091]
[0092] Among them, σ edge Represents the quantized value of the image edge blur, |·| represents the modulus, v represents the edge pixel intensity value, ∈ represents belonging to, represents the average edge pixel intensity value;
[0093] S25. Calculating an image complexity level based on an image complexity model according to the quantized value of the image noise level and the quantized value of the image edge blurriness;
[0094] The calculation expression of the image complexity model is as follows:
[0095]
[0096] σ noimax =max(I(i,j)-I smooth (i,j)), w1+w2=1,
[0097] Where C represents the image complexity level, round(·) represents the rounding function, m represents the maximum image complexity level, w1 represents the noise level weight coefficient, σ noimax represents the maximum noise corresponding to the pixel position in the image to be contour extracted, w2 represents the image edge fuzziness weight coefficient, σ edgemax represents the threshold of the image edge blur quantization value, max(·) represents the maximum value, where m is a positive integer greater than or equal to 3;
[0098] In this embodiment, the value of m is 5;
[0099] S26. Based on the methods of S21-S25, respectively obtain the image complexity level of each image to be contour extracted.
[0100] In this solution, a smaller image complexity level indicates a smaller image complexity of the image to be contour extracted, and level m indicates an extremely complex image to be contour extracted.
[0101] S3, classifying the complexity levels of the images to be contour extracted according to their image complexity levels, and constructing a complexity classification image dataset;
[0102] The edge detection-based contour extraction model in S4 includes a feature extraction network, a feature fusion module and an edge generation module connected in sequence;
[0103] The feature extraction network is used to extract edge direction distribution features, contour shape features and multi-scale texture features of the image to be contour extracted through multi-layer convolution operations;
[0104] In this solution, the feature extraction network uses the DarkNet53 module connected to the U-shaped network. The DarkNet53 module is the backbone network of YOLOv3 and achieves efficient feature extraction by stacking convolutional layers and residual blocks. When connected to the U-shaped network, the output feature map of the DarkNet53 module serves as the input of the U-shaped network, providing multi-scale feature information. The U-shaped network adopts an encoder-decoder structure. The encoder part gradually downsamples the feature map, and the decoder part restores the spatial resolution through upsampling and skip connections. The skip connection also fuses the low-level features in the encoder with the high-level features in the decoder, preserving the detailed information. In this invention, during upsampling in the decoder of the U-shaped network, the convolution operation is spliced with the same-scale downsampled feature layer in the encoder to integrate positioning and semantic information.
[0105] The feature fusion module is used to dynamically assign feature weights to edge direction distribution features and contour shape features based on the semantic information and spatial distribution characteristics in the edge direction distribution features and contour shape features according to the self-attention mechanism, and combine the feature weights of multi-scale texture features to obtain fused features;
[0106] In this scheme, the feature weights of multi-scale texture features are determined by the image complexity level, while the feature weights of edge direction distribution features and contour shape features are dynamically assigned by the self-attention mechanism according to the semantic information and spatial distribution characteristics in the image features. Finally, feature splicing is performed based on the weight distribution. This feature fusion method not only takes into account the increase in the weight distribution of multi-scale texture features for images with complex and rich image information, fully learning and extracting image objects and contour information, but also ensures that when facing images with simple and relatively single image information, the weight distribution of multi-scale texture features is reduced to improve training efficiency.
[0107] The edge generation module is used to generate candidate contours corresponding to the fusion features based on the generative adversarial network, and optimize the candidate contours through a diffusion process to obtain a predicted image contour.
[0108] In this solution, the edge generation module is implemented based on a generative adversarial network and diffusion process optimization. In this embodiment, the number of network layers in both the generator and discriminator of the generative adversarial network is set to 5, and the number of neurons in each layer is adjusted according to the output dimension of the previous layer to ensure that the model can effectively learn the image features and contour information. The parameters for adding and removing noise during the diffusion process were determined after multiple training sessions to add Gaussian noise with a large variance in the initial stage. As the number of iterations increases, the noise variance is gradually reduced to achieve a gradual optimization of the contour.
[0109] S4. Constructing a contour extraction model based on edge detection;
[0110] S5. According to the real annotated contours corresponding to the images to be contour-extracted, a contour extraction model based on edge detection is trained using the complexity classification image dataset to obtain a trained contour extraction model;
[0111] The S5 comprises the following steps:
[0112] S51. Randomly select an image to be contour-extracted from the complexity classification image dataset as a sample image;
[0113] S52, inputting the sample image into a contour extraction model based on edge detection, and using a feature extraction network to extract edge direction distribution features, contour shape features, and multi-scale texture features of the sample image;
[0114] S53, adjusting the feature weight of the multi-scale texture feature according to the image complexity level of the sample image;
[0115] The weight of the multi-scale texture feature in S53 is the quotient of the image complexity level and the highest image complexity level.
[0116] In this scheme, for images with high image complexity levels, the weight of their multi-scale texture features can be increased to better capture the texture features in the image. For images with low image complexity, the weight of their multi-scale texture features can be appropriately reduced to focus on extracting and fusing edge direction distribution features and contour shape features.
[0117] S54, using the feature fusion module to assign feature weights to the edge direction distribution features and the contour shape features based on the self-attention mechanism, and combining the feature weights of the multi-scale texture features to perform feature splicing on the edge direction distribution features, the contour shape features, and the multi-scale texture features to obtain a fused feature;
[0118] S55, generating candidate contours corresponding to the fusion features based on the generative adversarial network, and optimizing the candidate contours through a diffusion process to obtain a predicted image contour;
[0119] The S55 includes the following steps:
[0120] S551, obtaining the real annotated contour of the image to be contour extracted corresponding to the fusion feature;
[0121] S552, inputting the fused features into a generative adversarial network, and generating candidate contours through the generator;
[0122] In this scheme, the generative adversarial network includes a generator, a diffusion module, and a discriminator;
[0123] The generator is used to generate candidate contours corresponding to the fusion features according to the generator parameters; the diffusion module is used to add controllable noise to the candidate contours and diffuse it forward, and to gradually predict the contours and remove the noise in reverse to obtain the predicted image contours; the discriminator is used to discriminate the predicted image contours according to the real annotated contours, obtain a discrimination probability that can reflect the prediction accuracy, and feed the discrimination probability back to the generator to optimize the generator parameters and improve the quality of the generated candidate contours.
[0124] S553, adding noise to the candidate contour through a diffusion module and performing forward diffusion to obtain a high-noise contour;
[0125] S554, gradually predicting the contour from the high-noise contour through the diffusion module and reversely removing the noise to optimize the contour edge continuity to obtain the predicted image contour;
[0126] In this scheme, the diffusion module gradually optimizes the stability and accuracy of the generated contour by adding and removing noise at different time steps, making the generated contour more consistent with the shape of the real object, providing a basis for optimizing the quality of the predicted image contour through the diffusion process.
[0127] S555. Input the predicted image contour and the true annotated contour into the discriminator for binary classification to obtain the contour discrimination probability. In this solution, the discrimination probability of the discriminator corresponds to the similarity between the predicted image contour and the true annotated contour. The purpose of training the edge detection-based contour extraction model in this solution is to improve the discrimination probability.
[0128] S556, feeding back the contour discrimination probability to the generator to adjust the generator parameters;
[0129] In this scheme, the generator parameters refer to the convolution kernel weights and bias terms of each convolutional layer in the generator, the weight matrix and bias terms of the fully connected layer, the scaling parameters, offset parameters, running mean and running variance of the batch normalization layer.
[0130] S557. Repeat S551 to S556 several times according to the generator training loss function until the contour discrimination probability reaches the preset probability threshold and enter S56.
[0131] The calculation expression of the generator training loss function in S557 is as follows:
[0132] L Gan =λ smooth L smooth +λ acc L acc ,
[0133]
[0134] Among them, LGan represents the generator training loss function, λ smooth Represents the contour smoothness loss weight coefficient, L smooth represents the contour smoothness loss function, λ acc Represents the contour accuracy loss weight coefficient, L acc represents the contour accuracy loss function, represents the curvature of the p-th point on the candidate contour, ||·|| 2 Indicates the square of the norm, N represents the total number of contour points on the candidate contour, P p represents the pth point on the candidate contour, G q represents the qth point on the true annotation contour, k represents the image complexity level, and ||·|| represents the norm.
[0135] The generator training loss function constructed in this scheme consists of a contour smoothness loss function and a contour accuracy loss function. The contour smoothness loss function is used to penalize the irregularities of the candidate contours, such as sharp inflection points or violent fluctuations, to make the generated contours smoother, while the contour accuracy loss function is used to measure the difference between the candidate contours and the true contours to ensure that the prediction results are consistent with the target. During training, the contour smoothness loss weight coefficient and the contour accuracy loss weight coefficient in the generator training loss function are both related to the image complexity level to guide the generator to pay more attention to edge generation in complex images and generate higher quality candidate contours.
[0136] S56. Repeat S51 to S55 several times according to the contour extraction training loss function until the contour extraction training loss function converges to a preset expected value, thereby obtaining a trained contour extraction model.
[0137] The calculation expression of the contour extraction training loss function in S56 is as follows:
[0138]
[0139] Among them, L represents the contour extraction training loss function, w ssim represents the structural similarity weight, SSIM(·) represents the structural similarity loss function, Represents the predicted image contour, y gtedge represents the true annotation contour, w iou represents the weight of the contour intersection over union, IoU(·) represents the contour intersection over union loss function, w ede represents the edge distance weight, and EDE(·) represents the edge distance loss function.
[0140] S6. Obtain a new image to be contour extracted and an image complexity level, and input the image to be contour extracted into a trained contour extraction model for contour prediction to obtain a predicted image contour of the image as a contour extraction result.
[0141] In this solution, the method of S21 to S25 is used to obtain the image complexity level of the new image to be contour extracted.
[0142] The above description is only a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any technician familiar with this technical field can easily think of changes or replacements within the technical scope disclosed by the present invention, which should be covered by the scope of protection of the present invention.
Claims
1. A contour extraction method based on edge detection, characterized in that: The steps include: S1, obtaining a number of images to be contour-extracted and the true annotated contours corresponding to each of the images to be contour-extracted; S2. performing noise level quantization and edge blur quantization analysis on each image to be contour extracted, and calculating the image complexity level of each image to be contour extracted; S3, classifying the complexity levels of the images to be contour extracted according to their image complexity levels, and constructing a complexity classification image dataset; S4. Constructing a contour extraction model based on edge detection; S5. According to the real annotated contours corresponding to the images to be contour-extracted, a contour extraction model based on edge detection is trained using the complexity classification image dataset to obtain a trained contour extraction model; S6. Obtain a new image to be contour extracted and an image complexity level, and input the image to be contour extracted into a trained contour extraction model for contour prediction to obtain a predicted image contour of the image as a contour extraction result.
2. The contour extraction method based on edge detection according to claim 1, characterized in that: The S2 comprises the following steps: S21, converting the image to be contour-extracted into a grayscale image; S22, filtering the grayscale image using a Gaussian kernel to obtain a smoothed image; S23, performing noise quantization on the smoothed image based on a noise level quantization model to obtain a quantized value of the image noise level; The calculation expression of the noise level quantization model in S22 is as follows: Among them, σ noi Represents the quantized value of the image noise level, H represents the height of the image to be contoured, W represents the width of the image to be contoured, I(i,j) represents the intensity value at the pixel position (i,j) in the image to be contoured, and I smooth (i, j) represents the intensity value at the pixel position (i, j) in the smoothed image, where i represents the horizontal coordinate of the pixel and j represents the vertical coordinate of the pixel. S23, extracting edges from the contour extraction image according to the Canny algorithm, and setting a binary edge mask accordingly to obtain an edge mask set; The calculation expression of the edge mask set is as follows: S={I(i,j)|E(i,j)=1}, Where S represents the edge mask set, E(i, j) represents the binary edge mask at position (i, j) in the image to be contoured, and E(i, j) = 1 means that position (i, j) in the image to be contoured is the edge pixel position of the image to be contoured; S24, calculating the image edge blur quantization value based on the edge mask set and the edge blur quantization model; The calculation expression of the edge blur quantization model is as follows: Among them, σ edge Represents the quantized value of the image edge blur, |·| represents the modulus, v represents the edge pixel intensity value, ∈ represents belonging to, represents the average edge pixel intensity value; S25. Calculating an image complexity level based on an image complexity model according to the quantized value of the image noise level and the quantized value of the image edge blurriness; The calculation expression of the image complexity model is as follows: σ noimax =max(I(i,j)-I smooth (i,j)),w1+w2=1, Where C represents the image complexity level, round(·) represents the rounding function, m represents the maximum image complexity level, w1 represents the noise level weight coefficient, σ noimax represents the maximum noise corresponding to the pixel position in the image to be contour extracted, w2 represents the image edge fuzziness weight coefficient, σ edgemax Indicates the threshold of the image edge blur quantization value, max(·) indicates the maximum value, where m is a positive integer greater than or equal to 3; S26. Based on the methods of S21-S25, respectively obtain the image complexity level of each image to be contour extracted.
3. The contour extraction method based on edge detection according to claim 2, characterized in that: The edge detection-based contour extraction model in S4 includes a feature extraction network, a feature fusion module and an edge generation module connected in sequence; The feature extraction network is used to extract edge direction distribution features, contour shape features and multi-scale texture features of the image to be contour extracted through multi-layer convolution operations; The feature fusion module is used to dynamically assign feature weights to edge direction distribution features and contour shape features based on the semantic information and spatial distribution characteristics in the edge direction distribution features and contour shape features according to the self-attention mechanism, and combine the feature weights of multi-scale texture features to obtain fused features; The edge generation module is used to generate candidate contours corresponding to the fusion features based on the generative adversarial network, and optimize the candidate contours through a diffusion process to obtain a predicted image contour.
4. The contour extraction method based on edge detection according to claim 3, characterized in that: The S5 comprises the following steps: S51. Randomly select an image to be contour-extracted from the complexity classification image dataset as a sample image; S52, inputting the sample image into a contour extraction model based on edge detection, and using a feature extraction network to extract edge direction distribution features, contour shape features, and multi-scale texture features of the sample image; S53, adjusting the feature weight of the multi-scale texture feature according to the image complexity level of the sample image; S54, using the feature fusion module to assign feature weights to the edge direction distribution features and the contour shape features based on the self-attention mechanism, and combining the feature weights of the multi-scale texture features to perform feature splicing on the edge direction distribution features, the contour shape features, and the multi-scale texture features to obtain a fused feature; S55, generating candidate contours corresponding to the fusion features based on the generative adversarial network, and optimizing the candidate contours through a diffusion process to obtain a predicted image contour; S56. Repeat S51 to S55 several times according to the contour extraction training loss function until the contour extraction training loss function converges to a preset expected value, thereby obtaining a trained contour extraction model.
5. The contour extraction method based on edge detection according to claim 4, characterized in that: The weight of the multi-scale texture feature in S53 is the quotient of the image complexity level and the highest image complexity level.
6. The contour extraction method based on edge detection according to claim 4, characterized in that: The S55 includes the following steps: S551, obtaining the real annotated contour of the image to be contour extracted corresponding to the fusion feature; S552, inputting the fused features into a generative adversarial network, and generating candidate contours through the generator; S553, adding noise to the candidate contour through a diffusion module and performing forward diffusion to obtain a high-noise contour; S554, gradually predicting the contour from the high-noise contour through the diffusion module and reversely removing the noise to optimize the contour edge continuity to obtain the predicted image contour; S555, inputting the predicted image contour and the true annotated contour into the discriminator for binary classification to obtain the contour discrimination probability; S556, feeding back the contour discrimination probability to the generator to adjust the generator parameters; S557. Repeat S551 to S556 several times according to the generator training loss function until the contour discrimination probability reaches the preset probability threshold and enter S56.
7. The contour extraction method based on edge detection according to claim 6, characterized in that: The calculation expression of the generator training loss function in S557 is as follows: L Gan =λ smooth L smooth +λ acc L acc , Among them, L Gan represents the generator training loss function, λ smooth Represents the contour smoothness loss weight coefficient, L smooth represents the contour smoothness loss function, λ acc Represents the contour accuracy loss weight coefficient, L acc represents the contour accuracy loss function, represents the curvature of the p-th point on the candidate contour, ||·|| 2 Indicates the square of the norm, N represents the total number of contour points on the candidate contour, P p represents the pth point on the candidate contour, G q represents the qth point on the true annotation contour, k represents the image complexity level, and ||·|| represents the norm.
8. The contour extraction method based on edge detection according to claim 4, characterized in that: The calculation expression of the contour extraction training loss function in S56 is as follows: Among them, L represents the contour extraction training loss function, w ssim represents the structural similarity weight, SSIM(·) represents the structural similarity loss function, Represents the predicted image contour, y gtedge represents the true annotation contour, w iou represents the weight of the contour intersection over union, IoU(·) represents the contour intersection over union loss function, w ede represents the edge distance weight, and EDE(·) represents the edge distance loss function.
Citation Information
Cited By
Self-adaptive contour extraction and target recognition system and method for hand-eye calibration
CN121004617A