Industrial product defect detection method and system based on image processing
By constructing seed point update paths and predicting update trend points, the superpixel segmentation iteration process is optimized, and the problem of slow convergence speed of superpixel segmentation is solved, and the efficiency and accuracy of industrial product defect detection are improved.
Patent Information
- Application Number
- CN202410772724.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-17
- Publication Date
- 2024-11-15
- Estimated Expiration
- 2044-06-17
AI Technical Summary
The convergence speed of superpixel segmentation iteration is slow, affecting the efficiency of industrial product defect detection.
During the superpixel segmentation iteration process, by constructing the update path of seed points, predict the update trend points of each group of seed points, and select new seed points according to the color difference and the regularity of the update path to perform the next round of iterations, improving the super The convergence speed of pixel segmentation.
It significantly accelerates the iterative convergence speed of superpixel segmentation, reduces the complexity of industrial product defect detection, and makes the detection more accurate and efficient.
Smart Images

Figure CN118365633B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing technology, and in particular to an industrial product defect detection method and system based on image processing. Background Art
[0002] Industrial products refer to products used to produce other goods or provide services, such as metals, plates, alloys, and mechanical parts. In the production process of industrial products, various defects such as cracks, impurities, and bubbles may occur in industrial products due to various reasons such as raw materials and production processes. In order to improve the factory quality of industrial products, it is necessary to detect industrial product defects.
[0003] In order to improve the detection efficiency of industrial product defects, currently, industrial product images are often segmented into superpixels first, and then industrial product defects are detected based on the results of superpixel segmentation. For example, in the patent document with publication number CN109886937B, the denoised image of the insulator is segmented into certain superpixels using a superpixel segmentation algorithm, the processed image is divided into a training set and a test set and labels are added, and the support vector machine algorithm is used to classify the image to obtain the prediction result. In the patent document with publication number CN114677384B, the coating image is segmented into superpixels, and the uniformity of the coating on the surface of the solar cell is obtained according to the edge weights of each superpixel block and its adjacent superpixel blocks, and the uniformity is used to detect the coating defects of the solar cell.
[0004] However, in the process of superpixel segmentation iteration, pixels that are closer in color to the rest of the pixels in the superpixel block and closer to the center of the superpixel block are usually selected as new seed points based on the color and position distribution of all pixels in the superpixel block. This makes the position update of the seed point limited by the color and position distribution of the pixels in the superpixel block, and the position change is small each time it is updated, resulting in slow convergence of superpixel segmentation iteration, affecting the efficiency of industrial product defect detection. Summary of the invention
[0005] In order to solve the problem that superpixel segmentation iteration converges slowly and affects the efficiency of industrial product defect detection, the present invention provides an industrial product defect detection method and system based on image processing.
[0006] In a first aspect, the present invention provides an industrial product defect detection method based on image processing, which adopts the following technical solution:
[0007] An industrial product defect detection method based on image processing comprises the steps of:
[0008] Preprocess the industrial product image to obtain the industrial product area; perform superpixel segmentation on the industrial product area, and in each round of iteration of superpixel segmentation, group the seed points between different rounds according to the correspondence between the superpixel blocks between different rounds to obtain multiple groups of seed points and the update path of each group of seed points; predict the update trend point of each group of seed points according to the angle and length of each segment of the update path of each group of seed points; for each superpixel block obtained in the current round of iteration, predict the probability of each pixel point in the superpixel block as the seed point of the next round according to the color difference between each pixel point in the superpixel block and the superpixel block, the update trend point of a group of seed points corresponding to the superpixel block, and the regularity of the update path of the group of seed points; select new seed points according to the probability to perform the next round of iteration of superpixel segmentation; obtain a superpixel image of the industrial product area through multiple rounds of iteration; and perform industrial product defect detection based on the superpixel image of the industrial product area.
[0009] The present invention performs superpixel segmentation on the industrial product area, and performs industrial product defect detection based on the superpixel image of the industrial product area. Compared with directly using the grayscale image of the industrial product area for defect identification, the analysis object is changed from a large number of pixels to a small number of superpixel blocks, which reduces the complexity of industrial product defect identification and makes industrial product defect identification more accurate and efficient. In the process of superpixel segmentation iteration, the present invention constructs an update path for seed points, predicts the probability of pixels in the superpixel block as seed points for the next round based on the update path, and thus selects new seed points for the next round of iteration, which speeds up the speed at which the seed points tend to the center of the image features represented by the superpixel block to which they belong, thereby speeding up the convergence speed of superpixel segmentation, making industrial product defect detection more efficient.
[0010] In one embodiment, obtaining multiple groups of seed points and the update path of each group of seed points includes: recording the total number of rounds of the current iteration as , the current iteration is Round iteration; when When , there is no update path; when When Any superpixel block obtained by round iteration is recorded as ; All superpixel blocks obtained by round iteration are The superpixel block with the largest matching is In the The corresponding superpixel block of the round is denoted as ;Will In the The corresponding superpixel block of the round , In the The corresponding superpixel block of the round , …, In the The corresponding superpixel block of the round as well as In the The corresponding superpixel block of the round The seed points in are divided into a group; all the seed points in the group are connected in ascending order according to the rounds they belong to, and the update path of the seed points in the group is obtained.
[0011] The update path in the present invention reflects the position change of the seed point between different rounds of superpixel segmentation iterations, which helps to quickly analyze the distribution of image features in the superpixel block and provides a basis for selecting the seed point for the next round of iteration.
[0012] In one embodiment, the matching is obtained by forming a set of all pixel points in the target superpixel block, which is recorded as the first set of the target superpixel block, and the first set of All the pixels in each superpixel block obtained by round iteration form a set, which is recorded as The second set of each superpixel block obtained by round iteration; For each superpixel block obtained by the round of iteration, the union and intersection between the first set and the second set of the superpixel block are obtained, the number of pixels in the union and the number of pixels in the intersection are counted respectively, and the ratio of the number of pixels in the intersection to the number of pixels in the union is taken as the matching between the superpixel block and the target superpixel block.
[0013] The calculation of matching in the present invention improves the accuracy of the constructed update path.
[0014] In one embodiment, the step of obtaining the update trend point of each group of seed points according to the angle and length of each segment of the update path of each group of seed points includes: for each group of seed points, taking the average of the angles of each segment of the update path of the group of seed points as the trend direction of the group of seed points, denoted as ;According to the total length of the update path of the seed points and the length of each path in the update path, the trend length of the seed points is obtained, which is recorded as ; Set the seed point of this group The seed point during the round iteration is used as the reference point, and the The distance to the reference point is The pixel point is used as the update trend point of the group of seed points.
[0015] The updating trend point in the present invention is the position of the new seed point predicted according to the position change trend of the seed point, which provides a basis for the subsequent selection of the seed point for the next round of iteration.
[0016] In one embodiment, the trend length satisfies the expression:
[0017] ; In the formula, represents the trend length of the jth group of seed points; j represents the group number of the seed points; Indicates the distance between the seed point of the i-1th round and the seed point of the i-th round in the jth group of seed points; The sequence number indicating the number of iteration rounds; Indicates the total number of rounds in the current iteration; Indicates the number of seed points from the first round to the first round in the jth group of seed points The distance between the seed points of the round; represents the total length of the update path of the jth group of seed points; The rounding function.
[0018] In one embodiment, the regularity of the update path satisfies the expression:
[0019] ; In the formula, Indicates the regularity of the update path of the jth group of seed points; j represents the group number of the seed points; Indicates the number of seed points from the first round to the first round in the jth group of seed points The distance between the seed points of the round; Indicates the total number of rounds in the current iteration; represents the total length of the update path of the jth group of seed points; The sequence number indicating the number of iteration rounds; represents the angle of the line between the seed point of the i-1th round and the seed point of the i-th round in the jth group of seed points; Indicates the number of seed points from the first round to the first round in the jth group of seed points The angle of the line between the seed points of the round.
[0020] In the present invention, the regularity of the update path quantifies the regularity of the change of the distribution position of the seed points. The more regular the change of the distribution position of the seed points is, the more regular the distribution of the image features in the superpixel block is, and the more regular the seed points for the next round of iteration can be selected based on the update path. The regularity of the update path determines the reference degree of the update path when the seed points for the next round of iteration are subsequently selected, so that the seed points for the next round of iteration selected can speed up the iterative convergence speed of the superpixel segmentation as much as possible.
[0021] In one embodiment, the probability of each pixel point in the superpixel block being a seed point for the next round satisfies the expression:
[0022] ; represents the probability of the kth pixel in the target superpixel block being used as the seed point for the next round; k represents the sequence number of the pixel in the target superpixel block; represents the color difference between the kth pixel in the target superpixel block and the target superpixel block; F represents the maximum color difference between the pixel in the target superpixel block and the target superpixel block; C represents the regularity of the update path of a group of seed points corresponding to the target superpixel block; Represents the distance between the kth pixel in the target superpixel block and the center point of the target superpixel block; Represents the distance between the kth pixel in the target superpixel block and the update trend point of a set of seed points corresponding to the target superpixel block; Represents the distance between the two farthest pixels in the target superpixel block.
[0023] In the present invention, the probability of each pixel point in the superpixel block serving as the seed point for the next round comprehensively considers the overall color difference between each pixel point in the superpixel block and the superpixel block, the position difference with the center point of the superpixel block, and the position difference with the update trend point, and uses the regularity of the update path as the weight of the position difference between the pixel point and the update trend point. When the regularity of the update path is greater, the update trend point is more considered when selecting a new seed point, and the pixel point with a greater probability of serving as the seed point for the next round can accelerate the iterative convergence speed of the superpixel segmentation.
[0024] In one embodiment, the selecting of new seed points according to the probability includes: taking the pixel point with the highest probability of being the seed point of the next round in the target superpixel block as the new seed point; judging the probability of each pixel point in each superpixel block obtained in the current round of iteration being the seed point of the next round, and obtaining all new seed points.
[0025] The present invention uses the probability of each pixel point in the superpixel block being the seed point of the next round as a criterion, selects a new seed point for the next round of iteration, and accelerates the iterative convergence speed of superpixel segmentation.
[0026] In a second aspect, the present invention provides an industrial product defect detection system based on image processing, which adopts the following technical solution:
[0027] An industrial product defect detection system based on image processing includes: a processor and a memory, wherein the memory stores computer program instructions, and when the computer program instructions are executed by the processor, the above-mentioned industrial product defect detection method based on image processing is implemented.
[0028] By adopting the above technical solution, the above-mentioned industrial product defect detection method based on image processing is generated into a computer program and stored in a memory so as to be loaded and executed by a processor, thereby making a terminal device based on the memory and the processor for easy use.
[0029] The present invention has the following technical effects:
[0030] (1) The present invention reduces the complexity of industrial product defect identification, making industrial product defect identification more accurate and efficient;
[0031] (2) The update path of the present invention helps to quickly analyze the distribution of image features in the superpixel block, providing a basis for selecting the seed point for the next round of iteration, so that the seed point selected for the next round of iteration accelerates the convergence speed of superpixel segmentation, making the industrial product defect detection more efficient;
[0032] (3) The regularity of the update path of the present invention quantifies the regularity of the change in the distribution position of the seed points, determines the reference degree of the update path when selecting the seed points for the next round of iteration, so that the seed points selected for the next round of iteration can accelerate the iterative convergence speed of superpixel segmentation as much as possible, further improving the detection efficiency of industrial product defects;
[0033] (4) In the present invention, the probability of each pixel point in the superpixel block serving as the seed point for the next round comprehensively considers the overall color difference between each pixel point in the superpixel block and the superpixel block, the position difference between each pixel point in the superpixel block and the center point of the superpixel block, and the position difference between each pixel point and the update trend point. The obtained result is more accurate. The pixel point with a larger probability can accelerate the iterative convergence speed of the superpixel segmentation. The new seed point is selected according to the probability for the next round of iteration, which further improves the detection efficiency of industrial product defects. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] By reading the detailed description below with reference to the accompanying drawings, the above and other purposes, features and advantages of the exemplary embodiments of the present invention will become readily understood. In the accompanying drawings, several embodiments of the present invention are shown in an exemplary and non-restrictive manner, and the same or corresponding reference numerals represent the same or corresponding parts.
[0035] Figure 1 It is a flowchart of a method and system for detecting industrial product defects based on image processing according to an embodiment of the present invention. DETAILED DESCRIPTION
[0036] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0037] It should be understood that when the terms "first", "second", etc. are used in the claims, descriptions, and drawings of the present invention, they are only used to distinguish different objects, rather than to describe a specific order. The terms "include" and "comprise" used in the description and claims of the present invention indicate the presence of the described features, wholes, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components, and / or their collections.
[0038] The embodiment of the present invention discloses an industrial product defect detection method based on image processing, referring to Figure 1 , comprising steps S1 to S3:
[0039] S1: Collect industrial product images, preprocess the industrial product images, and obtain industrial product areas.
[0040] A camera is set up above the conveyor belt, and the image of the industrial product on the conveyor belt is photographed by the camera looking down. The industrial product image taken only contains one industrial product and the background, and is an RGB image. In order to facilitate subsequent processing, the RGB image is converted into a grayscale image.
[0041] Perform semantic segmentation on the grayscale image of industrial products to obtain an image of the industrial product area that only contains the industrial products but not the background. Specifically:
[0042] The input of the semantic segmentation network is a grayscale image of industrial products, and the output is a binary image of industrial products. The dataset of the semantic segmentation network is a dataset consisting of grayscale images of different industrial products with different backgrounds. The labels of the dataset are: pixels belonging to industrial products are marked as 1, and pixels belonging to the background are marked as 0. The loss function of the semantic segmentation network is the cross entropy loss.
[0043] Input the grayscale image of industrial products into the trained semantic segmentation network, and output the binary image of industrial products. The pixels with a pixel value of 0 in the binary image of industrial products are the background, and the pixels with a pixel value of 1 are industrial products. Multiply the binary image of industrial products with the grayscale image of industrial products to obtain the industrial product region image. The pixels with non-zero grayscale values in the industrial product region image are industrial products, so the region composed of pixels with non-zero grayscale values in the industrial product region image is recorded as the industrial product region. The pixels with a grayscale value of 0 in the industrial product region image are the background and will not be considered in subsequent analysis.
[0044] At this point, the industrial product area in the industrial product area image is acquired.
[0045] S2: Perform superpixel segmentation on the industrial product area to obtain a superpixel image of the industrial product area. In each round of iteration of superpixel segmentation, group the seed points between different rounds according to the correspondence between the superpixel blocks between different rounds to obtain multiple groups of seed points and an update path for each group of seed points. According to the update path, obtain the update trend point and the regularity of the update path. According to the update trend point, the regularity of the update path and the color difference between the pixel point in the superpixel block and the superpixel, obtain the probability that the pixel point in the superpixel block will be the seed point for the next round. According to the probability, select a new seed point for the next round of iteration.
[0046] It should be noted that, currently, before performing defect detection based on image features, superpixel segmentation is often used to pre-process the image. Superpixel segmentation can better capture features such as texture, color, and shape in the image, which is helpful for subsequent defect detection and identification. Therefore, the present invention first performs superpixel segmentation on the industrial product area, and identifies industrial product defects based on the results of superpixel segmentation.
[0047] It should be further explained that in the process of superpixel segmentation, except for the first round, the seed points of each iteration are obtained based on the distribution of pixel points in the superpixel block obtained in the previous iteration. The obtained seed points gradually approach the center of the image feature represented by the superpixel block. When all seed points are located at the center of the image feature represented by the superpixel block to which they belong, the convergence effect is achieved. The present invention takes into account that the selection of seed points is based on the color and position distribution of pixels in the superpixel block, so the color of the selected seed point is closer to the overall color distribution of the superpixel block, so that the position change of the seed point between different rounds reflects the distribution law of image features in the image. For example, when the selected seed point is closer to the right side of the superpixel block, it means that the overall color distribution of the superpixel block is closer to the color distribution of the pixels on the right side of the superpixel block, and the color of the seed point is closer to the color distribution of the pixels on the right side of the superpixel block. The color distribution difference between the seed point and the pixel on the left side of the superpixel block is greater. Therefore, there is a difference between the image features on the left side of the superpixel block and the image features on the right side, and the image features on the right side of the superpixel block account for most of the superpixel block. The image features on the right side of the superpixel block are the image features represented by the superpixel block. In the final superpixel segmentation result, the superpixel block needs to only contain the image features it represents. Therefore, in the process of multiple rounds of iterations, the position of the seed point of the superpixel block is likely to gradually change to the right. If the speed at which the position of the seed point of the superpixel block changes to the right is accelerated during the iteration, the convergence effect can be achieved faster. Therefore, the present invention obtains the update path of the seed points according to the position changes of the seed points in different rounds, selects the seed points for the next round of iteration according to the update path, and accelerates the speed at which the seed points tend to the center of the image features represented by the superpixel block to which they belong, thereby accelerating the iterative convergence speed of the superpixel segmentation and improving the efficiency of industrial product defect detection.
[0048] Specifically, the number of seed points N is preset, and the implementer can set the number of seed points according to the actual implementation situation, for example , where S represents the number of pixels contained in the industrial product area.
[0049] N seed points are evenly spread in the industrial product area, and the industrial product area is segmented into superpixels according to the seed points. In each round of superpixel segmentation, an update path of the seed points is constructed according to the correspondence between superpixel blocks obtained in different rounds of iteration.
[0050] Specifically, the total number of rounds of the current iteration is recorded as , then the current iteration is Round iteration.
[0051] when When , there is no update path, no subsequent calculation is performed, and new seed points are directly selected in each superpixel block according to the seed point selection method in superpixel segmentation, and the next round of iteration is performed based on the new seed points.
[0052] when When After rounds of iteration, any superpixel block is obtained as the target superpixel block, and the target superpixel block and the first The matching between each superpixel block obtained in the round iteration.
[0053] The target superpixel block is denoted as . The superpixel block with the largest match with the target superpixel block among all the superpixel blocks obtained in the round iteration is taken as the target superpixel block. In the The corresponding superpixel block of the round is denoted as .
[0054] Similarly, get In the The corresponding superpixel block of the round , In the The corresponding superpixel block of the round , …, The corresponding superpixel block in the second round , The corresponding superpixel block in the first round .
[0055] Will , , , …, , , The seed points in the group are divided into a group. All seed points in the group are connected in ascending order according to the rounds they belong to, and the update path of the seed points in the group is obtained. The line between the seed points of each adjacent round in the group is used as each segment of the update path.
[0056] Similarly, obtain multiple sets of seed points and the update path of each set of seed points, each set contains A seed point.
[0057] Optionally, the target superpixel block is The method for obtaining the matching between each superpixel block obtained by round iteration is:
[0058] For For each superpixel block obtained in the round of iteration, the number of identical pixels in the superpixel block and the target superpixel block is obtained, and the ratio of this number to the number of pixels contained in the industrial product area is used as the matching between the target superpixel block and the superpixel block.
[0059] Preferably, the target superpixel block is The matching between each superpixel block obtained by the round iteration satisfies the expression:
[0060] ;
[0061] In the formula, Represents the target superpixel block and the The first round of iterations The matching between superpixel blocks; Indicates The sequence number of the superpixel block obtained in the round iteration; Represents the set of all pixels in the target superpixel block; Indicates The first round of iteration The set of all pixels in a superpixel block; represents the intersection symbol; Represents the union symbol; Representing a collection and collection The number of pixels contained in the intersection of Representing a collection and collection The number of pixels contained in the union of ; represents the target superpixel block and the The first round of iteration The overlap ratio of the superpixel blocks is higher. When the overlap ratio is higher, the target superpixel block and the The first round of iteration The higher the matching between superpixel blocks.
[0062] It should be noted that, in the process of superpixel segmentation, the update path of each group of seed points reflects the distribution of image features in the local position of the industrial product area. If a group of seed points changes its position to the right continuously during the iteration process, it means that the image features on the left side of the local position are different from the image features on the right side. At this time, the update path of the group of seed points changes more regularly, and the distribution of image features in the local position can be predicted according to the update path of the group of seed points, so as to select the seed points of the next round of iteration, so that the seed points of the next round of iteration are closer to the center of the image features on the right side, and the iterative convergence speed is accelerated. If a group of seed points changes its position irregularly during the iteration process, it means that the local position contains multiple image features, and the distribution is complex, and the distribution of image features in the local position cannot be predicted according to the update path of the group of seed points. Then, the seed points of the next round of iteration selected according to the update path may not necessarily be able to accelerate the iterative convergence speed. Therefore, the present invention judges the regularity of the update path of each group of seed points, so that when selecting the seed points of the next round of iteration, the reference degree of the update path is determined according to the regularity of the update path.
[0063] Optionally, obtain the regularity of the update path of each group of seed points based on the update path of each group of seed points:
[0064] when When , the regularity of the update path of each group of seed points is set to 0.
[0065] when , for each group of seed points, according to the order of the seed points in the update path of the group of seed points, the coordinates of all the seed points in the group in the industrial product area constitute a coordinate sequence, a linear fit is performed on the coordinate sequence, the total error of the linear fitting result is negatively normalized, and the result is used as the regularity of the update path. The present invention does not limit the fitting algorithm used for linear fitting, and the implementer can select the fitting algorithm according to the actual implementation situation, such as the least squares method, the maximum likelihood method, etc. The present invention does not limit the method of negative correlation normalization, and the implementer can select the method of negative correlation normalization according to the actual implementation situation, such as by The model is negatively correlated normalized, where Represents an exponential function with a natural constant as its base.
[0066] Preferably, the regularity of the update path of each group of seed points is obtained according to the update path of each group of seed points:
[0067] ;
[0068] In the formula, Indicates the regularity of the update path of the jth group of seed points; j represents the group number of the seed points; Indicates the number of seed points from the first round to the first round in the jth group of seed points The distance between the seed points of the round; Indicates the total number of rounds in the current iteration; represents the total length of the update path of the jth group of seed points; Indicates the number of iteration rounds. In order to avoid the situation where the corresponding round number does not exist when i-1=0, i is For every integer in ; represents the angle of the line between the seed point of the i-1th round and the seed point of the i-th round in the jth group of seed points; Indicates the number of seed points from the first round to the first round in the jth group of seed points The angle of the line between the seed points of the round; Represents an exponential function with a natural constant as its base.
[0069] In the formula, Represents the directionality of the update path of the jth group of seed points. The larger the value is, the more linear the distribution of the seed points in the jth group is, and the directionality of the seed point update path is very strong; on the contrary, when The smaller it is, the more irregular the position changes of the seed points in the jth group are, and the directionality of the seed point update path is weaker.
[0070] In the formula, the angle of the line between the seed point of the i-1th round and the seed point of the i-th round in the jth group of seed points is It reflects the update direction of the j-th group of seed points when they are updated in the i-th round. The angle of the line between the seed points of the round Reflects the jth group of seed points passing through After rounds of iterations, the overall update direction is It indicates the difference between the update direction of the j-th group of seed points in the i-th round of update and the overall update direction. The larger the difference is, the less the j-th group of seed points conforms to the overall update rule of the j-th group of seed points in the i-th round of update.
[0071] When the superpixel segmentation starts to iterate, the seed points are evenly distributed. Therefore, in the first few iterations, the regularity of the position change of the seed points is poor. After several iterations, the position change of the seed points gradually tends to the center of the image feature represented by the superpixel block to which it belongs, and the regularity gradually increases. Therefore, the present invention normalizes the number of iteration rounds i to obtain ,Will As the weight of the difference between the update direction of the j-th group of seed points when updated in the i-th round and the overall update direction, the earlier the iteration round is, the less attention is paid to the difference between the update direction of the j-th group of seed points when updated in this round and the overall update direction; when the iteration round is closer to the current iteration round, the more attention is paid to the difference between the update direction of the j-th group of seed points when updated in this round and the overall update direction.
[0072] In the formula, the difference in the update direction of the jth group of seed points in each round of update is weighted and summed with the difference between the update direction of the whole update direction to obtain the difference in the update direction: When the difference in update direction is greater and the directionality of seed point update is weaker, the regularity of update path of seed point group j is smaller. When the difference in update direction is smaller and the directionality of seed point update is stronger, the regularity of update path of seed point group j is greater.
[0073] In the formula, when When , the update path of each group of seed points has only one section, and the regularity of the update path of each group of seed points calculated by the above method is inaccurate. Therefore, it is stipulated that when When , the regularity of the update path of each group of seed points is 0.
[0074] So far, the regularity of the update path of each group of seed points has been obtained.
[0075] It should be noted that in superpixel segmentation, the seed points for the next iteration are selected based on the color distribution and position distribution of all pixels in the superpixel block obtained in the current iteration. The color of the selected seed points is close to the color mean of the superpixel block, and the position is close to the center of the superpixel block. However, the iterative convergence speed of this selection method is slow. Therefore, the present invention selects the seed points for the next iteration based on the regularity of the update path of each group of seed points, speeding up the speed at which the seed points tend to the center of the image features represented by the superpixel block to which they belong, thereby speeding up the iterative convergence speed of superpixel segmentation and improving the efficiency of industrial product defect detection.
[0076] Specifically, the trend direction of each group of seed points is obtained according to the angle of each segment of the update path of each group of seed points:
[0077] ;
[0078] In the formula, Indicates the trend direction of the jth group of seed points; j represents the group number of the seed points; represents the angle of the line between the seed point of the i-1th round and the seed point of the i-th round in the jth group of seed points; Indicates the number of iteration rounds. In order to avoid the situation where the corresponding round number does not exist when i-1=0, i is For every integer in ; Indicates the total number of rounds in the current iteration; Represents the average value of the angle of each path in the update path of the j-th group of seed points.
[0079] Optionally, the trend length of each group of seed points is obtained based on the total length of the update path of each group of seed points and the length of each segment of the update path:
[0080] ;
[0081] In the formula, represents the trend length of the jth group of seed points; j represents the group number of the seed points; Indicates the distance between the seed point of the i-1th round and the seed point of the i-th round in the jth group of seed points; Indicates the number of iteration rounds. In order to avoid the situation where the corresponding round number does not exist when i-1=0, i is For every integer in ; Indicates the total number of rounds in the current iteration; The rounding function.
[0082] Preferably, the trend length of each group of seed points is obtained according to the total length of the update path of each group of seed points and the length of each segment of the update path:
[0083] ;
[0084] In the formula, represents the trend length of the jth group of seed points; j represents the group number of the seed points; Indicates the distance between the seed point of the i-1th round and the seed point of the i-th round in the jth group of seed points; Indicates the number of iteration rounds. In order to avoid the situation where the corresponding round number does not exist when i-1=0, i is For every integer in ; Indicates the total number of rounds in the current iteration; Indicates the number of seed points from the first round to the first round in the jth group of seed points The distance between the seed points of the round; represents the total length of the update path of the jth group of seed points; is the rounding function; It represents the directionality of the update path of the jth group of seed points. It represents the average update length in the trend direction of each iteration of the j-th group of seed points.
[0085] The jth group of seed points The seed point during the round iteration is used as the reference point, and the In the direction of the reference point The pixel point of is taken as the update trend point of the jth group of seed points.
[0086] At this point, the update trend point of each group of seed points is obtained. It should be noted that since each group of seed points is divided according to the corresponding relationship of super pixel blocks in each round of iteration, each super pixel block obtained in the current round of iteration corresponds to a group of seed points.
[0087] The first After rounds of iteration, any superpixel block is obtained as the target superpixel block, where is the total number of rounds in the current iteration.
[0088] Get the color difference between each pixel in the target superpixel block and the target superpixel block:
[0089] ;
[0090] In the formula, represents the color difference between the kth pixel in the target superpixel block and the target superpixel block; k represents the sequence number of the pixel in the target superpixel block; Represents the brightness of the kth pixel in the target superpixel block in the Lab color space; Represents the average brightness of all pixels in the target superpixel block in the Lab color space; Represents the red and green color of the kth pixel in the target superpixel block in the Lab color space; Represents the mean red and green values of all pixels in the target superpixel block in the Lab color space; Indicates the yellow-blue color of the k-th pixel in the target superpixel block in the Lab color space; Represents the mean yellow-blue value of all pixels in the target superpixel block in the Lab color space.
[0091] Optionally, the probability of each pixel in the target superpixel block being used as the seed point for the next round is obtained based on the color difference between each pixel in the target superpixel block and the target superpixel block, the regularity of the update path of a group of seed points corresponding to the target superpixel block, and the update trend point:
[0092] ;
[0093] In the formula, represents the probability of the kth pixel in the target superpixel block being used as the seed point for the next round; k represents the sequence number of the pixel in the target superpixel block; represents the color difference between the kth pixel in the target superpixel block and the target superpixel block; F represents the maximum color difference between the pixel in the target superpixel block and the target superpixel block; C represents the regularity of the update path of a group of seed points corresponding to the target superpixel block; Represents the distance between the kth pixel in the target superpixel block and the center point of the target superpixel block; Represents the distance between the kth pixel in the target superpixel block and the update trend point of a set of seed points corresponding to the target superpixel block; Represents an exponential function with a natural constant as its base.
[0094] In the formula, It reflects the color advantage of the kth pixel in the target superpixel block as the seed point for the next round. The smaller the color difference between the kth pixel and the target superpixel block, the greater the color advantage of the kth pixel as the seed point for the next round.
[0095] In the formula, It reflects the distance advantage of the k-th pixel point in the target superpixel block as the seed point for the next round. When the regularity C of the update path of a group of seed points corresponding to the target superpixel block is larger, the selection of seed points for the next round should consider the update trend points of a group of seed points corresponding to the target superpixel block, and should not consider the center point of the target superpixel block. At this time, the smaller 1-C is, the closer the k-th pixel point in the target superpixel block is to the center point of the target superpixel block, as well as are all small, and the distance advantage is small. When the kth pixel in the target superpixel block is closer to the update trend point, Smaller, The larger the 1-C is, the greater the distance advantage is. When the regularity C of the update path of a group of seed points corresponding to the target superpixel block is, the smaller the regularity C is, the more the selection of seed points in the next round should consider the center point of the target superpixel block, and the less the update trend point of a group of seed points corresponding to the target superpixel block should be considered. At this time, the larger the 1-C is, the closer the k-th pixel point in the target superpixel block is to the center point of the target superpixel block, Larger, The smaller the distance advantage is, the closer the k-th pixel point in the target superpixel block is to the update trend point. as well as Both are relatively small, so the distance advantage is relatively small.
[0096] In the formula, when the color advantage and distance advantage are greater, the probability of the kth pixel point in the target superpixel block being used as the seed point for the next round is greater.
[0097] Optionally, the probability of each pixel in the target superpixel block being used as the seed point for the next round is obtained based on the color difference between each pixel in the target superpixel block and the target superpixel block, the regularity of the update path of a group of seed points corresponding to the target superpixel block, and the update trend point:
[0098] ;
[0099] In the formula, represents the probability of the kth pixel in the target superpixel block being used as the seed point for the next round; k represents the sequence number of the pixel in the target superpixel block; represents the color difference between the kth pixel in the target superpixel block and the target superpixel block; F represents the maximum color difference between the pixel in the target superpixel block and the target superpixel block; C represents the regularity of the update path of a group of seed points corresponding to the target superpixel block; Represents the distance between the kth pixel in the target superpixel block and the center point of the target superpixel block; Represents the distance between the kth pixel in the target superpixel block and the update trend point of a set of seed points corresponding to the target superpixel block; Represents the distance between the two farthest pixels in the target superpixel block; Represents an exponential function with a natural constant as its base.
[0100] In the formula, It reflects the color advantage of the kth pixel in the target superpixel block as the seed point for the next round. The smaller the color difference between the kth pixel and the target superpixel block, the greater the color advantage of the kth pixel as the seed point for the next round.
[0101] In the formula, It reflects the distance advantage of the kth pixel point in the target superpixel block as the seed point for the next round. When the regularity of the update path of a group of seed points corresponding to the target superpixel block is greater, the selection of the seed point for the next round should consider the update trend point of the group of seed points corresponding to the target superpixel block, and should not consider the center point of the target superpixel block. Therefore, the regularity C of the update path is used as the distance between the kth pixel point in the target superpixel block and the update trend point. The weight of (1-C) is used as the distance between the kth pixel in the target superpixel block and the center point. The weight of the k-th pixel point is The smaller the distance, the greater the advantage of the k-th pixel as the seed point for the next round; conversely, when the regularity of the update path of a group of seed points corresponding to the target superpixel block is smaller, the selection of the seed point for the next round should consider the center point of the target superpixel block more, and the update trend point should be considered less. Therefore, when the distance between the k-th pixel and the center point of the target superpixel block is The smaller it is, the greater the distance advantage of the kth pixel as the seed point for the next round.
[0102] In the formula, when the color advantage is greater and the distance advantage is also greater, the probability that the kth pixel in the target superpixel block is used as the seed point for the next round is greater; conversely, when the color advantage is smaller or the distance advantage is smaller, the probability that the kth pixel in the target superpixel block is used as the seed point for the next round is smaller.
[0103] At this point, the probability of each pixel in the target superpixel block being the seed point for the next round is obtained. The pixel with the highest probability of being the seed point for the next round in the target superpixel block is used as the new seed point.
[0104] Similarly, the probability of each pixel point in each superpixel block obtained in the current round of iteration being used as the seed point of the next round is judged, all new seed points are obtained, and the next round of iteration is performed based on the new seed points.
[0105] In the process of continuous iteration, when the distance between each seed point of the next round and each seed point corresponding to the current round is less than the preset distance threshold, the iteration is stopped, and the image obtained by the current round of iteration is used as the superpixel image of the industrial product area. It should be noted that the distance threshold is set by the implementer according to the actual implementation situation, and there is no specific restriction. For example, the distance threshold is 2.
[0106] At this point, the superpixel segmentation of the industrial product area is achieved, and the superpixel image of the industrial product area is obtained.
[0107] S3: Perform industrial product defect detection based on the superpixel image of the industrial product area.
[0108] The neural network is used to identify industrial product defects based on the superpixel image of the industrial product area. The specific content of the neural network is as follows:
[0109] The neural network adopts a fully connected form, with the input being the superpixel image of the industrial product area, and the output being the defect area and defect category in the superpixel image of the industrial product area; the data set of the neural network is a data set consisting of superpixel images of the industrial product area corresponding to industrial products with different defects, and the labeling process is as follows: superpixel blocks that do not contain defects are labeled as 0, and superpixel blocks containing different defects are labeled with different labels, for example, superpixel blocks containing crack defects are labeled as 1, superpixel blocks containing impurity defects are labeled as 2, and superpixel blocks containing bubble defects are labeled as 3, etc.; the loss function of the neural network is the mean square error loss.
[0110] The super-pixel image of the industrial product area is input into the trained neural network, and the defect area and defect category in the super-pixel image of the industrial product area are output, thus realizing the detection of industrial product defects.
[0111] It should be noted that the present invention uses super-pixel images of industrial product areas for defect recognition. Compared with directly using grayscale images of industrial product areas for defect recognition, the analysis object is changed from a large number of pixels to a small number of super-pixel blocks, and the amount of data is reduced, which makes the convergence speed of the neural network faster and the results more accurate. At the same time, using grayscale images of industrial product areas for defect recognition requires labeling each pixel in the industrial product area, while using super-pixel images of industrial product areas for defect recognition only requires labeling super-pixel blocks, which greatly reduces the workload of data set labeling and saves labor costs.
[0112] At this point, the detection of industrial product defects has been achieved.
[0113] An embodiment of the present invention also discloses an industrial product defect detection system based on image processing, including a processor and a memory, wherein the memory stores computer program instructions, and when the computer program instructions are executed by the processor, an industrial product defect detection method based on image processing according to the present invention is implemented.
[0114] The above system also includes other components well known to those skilled in the art, such as a communication bus and a communication interface, and their configuration and functions are known in the art, so they will not be described in detail here.
[0115] Although this specification has shown and described a number of embodiments of the present invention, it will be apparent to those skilled in the art that such embodiments are provided by way of example only. Those skilled in the art will conceive of many modifications, changes and alternatives without departing from the ideas and spirit of the present invention. It should be understood that in the practice of the present invention, various alternatives to the embodiments of the present invention described herein may be employed.
[0116] The above are all preferred embodiments of the present invention, and are not intended to limit the protection scope of the present invention. Therefore, any equivalent changes made based on the structure, shape, and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. An industrial product defect detection method based on image processing, characterized in that: include: Preprocess the industrial product image to obtain the industrial product area; The industrial product area is segmented into superpixels. In each round of superpixel segmentation, the seed points between different rounds are grouped according to the correspondence between the superpixel blocks between different rounds to obtain multiple groups of seed points and the update path of each group of seed points. The update trend point of each group of seed points is predicted according to the angle and length of each segment in the update path of each group of seed points. For each superpixel block obtained in the current round of iteration, the probability of each pixel in the superpixel block being a seed point for the next round is predicted based on the color difference between each pixel in the superpixel block and the superpixel block, the update trend point of a group of seed points corresponding to the superpixel block, and the regularity of the update path of the group of seed points; new seed points are selected according to the probability for the next round of iteration of superpixel segmentation; Through multiple rounds of iterations, a super-pixel image of the industrial product area is obtained; Detect industrial product defects based on superpixel images of industrial product areas; The step of obtaining multiple groups of seed points and an update path for each group of seed points includes: The total number of rounds in the current iteration is recorded as , the current iteration is Round iteration; when When , there is no update path; when When Any superpixel block obtained by round iteration is recorded as ; All superpixel blocks obtained by round iteration are The superpixel block with the largest matching is In the The corresponding superpixel block of the round is denoted as ;Will In the The corresponding superpixel block of the round , In the The corresponding superpixel block of the round , …, The corresponding superpixel block in the second round as well as The corresponding superpixel block in the first round The seed points in are divided into a group; all the seed points in the group are connected in ascending order according to the rounds they belong to, and the update path of the seed points in the group is obtained.
2. The industrial product defect detection method based on image processing according to claim 1, characterized in that: The method for obtaining the matching is: All the pixels in the target superpixel block form a set, which is recorded as the first set of the target superpixel block. All the pixels in each superpixel block obtained by round iteration form a set, which is recorded as A second set of each superpixel block obtained by the round iteration; For For each superpixel block obtained by the round of iteration, the union and intersection between the first set and the second set of the superpixel block are obtained, the number of pixels in the union and the number of pixels in the intersection are counted respectively, and the ratio of the number of pixels in the intersection to the number of pixels in the union is taken as the matching between the superpixel block and the target superpixel block.
3. The industrial product defect detection method based on image processing according to claim 1 is characterized in that: The step of obtaining the update trend point of each group of seed points according to the angle and length of each path segment in the update path of each group of seed points includes: For each group of seed points, the average of the angles of each segment of the update path of the group of seed points is taken as the trend direction of the group of seed points, denoted as ;According to the total length of the update path of the seed points and the length of each path in the update path, the trend length of the seed points is obtained, which is recorded as ; Set the seed point of this group The seed point during the round iteration is used as the reference point, and the The distance to the reference point is The pixel point is used as the update trend point of the group of seed points.
4. The industrial product defect detection method based on image processing according to claim 3 is characterized in that: The trend length satisfies the expression: ; In the formula, represents the trend length of the jth group of seed points; j represents the group number of the seed points; Indicates the distance between the seed point of the i-1th round and the seed point of the i-th round in the jth group of seed points; The sequence number indicating the number of iteration rounds; Indicates the total number of rounds in the current iteration; Indicates the number of seed points from the first round to the first round in the jth group of seed points The distance between the seed points of the round; represents the total length of the update path of the jth group of seed points; The rounding function.
5. The industrial product defect detection method based on image processing according to claim 1, characterized in that: The regularity of the update path satisfies the expression: ; In the formula, Indicates the regularity of the update path of the jth group of seed points; j represents the group number of the seed points; Indicates the number of seed points from the first round to the first round in the jth group of seed points The distance between the seed points of the round; Indicates the total number of rounds in the current iteration; represents the total length of the update path of the jth group of seed points; The sequence number indicating the number of iteration rounds; represents the angle of the line between the seed point of the i-1th round and the seed point of the i-th round in the jth group of seed points; Indicates the number of seed points from the first round to the first round in the jth group of seed points The angle of the line between the seed points of the round.
6. The industrial product defect detection method based on image processing according to claim 1, characterized in that: The probability of the pixel point being the seed point for the next round satisfies the expression: ; represents the probability of the kth pixel in the target superpixel block being used as the seed point for the next round; k represents the sequence number of the pixel in the target superpixel block; represents the color difference between the kth pixel in the target superpixel block and the target superpixel block; F represents the maximum color difference between the pixel in the target superpixel block and the target superpixel block; C represents the regularity of the update path of a group of seed points corresponding to the target superpixel block; Represents the distance between the kth pixel in the target superpixel block and the center point of the target superpixel block; Represents the distance between the kth pixel in the target superpixel block and the update trend point of a set of seed points corresponding to the target superpixel block; Represents the distance between the two farthest pixels in the target superpixel block.
7. The industrial product defect detection method based on image processing according to claim 6, characterized in that: The selecting a new seed point according to the probability comprises: The pixel with the highest probability of being the seed point for the next round in the target superpixel block is used as the new seed point; the probability of each pixel in each superpixel block obtained in the current round of iteration being the seed point for the next round is judged to obtain all new seed points.
8. An industrial product defect detection system based on image processing, characterized in that: include: A processor and a memory, wherein the memory stores computer program instructions, and when the computer program instructions are executed by the processor, an industrial product defect detection method based on image processing according to any one of claims 1 to 7 is implemented.
