Gear surface defect detection method based on quantum contrast and superpixel clustering algorithm
Through quantum comparison and superpixel clustering algorithms, the problem of lack of labeled data in industrial scenarios is solved, and fast and accurate gear surface defect detection is achieved, improving detection efficiency and accuracy.
Patent Information
- Application Number
- CN202510185468.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-19
- Publication Date
- 2025-06-10
AI Technical Summary
The existing gear surface defect detection method based on deep learning requires labeling data, which makes it difficult to improve detection efficiency and accuracy under the conditions of lack of labeling in industrial scenarios.
Using detection methods based on quantum comparison and superpixel clustering algorithms, pre-segmented images are generated through superpixel clustering algorithms, features are extracted using direction gradient histograms, combined with SimCLR comparison learning framework and NT-Xent loss function optimization feature representation, and clustering iteration is performed using fast forward quantum optimization algorithm.
It realizes the rapid and accurate detection of gear surface defects in the absence of labeled data, reduces the leakage detection rate, improves segmentation accuracy and detection efficiency, and is suitable for assembly line detection in industrial scenarios.
Smart Images

Figure CN120125525A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of image recognition, and particularly relates to a gear surface defect detection method based on quantum contrast and superpixel clustering algorithms. Background Art
[0002] Quality inspection is a crucial link in the gear production line. During the production process of gear blanks, due to the influence of factors such as process, equipment, or environment, various defects may occur in the products, such as cracks, spots, black cores, and bubbles. However, many factories still rely on manual inspection for gear defect detection. Since this method completely depends on the judgment of the human eye and the experience of inspectors, it is easily affected by subjective factors, resulting in slow detection speed and low accuracy, which does not meet the requirements of modern automated production.
[0003] In the prior art, in order to overcome the defects of manual inspection, a detection method based on deep learning has been proposed. Chinese Patent CN115953386A discloses a lightweight gear surface defect detection method based on MSTA - YOLOv5, which realizes the detection and automatic sorting of gear surface defects and can improve the detection efficiency of gear surface defect detection. Chinese Patent CN117173098A discloses a gear surface defect detection method based on RDMS, which can eliminate the difficulty of manually collecting and annotating defect samples by only using normal gear surface images during the training process. At the same time, it has high detection accuracy during the detection process and can provide pixel - level defect localization, reducing the training threshold and improving the usage efficiency, with strong generalization ability.
[0004] Although the above - mentioned method of using deep learning for gear defect detection can improve the detection efficiency and accuracy, the detection method based on deep learning must require annotation and is helpless in the case of lacking annotated gear surface defect data in industrial scenarios. Summary of the Invention
[0005] In order to solve the above - mentioned technical problems, the present application proposes the following technical solutions:
[0006] In a first aspect, an embodiment of the present application provides a gear surface defect detection method based on quantum contrast and superpixel clustering algorithms, including:
[0007] Collecting gear images to be detected and performing pre - processing;
[0008] Generating a pre - segmented image through a superpixel clustering algorithm for the pre - processed data to produce superpixel regions;
[0009] Using the histogram of oriented gradients method to extract features for each superpixel block;
[0010] Create positive and negative sample pairs for each superpixel block using cosine similarity, train the SimCLR contrastive learning framework, and use the contrastive loss function NT-Xent to optimize the superpixel feature representation, so as to reduce the feature distance of positive sample pairs and increase the feature distance of negative sample pairs;
[0011] Use the fast-forward quantum optimization algorithm to perform clustering iteration on the optimized superpixel blocks.
[0012] In a possible implementation, the acquisition and preprocessing of the gear images to be detected include:
[0013] Use a high-precision camera to capture the surface defect images of the gears to be detected;
[0014] Perform down-frame clipping on the surface defect images to form a dataset;
[0015] Divide the dataset into a training set and a test set. For the image data in the dataset, first perform grayscale processing, and then use gamma correction to adjust the image contrast to reduce the impact of uneven illumination on the image.
[0016] In a possible implementation, the generation of a pre-segmented image from the preprocessed data through a superpixel clustering algorithm to generate superpixel regions includes:
[0017] Distribute K superpixel centers to the pixel points of the image;
[0018] Within the 3×3 range centered on K, move the superpixel center to the point with the smallest gradient among these 9 points;
[0019] Take an array label to save each pixel point and its corresponding superpixel, and the dis array to save the distance from the pixel point to the corresponding superpixel center;
[0020] For each superpixel center x, if the distance from the point to the superpixel center x is less than the distance from this point to the superpixel center it originally belonged to, it means that this point belongs to superpixel x, and update dis and label;
[0021] For each superpixel center, recalculate its position.
[0022] In a possible implementation, the calculation formula for the image gradient is:
[0023] G(x,y) = ||I(x + 1,y) - I(x - 1,y)|| 2 + ||I(x,y + 1) - I(x,y - 1)|| 2
[0024] Where I(x, y) is the lab vector fitting the pixel position coordinates (x, y), and ||.|| is the absolute value.
[0025] In a possible implementation, the formula for calculating the distance from a pixel point to the corresponding superpixel center is:
[0026]
[0027] where d c is the color distance, d s is the spatial distance, dis is the distance between pixel point i and cluster center k, is the maximum distance within the class, and m is a fixed constant with a value range of [1, 40].
[0028] In a possible implementation, the use of the Histogram of Oriented Gradients method to extract features from each superpixel block includes:
[0029] Calculating the gradient histogram of each superpixel block, dividing the angle range into N parts, with each 180 / N degrees as a unit, and accumulating the gradient values corresponding to all pixels in each part to obtain N values, which form an array;
[0030] Subsequently, using a sliding window to normalize the gradient histogram;
[0031] Finally, calculating the feature vector of each superpixel block.
[0032] In a possible implementation, using cosine similarity to create positive and negative sample pairs for each superpixel block, training the SimCLR contrastive learning framework, and using the contrastive loss function NT-Xent to optimize the superpixel feature representation, so that the feature distance of positive sample pairs is reduced and the feature distance of negative sample pairs is enlarged, including:
[0033] For the feature vectors of every two superpixel blocks, the cosine similarity is selected to calculate the similarity between Zi and Zj. Those with high similarity form positive sample pairs, and those with low similarity form negative sample pairs. The cosine similarity calculation formula is as follows:
[0034]
[0035] Using NT-Xent as the loss function for positive pair examples, making superpixels of the same class more similar in the feature space and superpixels of different classes farther apart. The loss function is as follows:
[0036]
[0037] where: u and v represent the feature vectors of the superpixel blocks, ∥u∥ represents the magnitude of the feature vector u, ∥v∥ represents the magnitude of the feature vector v, τ is the temperature parameter, Zi and Z j are the feature vectors of positive sample pairs, k is an index with a value range of (1, 2N), and Z k is the feature vector of all other sample pairs except Z i itself. By performing an exponential operation and summing the similarities between Z i and Z k , a normalization term is constructed.
[0038] In a possible implementation, the use of the fast-forward quantum optimization algorithm to perform clustering iteration on the optimized superpixel blocks includes:
[0039] After contrastive learning training, the optimized feature vectors of each superpixel block are obtained, and the values T k =[l k ,a k ,x k ,y k T of the feature vectors of every two superpixel blocks are obtained, and at the same time, a set of gradient values G ld ={P1, P2,..., Pn};
[0040] Initialize each quantum in the search space: Q k (e)=φ·Q1 k (e)+(1 - φ)·Q2 k (e), where Q k (e) represents the kth quantum with one e(poch), k = 1, 2, 3..., q, q represents the total number of quanta in Q, Q1 k (e) and Q2 k (e) are the two wave functions of the kth quantum, e(poch) represents a specific time point within the period, and kth represents the kth quantum;
[0041] Obtain the quantum position from Q k (e) and denote it as L k (e), and the formula is as follows:
[0042] Assume that each quantum can move in the quantum system, and calculate the motion performance of the quantum and denote it as M K (e), and the formula is as follows: where m f is the quantum motion factor, and its value range is [0, 1];
[0043] Obtain the displacement of each quantum, and assign the initial cluster center set to each displacement. The displacement accompanied by each quantum in the quantum system can be determined by L k (e) and Mk (e) is defined as D k (e) represents Q k The displacement of (e) is given by the formula: D K (e) = 2·|L K (e) - M K (e)|;
[0044] The Euclidean distance calculation, gray value assignment, and cluster center fitness evaluation are repeated to determine the fitness value. If a better fitness value exists, it is updated until the optimal solution for D K (e);
[0045] Enhance the quantum search range. Each quantum adjusts its corresponding M k (e) to obtain the enhanced search range M k (e + 1);
[0046] Through the enhanced search range M k (e + 1) the D k (e) obtains the updated displacement D k (e + 1), with the formula: D k (e + 1) = D k (e) + M k (e + 1);
[0047] Gradually increase the epoch until the cluster center stops changing or the algorithm reaches the maximum number of epochs. Reshape the number of cluster gray values into a segmented image.
[0048] In a possible implementation, the φ is a complex number, represented as φ = a + ib, where a and b are real numbers in [0, 1], and i is the imaginary unit In the representation of complex numbers, -1 represents a 180-degree rotation of the kth quantum around the origin, and i represents a 90-degree counterclockwise rotation of the kth quantum in the positive direction. The absolute value of φ is used to initialize the quantum in the search space during the calculation, defined as
[0049] Q1 k (e) and Q2 k (e) can be defined as:
[0050] Q1 K (e) = {G UB + r 1 ·(G UB - G LB )}
[0051] Q2 K (e) = {G UB + r 2 ·(GUB -G LB )}
[0052] where r 1 and r 2 represent two different random functions, and G UB and G LB represent the upper and lower bounds of the linear constraint, respectively.
[0053] In a possible implementation, the enhanced search range M k (e + 1) is calculated as follows:
[0054] M k (e + 1) = M 1 + M 2 + M 3
[0055] M 1 , M 2 , M 3 are respectively expressed as:
[0056] M 1 = α · M k (e)
[0057] M 2 = ln(1 / m f ) · r 3 · [pBD k (e) - D k (e)]
[0058] M 3 = ln(1 / m f ) · r 4 · [gBD(e) - D k (e)]
[0059] where: α is the quantum acceleration factor, defined as follows: e = 1, 2,..., E, where E represents the maximum number of epochs set by the algorithm, and α max and α min take values in [0.1, 0.9], pBD k (e) is the best displacement obtained since the first epoch of the kth quantum, gBD(e) is the best displacement among all displacements obtained in all epochs of the kth quantum, and r 3 and r 4 represent two different random functions, taking values in [0, 1] respectively.
[0060] In the embodiments of the present application, the proposed quantum contrast superpixel clustering algorithm can provide fast and accurate detection, can be applied to machines, and can well meet the requirements of the assembly line in industrial scenarios. In the case of a lack of annotation for defect detection in industrial scenarios, it can greatly reduce the missed detection rate of the existing model for gear surface defect segmentation, improve the segmentation accuracy, greatly improve the accuracy of machine inspection in industrial scenarios, and improve the detection efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0061] Figure 1 FIG. is a schematic flowchart of a gear surface defect detection method based on quantum contrast and superpixel clustering algorithm provided by an embodiment of the present application;
[0062] Figure 2 FIG. is a schematic flowchart of image preprocessing provided by an embodiment of the present application;
[0063] Figure 3 FIG. is a photo of a gear taken by a high-precision camera provided by an embodiment of the present application;
[0064] Figure 4 FIG. is a comparison diagram of gear image processing provided by an embodiment of the present application;
[0065] Figure 5 FIG. is a schematic flowchart of superpixel clustering provided by an embodiment of the present application;
[0066] Figure 6 FIG. is a schematic flowchart of contrastive learning model training provided by an embodiment of the present application;
[0067] Figure 7 FIG. is a schematic flowchart of a fast-forward quantum optimization clustering algorithm provided by an embodiment of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0068] The following describes the present solution in conjunction with the accompanying drawings and specific embodiments.
[0069] Referring to Figure 1 , the gear surface defect detection method based on quantum contrast and superpixel clustering algorithm provided in this embodiment includes:
[0070] S101, collect gear images to be detected and perform preprocessing.
[0071] The specific process is as shown in Figure 2 . In an industrial scenario, a high-precision camera is used to capture gear surface defects, and then these photos are subjected to frame dropping and cropping processing to form a data set. Refer to Figure 3It is a photo of a gear taken by a high-precision camera. For the dataset, the training set and the test set are first divided. The training set consists of 1525 defect images including pores, cracks, dirt, wear, etc., and the test set consists of 475 common defect images of various types. For the input image data, grayscale processing is first performed, and then gamma correction is used to adjust the image contrast to reduce the impact of uneven illumination on the image.
[0072] As Figure 4 shown, (a) is the gear image after grayscale processing, and (b) is the image after gamma correction corresponding to (a). It can be seen that the brightness of the gear in Figure (b) increases after adjusting the image contrast by gamma correction compared to (a). (a) is another group of gear images after grayscale processing, and (d) is the image after gamma correction corresponding to (c). It can be seen that there is an impact of light on the gear in Figure (a) after grayscale processing, and the brightness increases after adjusting the image contrast by gamma correction, correspondingly reducing the impact of uneven illumination on the image.
[0073] S102: Generate a pre-segmented image from the preprocessed data through a superpixel clustering algorithm to produce superpixel regions.
[0074] The specific process is as Figure 5 shown. In this embodiment, K superpixel centers are distributed to the pixel points of the image to implement seeding. Let the number of image pixels be N and the number of superpixels be K, then the size of the superpixel is N / K, and the distance between the clustering centers is Let the clustering center be C k =[l k ,a k ,b k ,x k ,y k T .
[0075] Fine-tune the position of the seeds. Within the 3×3 range centered on K, move the superpixel center to the point with the minimum gradient among these 9 points. This is to avoid the superpixel points falling on noise or boundaries. The calculation formula for the image gradient is as follows:
[0076] G(x,y)=||I(x + 1,y)-I(x - 1,y)|| 2 +||I(x,y + 1)-I(x,y - 1)|| 2
[0077] where I(x,y) is the lab vector corresponding to the pixel position coordinates (x,y), and ||.|| is the absolute value, thus considering both color and intensity information simultaneously.
[0078] Initialize the data. Take an array label to save which superpixel each pixel belongs to, and use the dis array to save the distance from the pixel to the center of the corresponding superpixel, that is, the distance to the center of the superpixel it belongs to. For each superpixel center x, if the distance from the point to the superpixel center x is less than the distance from this point to the center of the superpixel it originally belonged to, it means this point belongs to superpixel x, and update dis and label.
[0079] The distance metrics of the superpixel clustering algorithm include color distance and spatial distance. The distance calculation formula is as follows:
[0080]
[0081] Among them, d c is the color distance, d s is the spatial distance, dis is the distance between pixel i and clustering center k, is the maximum distance within the class, and m is a fixed constant with a value range of [1, 40].
[0082] Finally, for each superpixel center, recalculate its position.
[0083] S103. Use the Histogram of Oriented Gradients method to extract features for each superpixel block.
[0084] Calculate the gradient histogram of each superpixel block. Divide the angle range into N parts, with each 180 / N degrees as a unit. The gradient values corresponding to all pixels in each part are accumulated to obtain N values, which form an array. Subsequently, use a sliding window to normalize the gradient histogram, and finally calculate the feature vector of each superpixel block.
[0085] In this embodiment, the angle range is divided into 9 parts, with each 20 degrees as a unit. The gradient values corresponding to all pixels in each part are accumulated to obtain 9 values, which form an array. Subsequently, use a 2×2 sliding window to normalize the gradient histogram.
[0086] S104. Use cosine similarity to create positive and negative sample pairs for each superpixel block, train the SimCLR contrastive learning framework, and use the contrastive loss function NT-Xent to optimize the superpixel feature representation, so as to reduce the feature distance of positive sample pairs and increase the feature distance of negative sample pairs.
[0087] In this embodiment, as Figure 6 shown, for the feature vectors of every two superpixel blocks, select cosine similarity to calculate the similarity of Z i and Z j . The superpixel blocks with high similarity form positive sample pairs, and those with low similarity form negative sample pairs. The cosine similarity calculation formula is as follows:
[0088]
[0089] Use NT-Xent (Normalized Temperature-scaled Cross Entropy Loss Function) as the loss function for positive example pairs. Minimizing the calculation of this loss function corresponds to maximizing the probability that two images are similar. This makes superpixels of the same class more similar in the feature space while superpixels of different classes are farther apart. The loss function is as follows:
[0090]
[0091] where: u and v represent the feature vectors of superpixel blocks, ∥u∥ represents the magnitude of feature vector u, ∥v∥ represents the magnitude of feature vector v, τ is the temperature parameter, Z i and Z j are the feature vectors of positive sample pairs, k is an index with a value range of (1, 2N), Z k is the feature vector of all other sample pairs except Z i itself. By exponentiating and summing the similarities built from Z i and Z k , a normalization term is constructed.
[0092] S105. Use the fast-forward quantum optimization algorithm to perform clustering iteration on the optimized superpixel blocks.
[0093] See Figure 7 , after contrastive learning training, obtain the optimized feature vectors of each superpixel block, and get the values T k = [l k , a k , b k , x k , y k T , and at the same time obtain a set of gradient values G ld = {P1, P2,..., Pn}.
[0094] Initialize each quantum in the search space. Assume that the solutions to the optimization problem are scattered in the quantum system, and allow each quantum to move to search for solutions in the system. The quantum system is defined by initializing each quantum in the search space using the following Schrödinger equation:
[0095] Q k (e) = φ · Q1 k (e) + (1 - φ) · Q2 k (e)
[0096] where Q k (e) represents the kth quantum with one e (epoch), k = 1, 2, 3..., q, q represents the total number of quanta in Q, Q1k (e) and Q2 k (e) are the two wave functions of the kth quantum. e (epoch) represents a specific time point within a period, and kth represents the kth quantum. φ is a complex number, expressed as φ = a + ib, where a and b are real numbers in [0, 1], and i is the imaginary unit In the representation of complex numbers, -1 represents a 180-degree rotation of the kth quantum around the origin, and i represents a 90-degree rotation of the kth quantum in the counterclockwise direction on the positive side. Since it is impossible to directly use the complex number φ to initialize the quantum in the search space, the absolute value of φ is used to initialize the quantum in the search space during the calculation process, defined as
[0097] Q1 k (e) and Q2 k (e) can be defined as:
[0098] Q1 K (e) = {G UB +r 1 ·(G UB ―G LB )}
[0099] Q2 K (e) = {G UB +r 2 ·(G UB ―G LB )}
[0100] where r 1 and r 2 represent two different random functions, and G UB and G LB represent the upper and lower limits of the linear constraint respectively.
[0101] Obtain the displacement of each quantum. Assume that for each quantum, there must be a position for it in the quantum system. Obtain the position from Q k (e) and denote it as L k (e), and the formula is as follows:
[0102]
[0103] Calculate the motion performance of the quantum, enabling each quantum to move in the quantum system. The motion performance of Q k (e) is denoted as M k (e), and the formula is as follows:
[0104]
[0105] m f is the quantum motion factor, and its value range is [0, 1].[[]]END]]
[0106] Assign the initial cluster center set to each displacement. The displacement associated with each quantum in the quantum system can be defined by L k (e) and M k (e), and is denoted by D k (e) for the displacement of Q k (e). The formula is as follows: D K (e) = 2·|L K (e) − M K (e)|.
[0107] Repeat the Euclidean distance calculation, gray value assignment, and cluster center adaptability evaluation to determine the fitness value. If there is a better fitness value, update it until the optimal D K (e) is determined.
[0108] Enhance the quantum search range. Each quantum obtains the enhanced search range M k (e) by adjusting its corresponding M k (e) to obtain the enhanced search range M k (e + 1). The formula for the enhanced search range M
[0109] M k (e + 1) = M 1 + M 2 + M 3
[0110] M 1 , M 2 , M 3 are respectively expressed as:
[0111] M 1 = α·M k (e)
[0112] M 2 = ln(1 / m f )·r 3 ·[pBD k (e) − D k (e)]
[0113] M 3 = ln(1 / m f )·r 4 ·[gBD(e) − D k (e)]
[0114] Among them: α is the quantum acceleration factor, defined as follows: e = 1, 2,..., E, where E represents the maximum number of epochs set by the algorithm, α max and α minTake values in [0.1, 0.9], pBD k (e) is the best displacement obtained from the first epoch of the kth quantum, gBD(e) is the best displacement among all displacements obtained in all epochs of the kth quantum, r 3 and r 4 represent two different random functions, taking values in [0, 1] respectively.
[0115] Through the enhanced search range M k (e + 1) the D k (e) to obtain the updated displacement D k (e + 1), the formula is: D k (e + 1) = D k (e) + M k (e + 1). Gradually increase the epoch until the cluster center stops changing or the algorithm reaches the maximum number of epochs, and reshape the number of cluster gray values into a segmented image.
[0116] In the embodiments of the present application, "at least one" means one or more, and "a plurality" means two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships can exist. For example, A and / or B can represent the situation of A existing alone, A and B existing simultaneously, and B existing alone. Where A and B can be singular or plural. The character " / " generally represents an "or" relationship between the associated objects before and after. "At least one of the following" and its similar expressions refer to any combination of these items, including any combination of single items or plural items. For example, at least one of a, b, and c can represent: a, b, c, a - b, a - c, b - c, or a - b - c, where a, b, and c can be single or multiple.
[0117] As described above, only the specific implementation manners of the present application are concerned. Any person skilled in the art within the technical scope disclosed in the present application can easily think of changes or substitutions, which should all be covered within the protection scope of the present application. The protection scope of the present application shall be subject to the protection scope of the claims.
Claims
1. A gear surface defect detection method based on quantum contrast and superpixel clustering algorithm, characterized in that: include: Collect the gear images that need to be inspected and perform preprocessing; The pre-processed data is subjected to a superpixel clustering algorithm to generate a pre-segmented image and a superpixel region; The feature extraction of each superpixel block is performed using the histogram of oriented gradients method; Use cosine similarity to create positive and negative sample pairs for each superpixel block, train the SimCLR contrastive learning framework, and use the contrastive loss function NT-Xent to optimize the superpixel feature representation, so that the feature distance between positive sample pairs is reduced and the feature distance between negative sample pairs is increased; The optimized superpixel blocks are clustered iteratively using the fast-forward quantum optimization algorithm.
2. The gear surface defect detection method based on quantum contrast and superpixel clustering algorithm according to claim 1 is characterized in that: The collecting of the gear image to be inspected and preprocessing thereof include: Use a high-precision camera to capture images of gear surface defects that need to be inspected; The surface defect image is subjected to frame trimming processing to form a data set; The data set is divided into a training set and a test set. The image data in the data set is firstly grayscale processed, and then the image contrast is adjusted using gamma correction to reduce the impact of uneven illumination on the image.
3. The gear surface defect detection method based on quantum contrast and superpixel clustering algorithm according to claim 1 is characterized in that: The pre-processed data is subjected to a superpixel clustering algorithm to generate a pre-segmented image to generate a superpixel region, including: Distribute K superpixel centers to the pixels of the image; Within the 3×3 range centered on K, move the superpixel center to the point with the smallest gradient among these 9 points; Take an array label to save each pixel and the corresponding superpixel, and the dis array to save the distance from the pixel to the corresponding superpixel center; For each superpixel center x, if the distance from the point to the superpixel center x is less than the distance from the point to the superpixel center to which it originally belongs, it means that the point belongs to the superpixel x, and dis and label are updated; For each superpixel center, recalculate its position.
4. The gear surface defect detection method based on quantum contrast and superpixel clustering algorithm according to claim 3 is characterized in that: The calculation formula of image gradient is: G(x,y)=||I(x+1,y)-I(x-1,y)|| 2 +||I(x,y+1)-I(x,y-1)|| 2 Where I(x,y) is the lab vector that fits the pixel position coordinates (x,y), and ||.|| is the absolute value.
5. The gear surface defect detection method based on quantum contrast and superpixel clustering algorithm according to claim 3 is characterized in that: The distance calculation formula from a pixel to the corresponding superpixel center is: Among them, d c is the color distance, d s is the spatial distance, dis is the distance between pixel i and cluster center k, is the maximum distance within the class, and m is a fixed constant ranging from [1,40].
6. The gear surface defect detection method based on quantum contrast and superpixel clustering algorithm according to claim 1 is characterized in that: The method of using the directional gradient histogram to extract features from each super pixel block includes: Calculate the gradient histogram of each superpixel block, divide the angle range into N parts, one unit for every 180 / N degrees, and accumulate the gradient values corresponding to all pixels in each part to obtain N values to form an array; The gradient histogram is then normalized using a sliding window; Finally, the feature vector of each superpixel block is calculated.
7. The gear surface defect detection method based on quantum contrast and superpixel clustering algorithm according to claim 1 is characterized in that: The method uses cosine similarity to create positive and negative sample pairs for each superpixel block, trains the SimCLR contrast learning framework, and uses the contrast loss function NT-Xent to optimize the superpixel feature representation, so that the feature distance between positive sample pairs is reduced and the feature distance between negative sample pairs is increased, including: For the feature vectors of every two superpixel blocks, cosine similarity is used to calculate Z i and Z j The similarity of the two samples is as follows: the positive sample pairs are composed of the samples with high similarity, and the negative sample pairs are composed of the samples with low similarity. The cosine similarity calculation formula is as follows: Using NT-Xent as the loss function for the positive example makes superpixels of the same type more similar in the feature space and superpixels of different types farther apart. The loss function is as follows: Among them: u and v represent the feature vectors of the superpixel block, ∥u∥ represents the size of the feature vector u, ∥v∥ represents the size of the feature vector v, τ is the temperature parameter, Z i and Z j is the feature vector of the positive sample pair, k is an index ranging from (1, 2N), Z k Except Z i The feature vectors of all sample pairs other than itself are obtained by i and Z k The similarities constructed are exponentially calculated and summed to construct a normalized term.
8. The gear surface defect detection method based on quantum contrast and superpixel clustering algorithm according to claim 1 is characterized in that: The method of using the fast-forward quantum optimization algorithm to iterate clustering of the optimized superpixel blocks includes: After contrast learning and training, the optimized feature vector of each superpixel block is obtained, and the value T of the feature vector of every two superpixel blocks is obtained. k =[l k ,a k ,x k ,y k ] T , and obtain a set of gradient values G ld = {P1, P2, ..., Pn}; Initialize each quantum in the search space: Q k (e) = φ·Q1 k (e)+(1-φ)·Q2 k (e) where Q k (e) represents the kth quantum with an e(poch), k = 1, 2, 3..., q, q represents the total number of quanta in Q, Q1 k (e) and Q2 k (e) are the two wave functions of the kth quantum, e(poch) represents a specific time point in the cycle, and kth represents the kth quantum; By Q k (e) Obtain the quantum position and record it as L k (e), the formula is as follows: Assume that each quantum can move in the quantum system, and calculate the movement performance of the quantum as M K (e), the formula is as follows: Where m f is the quantum motion factor, with a value range of [0,1]; Obtain the displacement of each quantum and assign the initial cluster center set to each displacement. The displacement associated with each quantum in the quantum system can be expressed by L k (e) and M k (e) Definition, using D k (e) indicates Q k (e) displacement, the formula is as follows: D K (e) = 2·|L K (e)―M K (e)|; Repeat the Euclidean distance calculation, gray value assignment, and cluster center adaptability evaluation to determine the fitness value. If a better fitness value exists, update it until the optimal solution D is determined. K (e); To enhance the quantum search range, each quantum is adjusted by adjusting its corresponding M k (e) to obtain the enhanced search range M k (e+1); By enhancing the search range M k (e+1)D k (e) Get the updated displacement D k (e+1), the formula is: D k (e+1)=D k (e)+M k (e+1); Gradually increase the epoch until the cluster center stops changing or the algorithm reaches the maximum number of epochs, reshaping the number of cluster grayscale values into a segmented image.
9. The gear surface defect detection method based on quantum contrast and superpixel clustering algorithm according to claim 8 is characterized in that: The φ is a complex number, represented by φ=a+ib, where a and b are real numbers in [0,1], and i is an imaginary unit. In the complex number representation, -1 means that the kth quantum rotates 180 degrees around the origin, i means that the kth quantum rotates 90 degrees in the counterclockwise direction in the front direction. During the calculation process, the absolute value of φ is used to initialize the quantum in the search space, which is defined as Q1 k (e) and Q2 k (e) can be defined as: Q1 K (e)6{G UB +r1·(G UB ―G LB )} Q2 K (e)={G UB +r2·(G UB ―G LB )} Among them, r1 and r2 represent two different random functions, G UB and G LB represent the upper and lower limits of the linear constraints respectively.
10. The gear surface defect detection method based on quantum contrast and superpixel clustering algorithm according to claim 9 is characterized in that: Enhanced search range M k The calculation formula for (e+1) is: M k (e+1)=M1+M2+M3 M1, M2, and M3 are represented as follows: M1=α·M k (e) M2=ln(1 / m f )·r3·[pBD k (e)―D k (e)] M3=ln(1 / m f )·r4·[gBD(e)―D k (it)] Where: α is the quantum acceleration factor, defined as follows: e=1,2,...,E,where E represents the maximum epoch number set by the algorithm, α max and α min Take the value in [0.1,0.9], pBD k (e) is the best displacement obtained from the first epoch of the kth quantum, gBD(e) is the best displacement among the displacements obtained in all epochs of the kth quantum, r3 and r4 represent two different random functions, taking values in [0,1] respectively.
Citation Information
Patent Citations
Light-weight gear surface defect detection method based on MSTA-YOLOv5
CN115953386A
Gear surface defect detection method based on RDMS
CN117173098A
Cited By
Compressor iron casting surface defect identification method based on multi-scale texture analysis
CN122115440A
A Method for Surface Defect Identification of Compressor Cast Iron Parts Based on Multi-Scale Texture Analysis
CN122115440B