Defect edge extraction method and device based on terahertz image, terminal equipment and storage medium
By enhancing and segmenting terahertz images, and combining the inter-class variance method and active contour model, defect edge curves are automatically generated. This solves the problems of large errors and low efficiency caused by manually specifying defect areas in existing technologies, and achieves efficient and accurate defect edge extraction.
Patent Information
- Application Number
- CN202510960154.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-11
- Publication Date
- 2025-10-24
AI Technical Summary
The existing technology requires manual pre-designation of defect areas and has large errors in defect edge extraction, resulting in low efficiency.
After acquiring the original terahertz image and performing enhancement processing, the mean shift algorithm is used to segment it into the target region. The segmentation threshold is calculated by combining the maximum inter-class variance method. The input is then used to generate defect edge curves by an active contour model. Finally, a conditional adversarial generative network is used for image enhancement.
It realizes the automatic generation of defect areas, reduces human errors, and improves the accuracy and efficiency of defect edge extraction.
Smart Images

Figure CN120833351A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of defect detection, and in particular to a defect edge extraction method and device based on a terahertz image, a terminal device and a storage medium. BACKGROUND
[0002] Epoxy resins are widely used in the paint industry for metal anticorrosion and have developed into green anticorrosive coatings in many industrial fields. Epoxy resin coatings often work in corrosive environments. It becomes increasingly important to monitor them in a timely manner, as corrosion damage can greatly affect the performance and durability of structures. Reliable and effective detection is crucial. In addition to X-ray imaging and infrared imaging, terahertz (THz) pulse imaging technology has become a very attractive non-contact, non-destructive detection tool. Optical terahertz systems based on time-domain spectroscopy (TDS) principles enable the characterization of known and unknown multilayer systems below several microns. The advantage of sub-picosecond time resolution makes it a promising technology in some industrial quality detection. The ability of terahertz non-destructive testing of coating structures has been extensively studied in the past few years.
[0003] The defect edge extraction of the terahertz image often uses an active contour model. The traditional active contour model needs to manually pre-specify a defect region, and has low efficiency. Moreover, the convergence of the active contour model to a concave region and an inflection point position in a defect image is not good, resulting in a large defect edge extraction error. SUMMARY
[0004] The present application provides a defect edge extraction method and device based on a terahertz image, a terminal device and a storage medium, which can solve the problem of the prior art that a defect region needs to be manually pre-specified and has a large defect edge extraction error.
[0005] An embodiment of the present application provides a defect edge extraction method based on a terahertz image, comprising:
[0006] obtaining an original terahertz image;
[0007] performing enhancement processing on the original terahertz image to obtain an enhanced terahertz image;
[0008] segmenting the enhanced terahertz image into a plurality of target regions by a mean shift algorithm;
[0009] for each target region, calculating a segmentation threshold of a foreground and a background in the target region by an OTSU method, and segmenting a foreground region from the target region according to the segmentation threshold, as a defect region;
[0010] inputting the defect region into an active contour model, so that the active contour model generates a defect edge curve according to the defect region.
[0011] Further, the original terahertz image is input into the trained image enhancement model, so that a generator in the image enhancement model generates a preliminary enhanced terahertz image according to the original terahertz image.
[0012] Further, the original terahertz image is input into the trained image enhancement model, so that a generator in the image enhancement model generates a preliminary enhanced terahertz image according to the original terahertz image.
[0013] Further, the original terahertz image is input into the trained image enhancement model, so that a generator in the image enhancement model generates a preliminary enhanced terahertz image according to the original terahertz image.
[0014] Further, the original terahertz image is input into the trained image enhancement model, so that a generator in the image enhancement model generates a preliminary enhanced terahertz image according to the original terahertz image.
[0015] Further, the original terahertz image is input into the trained image enhancement model, so that a generator in the image enhancement model generates a preliminary enhanced terahertz image according to the original terahertz image.
[0016] Further, the original terahertz image is input into the trained image enhancement model, so that a generator in the image enhancement model generates a preliminary enhanced terahertz image according to the original terahertz image.
[0017] Further, the original terahertz image is input into the trained image enhancement model, so that a generator in the image enhancement model generates a preliminary enhanced terahertz image according to the original terahertz image.
[0018] Further, the original terahertz image is input into the trained image enhancement model, so that a generator in the image enhancement model generates a preliminary enhanced terahertz image according to the original terahertz image.
[0019] Further, the original terahertz image is input into the trained image enhancement model, so that a generator in the image enhancement model generates a preliminary enhanced terahertz image according to the original terahertz image.
[0020] Further, the original terahertz image is input into the trained image enhancement model, so that a generator in the image enhancement model generates a preliminary enhanced terahertz image according to the original terahertz image.
[0021] Further, the original terahertz image is input into the trained image enhancement model, so that a generator in the image enhancement model generates a preliminary enhanced terahertz image according to the original terahertz image.
[0022] Randomly selecting a pixel point in the enhanced terahertz image as an initial center point;
[0023] Repeating the center point moving operation until a modulus value of each pixel in the enhanced terahertz image is obtained; dividing pixels with the same modulus value into the same target area to obtain a plurality of target areas;
[0024] The center point moving operation includes:
[0025] Setting a drift point at the location of the current center point; wherein, when the center point movement operation is performed for the first time, the current center point is the initial center point;
[0026] Repeat the drift point movement operation until the number of iterations of the drift point movement operation reaches a preset first iteration number threshold or the mean drift vector of the current drift point is less than a preset mean drift vector threshold; use the modulus of the mean drift vector of the current drift point as the modulus value of the current center point; move the center point to the position of the current drift point, and delete the drift point;
[0027] The drift point moving operation includes:
[0028] Determine all first neighboring points within a certain distance around the current drift point; calculate the mean drift vector of the current drift point based on the positions of all first neighboring points;
[0029] Move the drift point according to the mean drift vector of the current drift point.
[0030] Furthermore, the segmentation thresholds of the foreground and background in the target area are calculated by the maximum inter-class variance method, including:
[0031] Dividing the target area into several gray levels according to the gray value of each pixel;
[0032] For each gray level, pixels with gray values less than or equal to the gray level are regarded as background, pixels with gray values greater than the gray level are regarded as foreground, and the inter-class variance between the foreground and background is calculated;
[0033] The gray level with the largest inter-class variance is used as the segmentation threshold.
[0034] Furthermore, generating a defect edge curve according to the defect area includes:
[0035] extracting an initial edge curve of the defect area;
[0036] Repeat the edge curve updating operation until the number of iterations reaches a preset second iteration number threshold or the relative change rate of the energy function is less than a preset relative change rate threshold; and use the current edge curve as the defect edge curve;
[0037] The edge curve updating operation comprises:
[0038] According to the current edge curve, an energy function is constructed, and a current energy function value is calculated;Wherein, when the edge curve updating operation is performed for the first time, the current edge curve is the initial edge curve;
[0039] According to the current energy function value and the energy function value of the last iteration, the relative change rate of the energy function is calculated;Wherein, when the edge curve updating operation is performed for the first time, the calculation of the relative change rate of the energy function is not performed;
[0040] For each curve pixel point on the current edge curve, eight second adjacent points adjacent to the curve pixel point are determined;The curve pixel point on the current edge curve is replaced by the second adjacent point in turn, and the candidate energy function value of the current edge curve after replacement is calculated in turn;The target pixel point corresponding to the maximum energy function value in the current energy function value and the candidate energy function value corresponding to each second adjacent point is determined;The target pixel point is used to replace the curve pixel point.
[0041] Another embodiment of the application also provides a defect edge extraction device based on a terahertz image, comprising: an image acquisition module, an image enhancement module, an image segmentation module, a defect region extraction module and a defect edge curve extraction module;
[0042] The image acquisition module is used to acquire an original terahertz image;
[0043] The image enhancement module is used to perform enhancement processing on the original terahertz image to obtain an enhanced terahertz image;
[0044] The image segmentation module is used to segment the enhanced terahertz image into a plurality of target regions by using a mean shift algorithm;
[0045] The defect region extraction module is used to calculate the segmentation threshold of the foreground and the background in each target region by using the maximum inter-class variance method, and segment the foreground region from the target region as a defect region according to the segmentation threshold;
[0046] The defect edge curve extraction module is used to input the defect region into an active contour model, so that the active contour model generates a defect edge curve according to the defect region.
[0047] Another embodiment of the present application also provides a terminal device, comprising a processor, a memory and a computer program stored in the memory and configured to be executed by the processor, when the computer program is executed by the processor, the steps of the method for extracting defect edge based on terahertz image are implemented.
[0048] Another embodiment of the present application also provides a computer readable storage medium, comprising a stored computer program, when the computer program is executed, the device where the computer readable storage medium is located executes the steps of the method for extracting defect edge based on terahertz image.
[0049] By implementing the present application, the following beneficial effects are achieved:
[0050] The present application obtains an original terahertz image, performs enhancement processing on the original terahertz image to obtain an enhanced terahertz image, divides the enhanced terahertz image into a plurality of target regions through a mean shift algorithm, divides a defect region from the target regions according to a segmentation threshold, inputs the defect region into an active contour model, and makes the active contour model generate a defect edge curve according to the defect region. The present application can automatically generate a defect region without manual designation, reduces human error, and saves manpower. The present application combines inter-class variance calculation to perform threshold segmentation on the target region, and optimizes the convergence effect of the concave region and the inflection point position in the defect image.
[0051] In summary, the present application can effectively solve the problem of poor defect edge extraction effect in the prior art. BRIEF DESCRIPTION OF DRAWINGS
[0052] In order to more clearly illustrate the technical solutions of the present application, the following will briefly introduce the drawings needed in the embodiments. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can also be obtained by those skilled in the art without creative labor.
[0053] Figure 1 is a flowchart of a method for extracting defect edge based on terahertz image provided by an embodiment of the present application;
[0054] Figure 2 is a structural diagram of an image enhancement model provided by an embodiment of the present application;
[0055] Figure 3 is a structural diagram of a device for extracting defect edge based on terahertz image provided by an embodiment of the present application. DETAILED DESCRIPTION
[0056] In order to make the objects, technical solutions and advantages of the present application clearer, the following will clearly and completely describe the technical solutions in the present application in conjunction with the accompanying drawings of the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the scope of protection of the present application.
[0057] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs; the terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of this application; the use of the terms "including," "comprising," or "having" in the specification and claims herein are used to mean "including but not limited to," or the like.
[0058] In the description of the embodiments of the present application, the technical terms "first", "second", etc. are only used to distinguish different objects, and cannot be understood as indicating or implying relative importance or implicitly indicating the number, specific order or primary and secondary relationship of the indicated technical features. In the description of the embodiments of the present application, the meaning of "a plurality of" is two or more, unless otherwise explicitly and specifically limited.
[0059] Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the present application. The appearance of the phrase in various places in the specification does not necessarily all refer to the same embodiment, nor is it necessarily independent or alternative embodiments to other embodiments. Those skilled in the art explicitly and implicitly understand that the embodiments described herein can be combined with other embodiments.
[0060] In the description of the embodiments of the present application, the term "several" refers to two or more (including two).
[0061] Reference is made to Figure 1 To solve the problem of manual pre-specification of defect area and large defect edge extraction error in the prior art, an embodiment of the present application provides a defect edge extraction method based on a terahertz image, comprising:
[0062] S1, obtaining an original terahertz image.
[0063] It should be noted that the original terahertz image obtained is of an epoxy resin coating.
[0064] S2, performing enhancement processing on the original terahertz image to obtain an enhanced terahertz image.
[0065] In a preferred embodiment, the enhancement processing on the original terahertz image to obtain an enhanced terahertz image comprises:
[0066] inputting the original terahertz image into the trained image enhancement model, so that a generator in the image enhancement model generates a preliminary enhanced terahertz image according to the original terahertz image;
[0067] performing median filtering processing on the preliminary enhanced terahertz image to obtain the enhanced terahertz image;
[0068] The image enhancement model is a conditional adversarial generative network, and includes a generator and a discriminator.
[0069] The training method of the image enhancement model includes:
[0070] obtaining a plurality of original terahertz image samples, performing non-local mean filtering processing and histogram equalization processing on the original terahertz image samples to obtain real terahertz image samples;
[0071] performing contrast reduction and resolution reduction processing on each of the real terahertz image samples to generate a corresponding initial terahertz image sample;
[0072] inputting each of the real terahertz image samples and the corresponding initial terahertz image sample into the image enhancement model, so that the image enhancement model generates an enhanced terahertz image sample according to the initial terahertz image sample through the generator; the discriminator calculates a first probability that the enhanced terahertz image sample is real and a second probability that the real terahertz image sample is real, calculates a discriminator loss function according to the first probability and the second probability, updates parameters of the discriminator through a back propagation algorithm according to the discriminator loss function; after the discriminator performs a preset number of updates, the discriminator recalculates a third probability that the enhanced terahertz image sample is real, calculates a generator loss function according to the third probability, and updates parameters of the generator through the back propagation algorithm according to the generator loss function.
[0073] It should be noted that a sample piece with different pre-prepared defects is prepared, and the sample piece is subjected to terahertz nondestructive testing and imaging testing by using a terahertz nondestructive testing and imaging testing system to obtain an original terahertz image sample. The sample piece is an epoxy resin coating sample piece.
[0074] In the embodiment, the original terahertz image sample is subjected to non-local mean filtering processing and limited contrast histogram equalization processing, and is output as an image with a resolution of 256x256, as a real terahertz image sample. The limited contrast histogram equalization processing is to prevent the contrast from being excessively strong. Then, a mature image processing algorithm is used to reduce the resolution and contrast of the real terahertz image sample, to generate an initial terahertz image sample. The initial terahertz image sample has lower quality than the real terahertz image sample. The initial terahertz image sample and the real terahertz image sample constitute a training sample set X i is an initial terahertz image sample, Y i is a real terahertz image sample, and N is the size of the data set.
[0075] The real terahertz image sample and the corresponding initial terahertz image sample are input into an image enhancement model for model training, and the specific process is as follows:
[0076] 1. Initialize the model:
[0077] (1) Generator: input the initial terahertz image sample X i , and generate an enhanced terahertz image sample X' i ;
[0078] (2) Discriminator: determine whether the input data is real data (real terahertz image sample Y i ) or fake data generated by the generator, and calculate the first probability that the enhanced terahertz image sample is real and the second probability that the real terahertz image sample is real.
[0079] 2. Train the discriminator (optimize the weight parameters of the discriminator through gradient backpropagation of the real data Y i and the generated data X' i , so that it can more accurately distinguish between real and fake samples):
[0080] (1) Calculate the discriminator loss function (such as binary cross-entropy loss) according to the first probability and the second probability;
[0081] (2) Calculate the gradient of the discriminator loss function with respect to the parameters of the discriminator through the backpropagation algorithm;
[0082] (3) Update the parameters of the discriminator according to the preset learning rate of the discriminator, to minimize the discriminator loss function;
[0083] 3. Train the generator (optimize the network weight parameters of the generator through gradient backpropagation of the discriminator on the generated data, so that it generates data closer to the real data):
[0084] (1) Use the updated discriminator to determine whether the fake sample X'i Evaluation is performed, and X' is calculated i a third probability that is true;
[0085] (2) Calculate the generator loss function (such as binary cross-entropy loss) of the third probability calculation generator;
[0086] (3) Calculate the gradient of the generator loss function on the generator parameters through the back propagation algorithm;
[0087] (4) Update the parameters of the generator according to the preset generator learning rate to minimize the loss function of the generator.
[0088] 4. Alternating iteration:
[0089] (1) Alternating update: the training of the generator and the discriminator is usually alternated in a fixed ratio, that is, the update of the generator is performed only after the discriminator has performed a preset number of updates (for example, the generator is trained once after the discriminator is trained 5 times) ;
[0090] (2) Iterative optimization: through multiple iterations, the parameters of the generator and the discriminator are constantly adjusted, and finally reach a Nash equilibrium state, that is, the samples generated by the generator are difficult to be distinguished by the discriminator.
[0091] In another embodiment, the generator loss function comprises a content loss and an adversarial loss.
[0092] wherein the expression of the generator loss function is:
[0093]
[0094] In the formula, denotes the generator loss; denotes the adversarial loss; denotes the content loss; λ denotes the weight of the content loss;
[0095] The expression of the content loss is:
[0096]
[0097] In the formula, denotes the content loss; ‖·‖2 denotes the L2 norm calculation; G(X) denotes the enhanced terahertz image output by the generator G; X denotes the initial terahertz image input into the generator G; Y denotes the real terahertz image;
[0098] The expression of the adversarial loss is:
[0099]
[0100] In the formula, represents the adversarial loss; D(G(X), X) represents the third probability output by the discriminator D.
[0101] It should be noted that the content loss prompts the generator to output an enhanced result approximating the high-contrast image, and the adversarial loss prompts the generator to output an enhanced result indistinguishable from the high-contrast image. The weight of the content loss is generally set to 100.
[0102] In another embodiment, the objective function expression of the discriminator is:
[0103]
[0104] In the formula, E represents an expectation operator; D(G(X)) represents the first probability output by the discriminator D; and D(Y) represents the second probability output by the discriminator D.
[0105] It should be noted that, in order to reduce the instability in adversarial training, a conditional term is introduced in the input of the discriminator, taking the input image X as the conditional term, so that the objective function of the discriminator in the algorithm is defined as follows:
[0106]
[0107] In a preferred embodiment, the generator is sequentially composed of a resolution reduction module, a feature extraction module, and a resolution restoration module.
[0108] The feature extraction module is sequentially composed of a first convolutional layer, a second convolutional layer, a third convolutional layer, a scale normalization layer, and a ReLU activation layer; wherein the output of the first convolutional layer and the output of the third convolutional layer are cascaded through a skip connection layer.
[0109] It should be noted that the output of the first convolutional layer and the output of the third convolutional layer are cascaded through a skip connection layer, which can better preserve the detailed features of the input image in the network mapping.
[0110] In the present embodiment, the resolution reduction module is configured to reduce the resolution of the input image and output a feature image; the feature extraction module is configured to linearly combine the feature image extracted from the input image; and the resolution restoration module is configured to restore the resolution of the cascaded feature image to the resolution of the input image.
[0111] In another embodiment, the resolution reduction module is sequentially composed of a convolution layer with a convolution kernel of 4x4, a step of 2x2 and padding of 1x1, and a ReLU activation layer; the feature extraction module is sequentially composed of three consecutive convolution layers with a convolution kernel of 3x3, a step of 1x1 and padding of 1x1, a scale normalization layer and a ReLU activation layer; and the resolution restoration module is sequentially composed of a deconvolution layer with a convolution kernel of 4x4, a step of 2x2 and padding of 1x1, and a ReLU activation layer.
[0112] The parameter settings of the convolution layers in the generator are shown in Table 1.
[0113]
[0114] Table 1
[0115] In another embodiment, the discriminator is sequentially composed of five convolution layers, a scale normalization layer, a LeakyReLU activation layer and a sigmoid function. Among the five convolution layers of the discriminator, each convolution layer except the first and the last convolution layer is accompanied by a scale normalization layer and a LeakyReLU activation layer.
[0116] The parameter settings of the convolution layers in the discriminator are shown in Table 2.
[0117]
[0118] Table 2
[0119] Please refer to Figure 2 A structure diagram of an image enhancement model provided by an embodiment of the present application.
[0120] In another embodiment, the median filtering processing of the preliminary enhanced terahertz image comprises:
[0121] The preliminary enhanced terahertz image is subjected to median filtering processing by using a square window of 3x3.
[0122] It should be noted that the median filtering processing can reduce the false edges in the image caused by noise.
[0123] S3, the enhanced terahertz image is segmented into a plurality of target regions by a mean shift algorithm.
[0124] In a preferred embodiment, the enhanced terahertz image is segmented into a plurality of target regions by a mean shift algorithm, which comprises:
[0125] A pixel point in the enhanced terahertz image is randomly selected as an initial center point;
[0126] Repeating the center point moving operation until a modulus value of each pixel in the enhanced terahertz image is obtained; dividing pixels with the same modulus value into the same target area to obtain a plurality of target areas;
[0127] The center point moving operation includes:
[0128] Setting a drift point at the location of the current center point; wherein, when the center point movement operation is performed for the first time, the current center point is the initial center point;
[0129] Repeat the drift point movement operation until the number of iterations of the drift point movement operation reaches a preset first iteration number threshold or the mean drift vector of the current drift point is less than a preset mean drift vector threshold; use the modulus of the mean drift vector of the current drift point as the modulus value of the current center point; move the center point to the position of the current drift point, and delete the drift point;
[0130] The drift point moving operation includes:
[0131] Determine all first neighboring points within a certain distance around the current drift point; calculate the mean drift vector of the current drift point based on the positions of all first neighboring points;
[0132] Move the drift point according to the mean drift vector of the current drift point.
[0133] In this embodiment, the specific steps of the mean shift algorithm are:
[0134] 1) Randomly select any pixel point in the enhanced terahertz image as the initial center point x;
[0135] 2) Set the drift point at the current center point;
[0136] 3) Find the first neighboring point within the bandwidth from the current drift point, that is, search within the radius h to satisfy ‖xx i Pixel x where ‖≤h i , h is the bandwidth; calculate all first neighboring points {x i}The mean drift vector relative to the current drift point x:
[0137]
[0138] K(x)=k(‖x‖ 2 );
[0139] Where M h (x) represents the mean shift vector; n represents the number of first neighboring points; K(·) represents the kernel function; k(·) represents the weight function;
[0140] 4) If the mean shift vector M h(x) < ε (ε is a preset mean shift vector threshold, generally 10 -3 ), or the iteration number reaches a preset first iteration number threshold, the iteration is stopped; otherwise, the mean shift vector of the current shift point x new = x + M h (x) is calculated, and step 3) is returned to continue iteration;
[0141] 5) The modulus of the mean shift vector of the current shift point is taken as the modulus value of the current center point, the center point is moved to the position of the current shift point, and the shift point is deleted; then step 2) is returned to continue iteration until the modulus values of all pixel points are calculated, and the iteration is stopped.
[0142] In a preferred embodiment, after the enhanced terahertz image is divided into a plurality of target regions, the method further comprises:
[0143] For each target region, the range of the target region is expanded by a mature dilation algorithm; wherein the expanded target region contains the original target region and a part of the surrounding background region.
[0144] It should be noted that the dilation algorithm expands the range of the target region outward by n pixels, so that the target region contains more background regions, facilitating threshold segmentation later.
[0145] S4, for each target region, the segmentation threshold of the foreground and the background in the target region is calculated by the maximum inter-class variance method; and according to the segmentation threshold, the foreground region is segmented from the target region as a defect region.
[0146] It should be noted that the threshold segmentation of the target region by the segmentation threshold can obtain a defect region with clearer defect shape information.
[0147] In a preferred embodiment, the calculation of the segmentation threshold of the foreground and the background in the target region by the maximum inter-class variance method comprises:
[0148] According to the gray value of each pixel in the target region, a plurality of gray levels are divided;
[0149] For each gray level, the pixels with a gray value less than or equal to the gray level are taken as the background, and the pixels with a gray value greater than the gray level are taken as the foreground, and the inter-class variance between the foreground and the background is calculated;
[0150] The gray level with the maximum inter-class variance is taken as the segmentation threshold.
[0151] In this embodiment, a plurality of gray levels are divided according to the gray value of each pixel in the target region. It is assumed that a total of L gray levels [1, 2,..., L] are divided, and the number of pixel points corresponding to the gray level l is nl (total pixel points are N).
[0152] For any gray level k, the pixels with gray value less than or equal to the gray level k are regarded as background, and the pixels with gray value greater than the gray level k are regarded as foreground, and there is:
[0153] ω 0,k μ 0,k +ω 1,k μ 1,k =μ T ;
[0154] ω 0,k +ω 1,k =1;
[0155] In the formula, ω 0,k represents the occurrence probability of the background corresponding to the gray level k; μ 0,k represents the average gray of the background corresponding to the gray level k; ω 1,k represents the occurrence probability of the foreground corresponding to the gray level k; μ 1,k represents the average gray of the foreground corresponding to the gray level k; μ T represents the average gray of the entire target region;
[0156] Then the inter-class variance between the foreground and the background is:
[0157] σ 2 =ω 0,k (μ 0,k -μ T ) 2 +ω 1,k (μ 1,k -μ T ) 2 ;
[0158] k is sequentially taken from [1, L], the corresponding inter-class variance is calculated and recorded, and the maximum inter-class variance is taken out, and the k corresponding to the maximum value is the segmentation threshold value.
[0159] S5, input the defect region to the active contour model, so that the active contour model generates a defect edge curve according to the defect region.
[0160] In a preferred embodiment, the generating a defect edge curve according to the defect region comprises:
[0161] extracting an initial edge curve of the defect region;
[0162] repeating the edge curve updating operation until the iteration number reaches a preset second iteration number threshold or the relative change rate of the energy function is less than a preset relative change rate threshold; and taking the current edge curve as the defect edge curve.
[0163] The edge curve updating operation comprises:
[0164] According to the current edge curve, an energy function is constructed, and a current energy function value is calculated; wherein, when the edge curve updating operation is performed for the first time, the current edge curve is the initial edge curve;
[0165] According to the current energy function value and the energy function value of the last iteration, a relative change rate of the energy function is calculated; wherein, when the edge curve updating operation is performed for the first time, the calculation of the relative change rate of the energy function is not performed;
[0166] For each curve pixel point on the current edge curve, eight second neighboring points adjacent to the curve pixel point are determined; the curve pixel point on the current edge curve is replaced by the second neighboring points in turn, and the candidate energy function values of the current edge curve after replacement are calculated in turn; a target pixel point corresponding to the maximum energy function value in the current energy function value and the candidate energy function values corresponding to each second neighboring point is determined; and the curve pixel point is replaced by the target pixel point.
[0167] It should be noted that the second iteration number threshold is generally preset to 100-1000, and the relative change rate threshold is generally preset to 0.01-0.05.
[0168] In another embodiment, the energy function comprises: an internal energy and an external energy;
[0169] The calculation formula of the internal energy is:
[0170]
[0171] In the formula, E int represents the internal energy; s represents a normalized arc length parameter of the edge curve; v(s) represents a parameterized curve function; a represents an elastic coefficient; and b represents a rigid coefficient;
[0172] The calculation formula of the external energy is:
[0173]
[0174] In the formula, represents the gradient amplitude of the defect region;
[0175] The expression of the energy function is:
[0176] E total = E int + γE ext ;
[0177] In the formula, E totaldenotes the energy function value; and γ denotes an external energy weight.
[0178] It should be noted that the value of s is in the range of [0, 1]. v(s) represents the position coordinates of a point on the curve, such as v(s) = (x(s), y(s)). The elastic coefficient α controls the continuity (tension) of the edge curve, prevents the distance between adjacent control points from being too large or broken, and the larger the value, the more the contour tends to keep the distance between points uniform, and is usually taken as 0.01-1.0. The rigidity coefficient β restricts the bending degree (curvature) of the curve, and inhibits the excessive bending or sharp corners of the contour, and the larger the value, the smoother the contour, and is usually taken as 0.1-5.0. Generally, Sobel, Canny, etc. Operator calculation. The external energy weight γ is generally taken as 0.5-2.0.
[0179] In another embodiment, the formula for calculating the relative change rate of the energy function is:
[0180]
[0181] In the formula, Δe j denotes the relative change rate of the energy function of the jth iteration edge curve updating operation; E total,j denotes the energy function value of the jth iteration edge curve updating operation; E total,j-1 denotes the energy function value of the iteration of the (j-1)th iteration edge curve updating operation.
[0182] It should be noted that the present application obtains an original terahertz image, performs enhancement processing on the original terahertz image to obtain an enhanced terahertz image, divides the enhanced terahertz image into a plurality of target regions through a mean shift algorithm, divides a defect region from the target region according to the segmentation threshold, and inputs the defect region into an active contour model to enable the active contour model to generate a defect edge curve according to the defect region. The present application can automatically generate a defect region without manual designation, reduces human error, and saves manpower; and the present application combines inter-class variance calculation to perform threshold segmentation on the target region, and optimizes the convergence effect of the concave region and the inflection point position in the defect image.
[0183] In summary, the present application can effectively solve the problem of poor defect edge extraction effect in the prior art.
[0184] As Figure 3 shown, on the basis of the above method embodiment, an embodiment of the present application provides a defect edge extraction device based on a terahertz image, which comprises an image acquisition module, an image enhancement module, an image segmentation module, a defect region extraction module, and a defect edge curve extraction module.
[0185] The image acquisition module is used to acquire an original terahertz image.
[0186] The image enhancement module is configured to perform enhancement processing on the original terahertz image to obtain an enhanced terahertz image.
[0187] The image segmentation module is configured to segment the enhanced terahertz image into a plurality of target regions by using a mean shift algorithm.
[0188] The defect region extraction module is configured to, for each target region, calculate a segmentation threshold of a foreground and a background in the target region by using an OTSU algorithm, and segment a foreground region from the target region as a defect region according to the segmentation threshold.
[0189] The defect edge curve extraction module is configured to input the defect region into an active contour model, so that the active contour model generates a defect edge curve according to the defect region.
[0190] It can be understood that the above device item embodiments correspond to the method item embodiments of the present application, and can realize the defect edge extraction method based on a terahertz image provided by any one of the above method item embodiments.
[0191] It should be noted that the device embodiments described above are only schematic, and some or all of the modules can be selected to achieve the purpose of the present embodiment. In addition, in the device embodiment provided by the present application, the connection relationship between the modules indicates that there is a communication connection between them, which can be realized as one or more communication buses or signal lines. Those skilled in the art can understand and implement it without creative labor.
[0192] On the basis of the above method item embodiments, another embodiment of the present application provides a terminal device, which comprises a processor, a memory and a computer program stored in the memory and configured to be executed by the processor, and when the processor executes the computer program, the method for extracting a defect edge based on a terahertz image according to any one of the embodiments of the present application is realized.
[0193] For example, in this embodiment, the computer program can be divided into one or more modules, which are stored in the memory and executed by the processor to complete the present application. The one or more modules can be a series of computer program instruction segments capable of completing a specific function, which are used to describe the execution process of the computer program in the terminal device.
[0194] The terminal device can be a desktop computer, a notebook computer, a palm computer and a cloud server, etc. The terminal device can include, but is not limited to, a processor and a memory.
[0195] The processor can be a central processing unit (CPU), and can also be other general-purpose processors, a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware component, etc. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor and the like, which is a control center of the terminal device and connects all parts of the terminal device through various interfaces and lines.
[0196] On the basis of the above-mentioned method embodiment, another embodiment of the present application provides a computer readable storage medium, including a stored computer program, wherein when the computer program runs, the device where the computer readable storage medium is located executes the terahertz image-based defect edge extraction method described in any one of the above-mentioned method embodiments of the present application.
[0197] The modules / units integrated in the device / terminal equipment, if realized in the form of software function units and sold or used as independent products, can be stored in a computer readable storage medium. Based on this understanding, all or part of the processes in the above-mentioned embodiment methods can also be completed by a computer program instructing related hardware, and the computer program can be stored in a computer readable storage medium. When the processor executes the computer program, the steps of the above-mentioned various method embodiments can be implemented. The computer program includes computer program code, which can be in the form of source code, object code, executable file or some intermediate form, etc. The computer readable medium can include any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signal, telecommunication signal and software distribution medium, etc.
[0198] The above-mentioned is the preferred embodiment of the present application, and it should be pointed out that for those skilled in the art, without departing from the principle of the present application, a number of improvements and refinements can be made, and these improvements and refinements are also considered to be within the protection scope of the present application.
Claims
1. A defect edge extraction method based on a terahertz image, characterized by, The method comprises the following steps: acquiring an original terahertz image; performing enhancement processing on the original terahertz image to obtain an enhanced terahertz image; segmenting the enhanced terahertz image into a plurality of target regions by using a mean shift algorithm; for each target region, calculating a segmentation threshold of foreground and background in the target region by using an OTSU method, and segmenting a foreground region from the target region as a defect region according to the segmentation threshold; inputting the defect region into an active contour model to make the active contour model generate a defect edge curve according to the defect region.
2. The terahertz image-based defect edge extraction method of claim 1, wherein, The method of performing enhancement processing on the original terahertz image to obtain an enhanced terahertz image comprises the following steps: inputting the original terahertz image into a trained image enhancement model to make a generator in the image enhancement model generate a preliminary enhanced terahertz image according to the original terahertz image; performing median filtering processing on the preliminary enhanced terahertz image to obtain the enhanced terahertz image. The image enhancement model is a conditional generative adversarial network, which comprises a generator and a discriminator. The training method of the image enhancement model comprises the following steps: acquiring a plurality of original terahertz image samples, performing non-local mean filtering processing and histogram equalization processing on the original terahertz image samples to obtain real terahertz image samples; performing contrast reduction and resolution reduction processing on each real terahertz image sample to generate a corresponding initial terahertz image sample; inputting each real terahertz image sample and the corresponding initial terahertz image sample into the image enhancement model to make the image enhancement model generate an enhanced terahertz image sample according to the initial terahertz image sample by using the generator, calculate a first probability that the enhanced terahertz image sample is real and a second probability that the real terahertz image sample is real by using the discriminator, calculate a discriminator loss function according to the first probability and the second probability, update parameters of the discriminator by using a back propagation algorithm according to the discriminator loss function, and after the discriminator is updated for a preset number of times, calculate a third probability that the enhanced terahertz image sample is real by using the discriminator again, calculate a generator loss function according to the third probability, and update parameters of the generator by using a back propagation algorithm according to the generator loss function.
3. The terahertz image-based defect edge extraction method of claim 2, wherein, The generator is sequentially composed of a resolution reduction module, a feature extraction module and a resolution restoration module. The feature extraction module is sequentially composed of a first convolutional layer, a second convolutional layer, a third convolutional layer, a scale normalization layer and a ReLU activation layer, wherein the output of the first convolutional layer and the output of the third convolutional layer are cascaded through a skip connection layer.
4. The terahertz image-based defect edge extraction method of claim 1, wherein, The method of segmenting the enhanced terahertz image into a plurality of target regions by using a mean shift algorithm comprises the following steps: randomly selecting a pixel point in the enhanced terahertz image as an initial center point; repeating a center point moving operation until the modulus of each pixel point in the enhanced terahertz image is obtained, and dividing pixel points with the same modulus into the same target region to obtain a plurality of target regions; The center point moving operation comprises the following steps: setting a drift point at a current center point position; wherein the current center point is the initial center point when the center point moving operation is performed for the first time; repeating the drift point moving operation until the iteration number of the drift point moving operation reaches a preset first iteration number threshold or the mean value drift vector of the current drift point is less than a preset mean value drift vector threshold; taking the modulus of the mean value drift vector of the current drift point as the modulus value of the current center point; moving the center point to the position of the current drift point and deleting the drift point; the drift point moving operation comprises: determining all first neighboring points within a certain distance around the current drift point; calculating the mean value drift vector of the current drift point according to the positions of all the first neighboring points; moving the drift point according to the mean value drift vector of the current drift point.
5. The terahertz image-based defect edge extraction method of claim 1, wherein, after the enhanced terahertz image is segmented into a plurality of target regions, further comprising: for each target region, expanding the range of the target region by a mature inflation algorithm; wherein the expanded target region contains the original target region and a part of the surrounding background region.
6. The terahertz image-based defect edge extraction method of claim 1, wherein, the method for calculating the segmentation threshold of the foreground and the background in the target region by the maximum inter-class variance method comprises: dividing a plurality of gray levels according to the gray values of each pixel in the target region; for each gray level, taking the pixels with gray values less than or equal to the gray level as the background and the pixels with gray values greater than the gray level as the foreground, and calculating the inter-class variance between the foreground and the background; taking the gray level with the maximum inter-class variance as the segmentation threshold.
7. The terahertz image-based defect edge extraction method of claim 1, wherein, the method for generating a defect edge curve according to the defect region comprises: extracting an initial edge curve of the defect region; repeating the edge curve updating operation until the iteration number reaches a preset second iteration number threshold or the relative change rate of the energy function is less than a preset relative change rate threshold; taking the current edge curve as the defect edge curve; wherein the edge curve updating operation comprises: constructing an energy function according to the current edge curve and calculating the current energy function value; wherein the current edge curve is the initial edge curve when the edge curve updating operation is performed for the first time; calculating the relative change rate of the energy function according to the current energy function value and the energy function value of the last iteration; wherein the calculation of the relative change rate of the energy function is not performed when the edge curve updating operation is performed for the first time; for each curve pixel point on the current edge curve, determining eight second neighboring points adjacent to the curve pixel point; replacing the curve pixel point on the current edge curve with the second neighboring points in turn, calculating the candidate energy function value of the current edge curve after replacement in turn; determining the target pixel point corresponding to the maximum energy function value in the current energy function value and the candidate energy function value corresponding to each second neighboring point; replacing the curve pixel point with the target pixel point.
8. A terahertz image-based defect edge extraction apparatus, characterized by comprising: comprising: an image acquisition module, an image enhancement module, an image segmentation module, a defect region extraction module and a defect edge curve extraction module; the image acquisition module is used to acquire an original terahertz image; The image enhancement module is configured to perform enhancement processing on the original terahertz image to obtain an enhanced terahertz image. The image segmentation module is configured to segment the enhanced terahertz image into a plurality of target regions by using a mean shift algorithm. The defect region extraction module is configured to calculate, for each target region, a segmentation threshold of a foreground and a background in the target region by using an OTSU algorithm. According to the segmentation threshold, a foreground region is segmented from the target region as a defect region. The defect edge curve extraction module is configured to input the defect region into an active contour model, so that the active contour model generates a defect edge curve according to the defect region.
9. A terminal device, comprising: A computer program product including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor implements the terahertz image-based defect edge extraction method according to any one of claims 1-7 when executing the computer program.
10. A computer-readable storage medium, characterized in that, The computer program product includes: A stored computer program, wherein the computer program controls a device in which the computer readable storage medium is located to perform the terahertz image-based defect edge extraction method according to any one of claims 1-7 when the computer program is running.
Citation Information
Cited By
Chip unmarked detection method and system
CN121431429A
Board card defect detection method and system based on image processing
CN121982021A
A board defect detection method and system based on image processing
CN121982021B
