Cement crack detection method based on Anger model
Through the image repair network and watershed algorithm based on the Anogan model, the problem of insufficient accuracy and segmentation integrity in cement crack detection is solved, and efficient and accurate crack detection and length calculation are achieved.
Patent Information
- Application Number
- CN202411798064.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-09
- Publication Date
- 2025-04-15
AI Technical Summary
The existing cement crack detection methods have shortcomings in terms of accuracy and segmentation integrity, especially when dealing with small cracks, the positioning accuracy is not high, and the traditional methods are inefficient and subjective.
An image repair network based on the Anogan model is adopted, and the generator and discriminator are constructed, and fine features are extracted in combination with multi-scale hybrid attention modules, and crack detection is performed by combining curvature calculation and watershed algorithm to extract edge areas and crack centerlines.
Accurate detection and fine segmentation of cement cracks are achieved, the accuracy and efficiency of detection are improved, and the crack length can be accurately calculated.
Smart Images

Figure CN119831934A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of target detection, and in particular, to a cement crack detection method based on the Anogan model. Background Art
[0002] In the field of infrastructure maintenance, especially for road and bridge health monitoring, crack detection is a critical task. Cracks in cement pavement not only affect the appearance of the road and the driving experience, but more importantly, they are an important sign of structural health deterioration. If not handled in time, it may cause more serious structural damage and even threaten public safety. Therefore, developing a technology that can detect and segment cement cracks in real time, accurately and efficiently is crucial to ensure the long-term stability and safety of infrastructure.
[0003] Traditional crack detection methods mainly rely on manual visual inspection or simple image processing techniques. Although manual inspection is intuitive, it is inefficient, subjective, and difficult to implement in large-scale road networks. Early automation attempts based on image processing, such as edge detection and threshold segmentation, have improved detection speed, but these methods often have limited accuracy due to the complexity of the road background and changes in lighting conditions, especially when dealing with small cracks or complex crack patterns.
[0004] In recent years, deep learning techniques, especially convolutional neural networks (CNNs), have demonstrated excellent performance in image recognition and classification tasks. However, for cement crack detection and segmentation, although existing deep learning models have made significant progress in target detection, their positioning accuracy and segmentation integrity when dealing with small cracks still need to be improved. In addition, most current methods usually focus on target positioning rather than fine contour extraction, which is an obvious limitation in crack detection scenarios, because the precise location and shape of cracks are crucial to assessing their severity. Summary of the invention
[0005] In order to overcome at least one deficiency in the prior art, the present application provides a cement crack detection method based on the Anogan model.
[0006] In a first aspect, a cement crack detection method based on the Anogan model is provided, comprising:
[0007] An image restoration network is constructed, the image restoration network includes an Anogan model, the Anogan model includes a generator and a discriminator; the generator includes a first encoder, a decoder, and a second encoder connected in sequence; the first encoder and the second encoder have the same structure, both including a plurality of hybrid attention modules connected in sequence, and the hybrid attention module is used to extract fine attention features;
[0008] Train the image restoration network to obtain a trained generator;
[0009] Input the image to be detected into the trained generator to obtain the repaired image;
[0010] Calculate the difference between the repaired image and the image to be detected, and determine whether there is a crack in the image to be detected based on the difference;
[0011] If there are cracks in the image to be detected, calculate the curvature of each pixel in the image to be detected, and extract the edge area based on the curvature;
[0012] Perform distance transformation on the edge area to obtain a distance map; divide the edge area using a watershed algorithm based on the distance map to obtain multiple image areas; perform thinning processing on the multiple image areas to extract the crack centerline;
[0013] Calculate the length of the crack centerline to get the crack length.
[0014] In one embodiment, the first encoder includes a convolutional layer, a nonlinear activation function layer, and a plurality of hybrid attention modules connected in sequence;
[0015] The hybrid attention module includes: a downsampling unit, a multi-scale hybrid attention unit MS-HAM and a batch normalization + activation function unit; the multi-scale hybrid attention unit MS-HAM includes a multi-scale convolution module, a channel attention module and a spatial attention module.
[0016] In one embodiment, the decoder includes: a plurality of deconvolution units connected in sequence, the last deconvolution unit includes a convolution layer and an activation function layer; the remaining deconvolution units include a deconvolution layer, a batch normalization layer + an activation function layer.
[0017] In one embodiment, the discriminator includes a sequentially connected convolutional layer, a non-linear activation function layer, a plurality of sequentially connected hybrid attention modules, and a classification layer.
[0018] In one embodiment, calculating the curvature of each pixel in the image to be detected and extracting the edge area according to the curvature includes:
[0019] The image to be detected is smoothed using a Gaussian filter to remove noise and obtain a processed image;
[0020] Calculate the gradient I of each pixel in the x direction in the processed image x and the gradient in the y direction I y ;
[0021] According to the gradient I in the x direction x and the gradient in the y direction I y Calculate the second derivative of the image Ixx ,I yy , and the cross derivative I xy ;
[0022] The curvature of each pixel is calculated using the following formula:
[0023]
[0024] Among them, K(x,y) is the curvature of the pixel point (x,y);
[0025] Set the threshold K threshold , the edge value of each pixel is determined using the following formula:
[0026]
[0027] Among them, I edge (x,y) is the edge value of the pixel (x,y);
[0028] All pixels with edge values of 1 constitute the preliminary edge area;
[0029] The non-maximum suppression method is used to remove noise and fractures from the preliminary edge region, and the edge region is enhanced through a dilation operation to obtain the final edge region.
[0030] In one embodiment, distance transformation is performed on the edge region to obtain a distance map, including:
[0031] Calculate the distance between each pixel in the edge area and other pixels, and select the minimum value of all calculated distances as the distance value corresponding to the pixel;
[0032] The distance values of all pixels constitute a distance map.
[0033] In one embodiment, the edge area is divided using a watershed algorithm according to the distance map to obtain multiple image areas; including:
[0034] Find local maximum points in the distance graph;
[0035] According to the local maximum points and the distance map, the watershed algorithm is used to divide the edge area to obtain multiple image areas.
[0036] In one embodiment, calculating the length of the crack centerline includes:
[0037] The Euclidean distance between any two adjacent pixel points on the crack centerline is calculated, and all Euclidean distances are accumulated to obtain the length of the crack centerline.
[0038] In a second aspect, a cement crack detection device based on the Anogan model is provided, comprising:
[0039] A network construction module is used to construct an image restoration network, the image restoration network includes an Anogan model, the Anogan model includes a generator and a discriminator; the generator includes a first encoder, a decoder, and a second encoder connected in sequence; the first encoder and the second encoder have the same structure, both including a plurality of hybrid attention modules connected in sequence, and the hybrid attention module is used to extract fine attention features;
[0040] A network training module is used to train the image restoration network to obtain a trained generator;
[0041] The repair module is used to input the image to be detected into the trained generator to obtain the repaired image;
[0042] A crack detection module is used to calculate the difference between the repaired image and the image to be detected, and determine whether there is a crack in the image to be detected based on the difference;
[0043] The edge region extraction module is used to calculate the curvature of each pixel in the image to be detected if there are cracks in the image to be detected, and extract the edge region according to the curvature;
[0044] The crack centerline extraction module is used to perform distance transformation on the edge area to obtain a distance map; divide the edge area using a watershed algorithm based on the distance map to obtain multiple image areas; perform refinement processing on the multiple image areas to extract the crack centerline;
[0045] The crack length calculation module is used to calculate the length of the crack centerline, that is, the crack length.
[0046] Compared with the prior art, the present application has the following beneficial effects: the cement crack detection method based on the Anogan model of the present application designs a multi-scale hybrid attention unit MS-HAM in the Anogan model to extract fine attention features, thereby obtaining accurate repair images and ensuring the accuracy of crack detection results; at the same time, an improved crack extraction and length calculation method is adopted to obtain accurate length calculation results. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] The present application may be better understood by referring to the following description given in conjunction with the accompanying drawings, which together with the following detailed description are included in this specification and form a part of this specification. In the drawings:
[0048] Figure 1 A flow chart of a cement crack detection method based on the Anogan model is shown;
[0049] Figure 2 shows a schematic structural diagram of a first encoder;
[0050] Figure 3 shows a schematic diagram of the structure of the hybrid attention module;
[0051] Figure 4 A schematic diagram of the structure of a decoder is shown;
[0052] Figure 5 The structural block diagram of the cement crack detection device based on the Anogan model is shown. DETAILED DESCRIPTION
[0053] The exemplary embodiments of the present application will be described below in conjunction with the accompanying drawings. For the sake of clarity and conciseness, not all features of the actual embodiments are described in the specification. However, it should be understood that many implementation-specific decisions can be made in the process of developing any such actual embodiments in order to achieve the specific goals of the developer, and these decisions may vary from embodiment to embodiment.
[0054] It is also necessary to explain here that, in order to avoid obscuring the present application due to unnecessary details, only the device structure closely related to the scheme according to the present application is shown in the drawings, while other details that are not closely related to the present application are omitted.
[0055] It should be understood that the present application is not limited to the described implementation forms due to the following description with reference to the accompanying drawings. In this article, where feasible, the embodiments can be combined with each other, features between different embodiments can be replaced or borrowed, and one or more features can be omitted in one embodiment.
[0056] The present application embodiment provides a cement crack detection method based on the Anogan model. Figure 1 A flow chart of the cement crack detection method based on the Anogan model is shown in FIG. Figure 1 , methods include:
[0057] Step S1, constructing an image restoration network, the image restoration network includes an Anogan model, the Anogan model includes a generator and a discriminator; the generator includes a first encoder, a decoder, and a second encoder connected in sequence; the first encoder and the second encoder have the same structure, both including multiple hybrid attention modules connected in sequence, and the hybrid attention module is used to extract fine attention features.
[0058] Specifically, Figure 2 A schematic diagram of the structure of the first encoder is shown, see Figure 2 The first encoder includes a convolutional layer Conv, a nonlinear activation function layer Leaky Relu, and a plurality of hybrid attention modules connected in sequence. In this embodiment, the number of the hybrid attention modules can be 4 or 5.
[0059] Here, the stride of the convolution layer Conv is 2, the purpose is to reduce the size of the input image, and the Leaky Relu activation function is used to allow the gradient to flow through all layers.
[0060] Figure 3 shows a schematic diagram of the structure of the hybrid attention module, see Figure 2 and Figure 3 The hybrid attention module includes: downsampling unit Downsample, multi-scale hybrid attention unit (Multi-Scale Hybrid AttentionMechanism, MS-HAM) and batch normalization + activation function unit BacthcNorm + Leaky Relu; the multi-scale hybrid attention unit MS-HAM includes a multi-scale convolution module MultiScaleConv, a channel attention module ChannelAttention and a spatial attention module SpatialAttention.
[0061] Through the downsampling layer, the size of the feature map is halved, and the multi-scale hybrid attention unit MS-HAM is used to enhance the focus on local and global features and improve the expressiveness of features. The convolution kernels of the multi-scale convolution module MultiScaleConv, the channel attention module ChannelAttention, and the spatial attention module SpatialAttention are different, which are 3, 5, and 7 respectively. For the specific structure, see Figure 3 .
[0062] Figure 4 A schematic diagram of the decoder is shown in FIG. Figure 4 , the decoder includes: a plurality of deconvolution units connected in sequence, the last deconvolution unit includes a convolution layer and an activation function layer; the remaining deconvolution units include a deconvolution layer, a batch normalization layer + an activation function layer.
[0063] Here, the convolution kernel size of the deconvolution layer is 4, the step size is 1, and the feature map is continuously upsampled to nearly half the size of the original image through multiple deconvolution units, and then upsampled to the original image size by the final deconvolution layer.
[0064] Specifically, the discriminator includes a sequentially connected convolutional layer, a nonlinear activation function layer, a plurality of sequentially connected hybrid attention modules, and a classification layer.
[0065] In this step, the first encoder is used to convert the input image into a low-dimensional latent representation, the decoder is used to convert the low-dimensional latent representation to the image space and reconstruct a similar image; the second encoder is used to generate another latent representation based on the similar image; the discriminator is used to map the input image to the feature space and classify it as true or false.
[0066] The convolutional layers, nonlinear activation function layers, and multiple hybrid attention modules connected in sequence are used to extract features. The extracted features are input into the classification layer for classification to obtain a probability value ranging from 0 to 1, which indicates the probability that the input image is real data. Such a design can effectively perform binary classification tasks, that is, distinguish between real data and generated data.
[0067] Step S2: training the image restoration network to obtain a trained generator.
[0068] First, obtain the model training data set: along the crack direction on the target road surface, use the camera to continuously shoot and obtain a series of crack images. Classify the collected images into positive samples (no cracks) and test samples (with cracks).
[0069] Then, all data are uniformly converted into grayscale images and the pixel values are scaled to the range of [0, 1], and the size is scaled to 512*512 pixels. Simplifying image features and eliminating the effects of illumination changes while retaining the significant features of cracks includes: a) converting the original color image to a grayscale image; b) scaling the pixel values of the grayscale image from an 8-bit unsigned integer format to a floating point range of [0, 1]; c) uniformly adjusting the image size to 512×512 pixels; d) using histogram equalization to eliminate the effects of illumination changes in the image; e) highlighting the crack features through sharpening filtering or other enhancement techniques.
[0070] Then, the training data is input into the image restoration network for training, the Adam algorithm is used to optimize the weight parameters, and the trained model is saved.
[0071] The specific training process of the Anogan model is an existing technology and may include:
[0072] Generate noise: First generate a random noise Z.
[0073] Generate an image: Input the noise Z into the generator to generate an image.
[0074] Comparison loss: Compare the generated image with the images in the training set and calculate the loss value ResidualLoss. If the generated image does not match any image in the training set, it means that the image is abnormal.
[0075] Discriminator: In addition to the generator, the discriminator also plays an important role. The test image and the generated image are input to the discriminator, and the difference in output features is calculated, which is called Discrimination loss.
[0076] Merged loss function: Finally, the Discrimination Loss and Residual Loss are combined to form a loss function. The loss value is reduced through training to improve the detection ability of the model.
[0077] Step S3, input the image to be detected into the trained generator to obtain a repaired image.
[0078] Step S4, calculating the difference between the repaired image and the image to be detected, and determining whether there is a crack in the image to be detected based on the difference.
[0079] Here, the L2 norm is used to calculate the difference between the two images:
[0080]
[0081] Among them, I real is the image to be detected, I gen For the restored image, I real (i,j) is I real The pixel value at position (i, j) in I gen (i,j) is I gen The pixel value at position (i, j) in .
[0082] If the difference value is greater than the set threshold, it is determined that there is a crack in the image to be detected, otherwise, there is no crack.
[0083] Step S5: If there are cracks in the image to be detected, the curvature of each pixel in the image to be detected is calculated, and the edge area is extracted according to the curvature.
[0084] Step S6, performing distance transformation on the edge area to obtain a distance map; dividing the edge area using a watershed algorithm according to the distance map to obtain multiple image areas; performing thinning processing on the multiple image areas to extract the crack centerline, where a thinning algorithm can be used for thinning processing.
[0085] Step S7, calculating the length of the crack centerline, which is the crack length.
[0086] In the above embodiment, a multi-scale hybrid attention unit MS-HAM is designed in the Anogan model to extract fine attention features, thereby obtaining an accurate repair image and ensuring the accuracy of the crack detection result; at the same time, an improved crack extraction and length calculation method is used to obtain an accurate length calculation result.
[0087] In one embodiment, step S5, calculating the curvature of each pixel in the image to be detected and extracting the edge area according to the curvature, includes:
[0088] Step S51, using a Gaussian filter to perform smoothing processing on the image to be detected to remove noise, thereby obtaining a processed image.
[0089] Step S52, calculate the gradient I of each pixel in the processed image in the x direction x and the gradient in the y direction I y ;
[0090]
[0091] Among them, I represents the processed image.
[0092] Step S53: according to the gradient I in the x direction x and the gradient in the y direction I y Calculate the second derivative of the image I xx ,I yy , describes the curvature of the curve in the x and y directions, and the cross derivative I xy , describes the coupling effect of the curve in the x-direction and the y-direction.
[0093]
[0094] Step S54, using the following formula to calculate the curvature of each pixel:
[0095]
[0096] Among them, K(x,y) is the curvature of the pixel point (x,y);
[0097] Step S55, setting the threshold K threshold To distinguish significant edges, the edge value of each pixel is determined using the following formula:
[0098]
[0099] Among them, I edge (x,y) is the edge value of the pixel (x,y);
[0100] Step S56, all pixels with edge values of 1 constitute a preliminary edge area;
[0101] Step S57: A non-maximum suppression method is used to remove noise and fractures from the preliminary edge region, and an expansion operation is performed to enhance the edge region to obtain a final edge region.
[0102] Here, the non-maximum suppression method retains the local maximum as the edge point and removes other insignificant edges.
[0103] In one embodiment, step S6, performing distance transformation on the edge region to obtain a distance map, includes:
[0104] Calculate the distance between each pixel point (x, y) and other pixels in the edge area, and select the minimum value of all calculated distances as the distance value D(x, y) corresponding to the pixel point (x, y);
[0105] The distance values of all pixels constitute a distance map.
[0106] In one embodiment, step S6, dividing the edge area using a watershed algorithm according to the distance map to obtain multiple image areas, includes:
[0107] Find local maximum points in the distance graph;
[0108] According to the local maximum points and the distance map, the watershed algorithm is used to divide the edge area to obtain multiple image areas.
[0109] In this embodiment, the watershed algorithm is applied to image segmentation, the distance map is regarded as terrain, the local maximum points found on the distance map, that is, the initial markers Imarkers(x, y), are used as seed points, and various "watersheds" are generated from them. The watershed algorithm is used to divide the edge area to obtain multiple image areas.
[0110] In one embodiment, step S7, calculating the length of the crack centerline, includes:
[0111] The Euclidean distance between any two adjacent pixel points on the crack centerline is calculated, and all Euclidean distances are accumulated to obtain the length of the crack centerline.
[0112] Using the same inventive concept as the cement crack detection method based on the Anogan model, this embodiment also provides a corresponding cement crack detection device based on the Anogan model. Figure 5 The structural block diagram of the cement crack detection device based on the Anogan model is shown, and the device includes:
[0113] A network construction module 51 is used to construct an image restoration network, the image restoration network includes an Anogan model, the Anogan model includes a generator and a discriminator; the generator includes a first encoder, a decoder and a second encoder connected in sequence; the first encoder and the second encoder have the same structure, both including a plurality of hybrid attention modules connected in sequence, and the hybrid attention module is used to extract fine attention features;
[0114] A network training module 52 is used to train the image restoration network to obtain a trained generator;
[0115] A repair module 53 is used to input the image to be detected into the trained generator to obtain a repaired image;
[0116] A crack detection module 54 is used to calculate the difference between the repaired image and the image to be detected, and determine whether there is a crack in the image to be detected according to the difference;
[0117] The edge region extraction module 55 is used to calculate the curvature of each pixel in the image to be detected if there are cracks in the image to be detected, and extract the edge region according to the curvature;
[0118] The crack centerline extraction module 56 is used to perform distance transformation on the edge area to obtain a distance map; divide the edge area using a watershed algorithm according to the distance map to obtain multiple image areas; perform thinning processing on the multiple image areas to extract the crack centerline;
[0119] The crack length calculation module 57 is used to calculate the length of the crack centerline, that is, the crack length.
[0120] The cement crack detection device based on the Anogan model of this embodiment has the same inventive concept as the cement crack detection method based on the Anogan model mentioned above. Therefore, the specific implementation method of the device can be seen in the implementation example part of the cement crack detection method based on the Anogan model mentioned above, and its technical effect corresponds to the technical effect of the above method, which will not be repeated here.
[0121] The above are only various implementations of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A cement crack detection method based on the Anogan model, characterized in that: include: An image restoration network is constructed, wherein the image restoration network includes an Anogan model, wherein the Anogan model includes a generator and a discriminator; the generator includes a first encoder, a decoder, and a second encoder connected in sequence; the first encoder and the second encoder have the same structure, both including a plurality of hybrid attention modules connected in sequence, wherein the hybrid attention module is used to extract fine attention features; Training the image restoration network to obtain a trained generator; Inputting the image to be detected into the trained generator to obtain a restored image; Calculating the difference between the repaired image and the image to be detected, and determining whether there is a crack in the image to be detected according to the difference; If there are cracks in the image to be detected, calculate the curvature of each pixel in the image to be detected, and extract the edge area according to the curvature; Performing distance transformation on the edge area to obtain a distance map; dividing the edge area using a watershed algorithm according to the distance map to obtain multiple image areas; performing thinning processing on the multiple image areas to extract the crack centerline; The length of the crack centerline is calculated to be the crack length.
2. The method according to claim 1, characterized in that The first encoder includes a convolutional layer, a nonlinear activation function layer, and a plurality of hybrid attention modules connected in sequence; The hybrid attention module includes: a downsampling unit, a multi-scale hybrid attention unit MS-HAM and a batch normalization + activation function unit; the multi-scale hybrid attention unit MS-HAM includes a multi-scale convolution module, a channel attention module and a spatial attention module.
3. The method according to claim 1, characterized in that The decoder comprises: a plurality of deconvolution units connected in sequence, the last deconvolution unit comprises a convolution layer and an activation function layer; the remaining deconvolution units comprise a deconvolution layer, a batch normalization layer+an activation function layer.
4. The method according to claim 1, characterized in that The discriminator includes a sequentially connected convolutional layer, a nonlinear activation function layer, a plurality of sequentially connected hybrid attention modules, and a classification layer.
5. The method according to claim 1, characterized in that in, Calculating the curvature of each pixel in the image to be detected, and extracting the edge area according to the curvature, including: The image to be detected is smoothed by using a Gaussian filter to remove noise, thereby obtaining a processed image; Calculate the gradient I of each pixel in the processed image in the x direction x and the gradient in the y direction I y ; According to the gradient I in the x direction x and the gradient in the y direction I y Calculate the second derivative of the image I xx ,I yy , and the cross derivative I xy ; The curvature of each pixel is calculated using the following formula: Among them, K(x,y) is the curvature of the pixel point (x,y); Set the threshold K threshold , the edge value of each pixel is determined using the following formula: Among them, I edge (x,y) is the edge value of the pixel (x,y); All pixels with edge values of 1 constitute the preliminary edge area; A non-maximum suppression method is used to remove noise and fractures from the preliminary edge region, and a dilation operation is performed to enhance the edge region to obtain a final edge region.
6. The method according to claim 1, characterized in that in, Performing distance transformation on the edge region to obtain a distance map includes: Calculate the distance between each pixel point in the edge area and other pixel points, and select the minimum value of all calculated distances as the distance value corresponding to the pixel point; The distance values of all pixels constitute a distance map.
7. The method according to claim 1, characterized in that in, Dividing the edge area using a watershed algorithm according to the distance map to obtain multiple image areas; including: Finding a local maximum point in the distance map; According to the local maximum point and the distance map, the edge area is divided by using a watershed algorithm to obtain a plurality of image areas.
8. The method according to claim 1, characterized in that in, Calculating the length of the crack centerline includes: The Euclidean distance between any two adjacent pixel points on the crack centerline is calculated, and all Euclidean distances are accumulated to obtain the length of the crack centerline.
9. A cement crack detection device based on the Anogan model, characterized in that: include: A network construction module, used to construct an image restoration network, wherein the image restoration network includes an Anogan model, wherein the Anogan model includes a generator and a discriminator; the generator includes a first encoder, a decoder, and a second encoder connected in sequence; the first encoder and the second encoder have the same structure, both including a plurality of hybrid attention modules connected in sequence, wherein the hybrid attention module is used to extract fine attention features; A network training module, used to train the image restoration network to obtain a trained generator; A repair module, used for inputting the image to be detected into the trained generator to obtain a repaired image; A crack detection module, used to calculate the difference between the repaired image and the image to be detected, and determine whether there is a crack in the image to be detected according to the difference; An edge region extraction module, used for calculating the curvature of each pixel in the image to be detected if there are cracks in the image to be detected, and extracting the edge region according to the curvature; A crack centerline extraction module is used to perform distance transformation on the edge area to obtain a distance map; divide the edge area using a watershed algorithm according to the distance map to obtain multiple image areas; and perform thinning processing on the multiple image areas to extract the crack centerline; The crack length calculation module is used to calculate the length of the crack centerline, that is, the crack length.