A method and device for multi-layer image segmentation and target contour defect detection
By employing multi-layer image segmentation and target contour defect detection methods, and utilizing techniques such as median filtering and flood filling, the challenges of detecting different types of defects have been solved, achieving efficient and accurate defect detection and meeting the needs of industrial production.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-21
- Publication Date
- 2026-04-03
AI Technical Summary
Existing technologies are insufficient to comprehensively detect different types of target contour defects. Errors exist in image segmentation boundaries, manual annotation is costly, and image information is not fully utilized, resulting in low detection accuracy.
A multi-layer image segmentation method is adopted, including image preprocessing, segmentation processing and range calculation. Using techniques such as median filtering and flood filling, the target contour is judged to be abnormal by calculating the block area and the range.
It improves testing efficiency, saves labor costs, and enhances testing accuracy and speed, thus meeting the needs of industrial production.
Smart Images

Figure CN116703823B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image defect detection, and in particular to a method and device for multi-layer image segmentation and target contour defect detection. Background Technology
[0002] In industrial production, image-based defect detection has significant practical value. With the continuous development of manufacturing technology and the rapid advancement of industrialization, product quality is becoming increasingly crucial to a company's competitiveness. In manufacturing, product quality is a persistent and critical issue that must be addressed during the production process. Among these issues, product defects are a common problem. Defects can lead to unstable product performance, render products unusable, and cause negative user experiences and safety hazards. Defect detection technology is a vital means of achieving product quality control during manufacturing, enabling the timely detection and resolution of defects. Currently, with the continuous development and application of technologies such as image recognition, defect detection technology is constantly improving and being perfected. Developing efficient, accurate, and reliable defect detection technology is of great significance for improving product quality, reducing production costs, and enhancing corporate competitiveness. However, existing technologies have the following shortcomings:
[0003] (1) Different detection capabilities for different types of target contours: Different types of defects require different detection technologies, but existing technologies are often only good at detecting specific types of defects and are difficult to fully cover all possible defect types.
[0004] (2) Defects in the segmentation boundary line: The calculation method used in traditional image segmentation usually only takes integer points for the horizontal coordinate of the pixel, which means that the straight line at the intersection is not necessarily a smooth straight line and may be discontinuous, resulting in errors in the final area calculation process.
[0005] (3) High cost of manual annotation: Defect detection technology requires a large amount of annotation data for verification, but the cost of manual annotation data is often very high. Therefore, when the sample to be tested is large, the workload of checking the test results is large.
[0006] (4) Incomplete application of image information: The existing detection methods do not fully utilize information, resulting in insufficient detection accuracy. Summary of the Invention
[0007] To address the aforementioned problems, this invention provides a multi-layer image segmentation and target contour defect detection method and device, which can effectively meet the requirements of high speed and high accuracy.
[0008] A multi-layer image segmentation and target contour defect detection method mainly includes:
[0009] S1: Input the target image to be detected and preprocess it. The preprocessing includes: image grayscale conversion, binarization, inversion, and finding the minimum outer matrix.
[0010] S2: Perform segmentation on the preprocessed image;
[0011] S3: Calculate the area of each block in the segmented image and calculate the range of the areas;
[0012] S4: Compare the range with the threshold to determine if the range is greater than the threshold. If yes, proceed to step S5. If no, determine that the target image contour is in a normal state.
[0013] S5: Determine whether the target image contour is completely segmented. If yes, the target image contour is in an abnormal state. If not, return to step S2.
[0014] Furthermore, the specific steps for preprocessing are as follows:
[0015] S11: Iterate through all the read-in images;
[0016] S12: Image grayscale processing, converting the RGB image to a grayscale image through color space conversion, and processing the grayscale image with a median filter;
[0017] S13: Perform threshold transformation on the processed image, binarize the grayscale image into a black and white image, and invert the black and white image.
[0018] S14: After inverting the image, find the contour of the target image, return the outermost boundary, find the minimum bounding matrix of the boundary, and determine whether the minimum bounding matrix satisfies the segmentation condition. If it cannot be divided equally, the width and height of the minimum bounding rectangle must be changed so that the rectangle can be divided equally.
[0019] Furthermore, the image is converted to grayscale using the following formula:
[0020]
[0021] In the formula, It is a pixel. The grayscale value after grayscale transformation. These represent the values of pixels in the red, green, and blue channels of an RGB image, respectively.
[0022] Furthermore, the binarization formula is as follows:
[0023]
[0024] In the formula, Represents the pixels in the original image The corresponding pixel value, Represents the pixel after binarization The corresponding pixel value.
[0025] Furthermore, the binarized image is inverted, and the inverted image is saved as a new image. The image is then filled using a flood fill method. The union of the filled image and the original image is calculated to obtain the filled binary image. The steps are as follows: , As shown:
[0026]
[0027]
[0028] In the formula, Represents the number of pixels after the union operation on the image. The corresponding grayscale value, Represents the pixel after binarization The corresponding pixel value, Represents the pixels after image transformation The corresponding grayscale value, This indicates that the image is inverted. This indicates that the image will be flooded with water.
[0029] Furthermore, the specific implementation process of step S14 is as follows:
[0030] S14.1: If the height of the matrix does not meet the partitioning condition, increment the height of the matrix by one and proceed to step S14;
[0031] S14.2: If the matrix width does not meet the partitioning condition, increment the matrix width by one and proceed to step S14;
[0032] S14.3: If the length and width of the matrix both satisfy the segmentation condition, then return the image contained in the smallest bounding matrix.
[0033] Furthermore, the basic steps of dividing the minimum bounding rectangle into equal parts in step S14 are shown in equation (5):
[0034]
[0035] In the formula, They represent the updated minimum outermost matrix at... The starting coordinates on the axis, the original minimum bounding matrix in The starting coordinates on the axis They represent the updated minimum outermost matrix at... The endpoint coordinates on the axis, the original minimum bounding matrix in End point coordinates on the axis Indicates the coordinates of the start and end points of the image. Indicates the coordinates of the start and end points of the image. They represent the updated minimum outermost matrix at... The starting coordinates on the axis, the original minimum bounding matrix in The starting coordinates on the axis They represent the updated minimum outermost matrix at... The endpoint coordinates on the axis, the original minimum bounding matrix in The endpoint coordinates on the axis.
[0036] Furthermore, the image segmentation process involves the following steps:
[0037] S21: Divide the image contained in the returned minimum bounding matrix along the midline of the matrix height, and stitch the lower half of the matrix to the right side of the image. At the same time, divide the stitched image into four equal-sized blocks from left to right.
[0038] S22: Divide the four matrix blocks along their respective main diagonals to divide the image into eight triangular matrices.
[0039] S23: Calculate the difference between the maximum and minimum areas, i.e., obtain the range 1, and compare it with the threshold. σ If the range is greater than this threshold σ Then, iterate through each triangular matrix, find the sixteenth bisector of the target contour, iterate through all pixels of all upper triangular matrices, determine their positional relationship with the bisector, and thus divide all upper triangular matrices into two parts; similarly, iterate through all lower triangular matrices, find the sixteenth bisector, divide the target contour into sixteen parts along the bisector, calculate the area of each part, and simultaneously calculate the range 2, comparing the range 2 with the threshold. σ If the range is still greater than the threshold, the value of the range is... σ If the condition is met, the target image contour is judged to be in an abnormal state; otherwise, the target image contour is considered to be normal, and the result is output.
[0040] Furthermore, the image segmentation formula is as follows:
[0041]
[0042]
[0043] in, This indicates the pixel position of the segmented image. Pixel value at that location, The x-coordinate is The vertical axis corresponding to the 16 equal division lines in the original graph Represents the number of pixels after the union operation on the image. The corresponding grayscale value, These represent the slope and intercept of the line, respectively.
[0044] A multi-layer image segmentation and target contour defect detection device includes: a processor and a storage device; the processor loads and executes instructions and data in the storage device to implement a multi-layer image segmentation and target contour defect detection method.
[0045] The beneficial effects of the technical solution provided by this invention are: target contour defect detection has a wide range of applications in industrial production, effectively improving detection efficiency and saving manual inspection costs. A detailed analysis of these effects is as follows:
[0046] (1) This invention proposes a multi-layer image segmentation and target contour defect detection method. The input target image is preprocessed, including image grayscale conversion, binarization, inversion, and finding the minimum bounding matrix. Thus, this invention can reduce the impact of noise on image detection by employing image processing methods such as median filtering and flooding. Furthermore, this invention can also solve the problems of segmenting images along the midline, along the diagonal, and along arbitrary straight lines by segmenting the preprocessed image.
[0047] (2) In order to compare the similarity of each block, this invention proposes a method to approximate the area of the target contour in each block by counting the number of pixels with a value greater than a threshold. The area of each block is calculated for the segmented image, and the range of the area is calculated. The range is compared with the threshold to determine whether the range is greater than the threshold. If not, the target image contour is in a normal state. Therefore, when the blocks of the target contour are small enough, if the areas of two blocks are similar, it can be said that the phase velocity of the blocks is high. Therefore, the condition of the entire target contour can be approximated by calculating the area, which effectively improves the calculation speed.
[0048] (3) This invention completes the segmentation and detection of the target contour in multiple stages. First, the target contour is divided into four parts, then into eight parts, and the detection of the eight parts is completed. It is then determined whether the conditions are met. If the conditions are met, i.e., the range is less than the threshold, then the segmentation is stopped. If the conditions are not met, i.e., the range is greater than the threshold, then it is determined whether the target image contour is completely segmented. If it is, then the target image contour is in an abnormal state. If not, then the segmentation process is performed again. The target contour is segmented into sixteen parts in the second segmentation. Compared with the traditional method of segmenting into a fixed number of parts, this invention can provide higher accuracy without increasing the time significantly, and can make more accurate judgments. Compared with the traditional method, this invention does not further subdivide the target contour when it can be judged into eight parts, saving time without affecting the accuracy and better meeting the needs of actual industrial production. Attached Figure Description
[0049] The present invention will be further described below with reference to the accompanying drawings and embodiments. In the accompanying drawings:
[0050] Figure 1 This is a flowchart of a multi-layer image segmentation and target contour defect detection method according to an embodiment of the present invention.
[0051] Figure 2 This is a diagram showing the effect of image preprocessing in an embodiment of the present invention.
[0052] Figure 3 This is a diagram showing the result after flooding in an embodiment of the present invention.
[0053] Figure 4 It is the minimum bounding matrix diagram of the target contour in the embodiments of the present invention.
[0054] Figure 5 This is a diagram showing the result of four blocks being segmented in an embodiment of the present invention.
[0055] Figure 6 This is a diagram showing the result of the four-block optimization in an embodiment of the present invention.
[0056] Figure 7 This is a diagram showing the result of dividing the object into eight equal parts in an embodiment of the present invention.
[0057] Figure 8 This is a diagram showing the result of dividing the object into sixteen equal parts in an embodiment of the present invention.
[0058] Figure 9 This is an example of the present invention: the input image of a bottle cap and the judgment result.
[0059] Figure 10 The input image and judgment result are for the bottle cap in Example 2 of this invention.
[0060] Figure 11 These are the input image and judgment result of Example 3 of the present invention.
[0061] Figure 12 These are the input image and judgment result of Example 4 of the present invention.
[0062] Figure 13 This is a schematic diagram of the hardware device working in an embodiment of the present invention. Detailed Implementation
[0063] To provide a clearer understanding of the technical features, objectives, and effects of the present invention, specific embodiments of the present invention will now be described in detail with reference to the accompanying drawings.
[0064] This invention provides a method and apparatus for multi-layer image segmentation and target contour defect detection. The main idea is to first segment the image into multiple blocks, calculate the area of each block, calculate the range of the areas, and compare the range with a threshold to determine whether the target contour is abnormal. Target contour defect detection has wide applications in industrial production, effectively improving detection efficiency and saving on manual inspection costs.
[0065] Please refer to Figure 1 , Figure 1 This is a flowchart of a multi-layer image segmentation and target contour defect detection method according to an embodiment of the present invention. It mainly consists of three parts: the first part is preprocessing the target image, which significantly affects the subsequent detection results; the second part is image segmentation; and the third part is detecting the segmented blocks and judging the overall condition of the target contour defects. Specifically, the method includes:
[0066] 1. Image preprocessing
[0067] The input image to be detected is first processed into grayscale. The grayscale transformation formula is as follows: As shown:
[0068]
[0069] In the formula, It is a pixel. The grayscale value after grayscale transformation. These represent the values of pixels in the red, green, and blue channels of an RGB image, respectively.
[0070] The image after grayscale transformation is processed using a median filter. A median filter is a non-linear filter that replaces the grayscale value of each pixel in the image with the average of the grayscale values in its neighborhood, thereby eliminating some of the noise affecting the image.
[0071] Figure 2 The image on the left shows the result of converting the target image outline to grayscale. Figure 2The image on the right shows the result after binarizing the target image contour and applying median filtering.
[0072] By setting a threshold, the image can be binarized, with pixels greater than 128 assigned a value of 255 and pixels less than 128 assigned a value of 0, as shown in formula (2). Binarized images are easier to extract features from.
[0073]
[0074] In the formula Represents the pixels in the original image The corresponding pixel value, Represents the pixel after binarization The corresponding pixel value.
[0075] The binarized image is inverted, and the inverted image is saved as a new image. Since the target contour edge information in this invention is used to detect the target contour condition, only the edge information needs to be obtained. Therefore, a flood filling method is used to fill the outside of the image to better obtain the target contour boundary. The union of the filled image and the original image is then calculated to obtain the filled binary image. The steps are as follows: , As shown:
[0076]
[0077]
[0078] In the formula This indicates that after the image is subjected to a union operation The corresponding grayscale value, Represents the pixels after image transformation The corresponding grayscale value, This indicates that the image is inverted. This indicates that the image will be flooded with water.
[0079] The result after flooding is as follows Figure 3 As shown. The image boundary is detected, and the minimum bounding rectangle of the boundary is found. The image of the minimum bounding rectangle is shown below. Figure 4 As shown. At the same time, it is determined whether the smallest bounding rectangle can be divided equally. If it cannot be divided equally, the width and height of the smallest bounding rectangle must be changed so that the rectangle can be divided equally. The basic steps are shown in equation (5).
[0080]
[0081] In the formula, and They represent the minimum outer matrix respectively. The starting and ending points on the axis; and and These represent the starting and ending points of the minimum outer matrix on the Y-axis, respectively. They represent the updated minimum outermost matrix at... The starting coordinates on the axis, the original minimum bounding matrix in The starting coordinates on the axis They represent the updated minimum outermost matrix at... The endpoint coordinates on the axis, the original minimum bounding matrix in End point coordinates on the axis Indicates the coordinates of the start and end points of the image. Indicates the coordinates of the start and end points of the image. They represent the updated minimum outermost matrix at... The starting coordinates on the axis, the original minimum bounding matrix in The starting coordinates on the axis They represent the updated minimum outermost matrix at... The endpoint coordinates on the axis, the original minimum bounding matrix in The endpoint coordinates on the axis.
[0082] The specific steps of preprocessing are as follows:
[0083] Step 11: Iterate through all the read-in images;
[0084] Step 12: Convert the RGB image to a grayscale image through color space conversion, and process the grayscale image using a median filter;
[0085] Step 13: Perform a threshold transformation on the processed image to binarize the grayscale image into a black and white image. Then, perform an opening operation on the black and white image.
[0086] Step 14: Locate the image contour, return to the outermost boundary, find the minimum bounding matrix of the boundary, and determine whether the minimum bounding matrix satisfies the segmentation condition.
[0087] Step 14.1: If the height of the matrix does not meet the partitioning condition, increment the height of the matrix by one and proceed to Step 14;
[0088] Step 14.2: If the matrix width does not meet the partitioning condition, increase the matrix width by one and proceed to Step 14;
[0089] Step 14.3: If the length and width of the matrix both satisfy the segmentation condition, then return the image contained in the smallest bounding matrix.
[0090] 2. Image segmentation, range and threshold determination, and determination results.
[0091] After image preprocessing, the image content contained in the minimum bounding matrix of the image edges is saved. The image is then segmented. First, the target contour is divided into four equal parts along the axis of symmetry. The result after segmentation is as follows: Figure 5 As shown.
[0092] Convert the image into a two-dimensional array. Divide this array into four separate arrays, each containing the contents of the top-left, top-right, bottom-left, and bottom-right portions of the original array. In each individual array, set the values of the other three portions to 0, leaving the contents of the current block unchanged. At this point, the image can be divided into four equal-sized blocks. For easier subsequent segmentation, rotate the last three blocks so that all four blocks face the same direction. Divide each block along its main diagonal into two triangular matrices, resulting in eight triangular matrices in total.
[0093] To improve detection accuracy, the target contour needs to be further segmented into its constituent blocks. Simultaneously, to improve efficiency and reduce image types, the image types can be initially... Figure 5 The blocks in the image are adjusted to face the same direction: the second block is rotated 90 degrees counterclockwise, the third block is rotated 90 degrees clockwise, and the fourth block is rotated 180 degrees clockwise. The resulting image after rotation is shown below. Figure 6 As shown. Figure 6 Each target contour block in the image is further subdivided along the main diagonal. The result of the secondary subdivision is as follows: Figure 7 As shown.
[0094] Calculate the area of each block, calculate the range of the areas, and compare the range with the threshold σ. If the range is less than the threshold, the calculation is performed. If the difference between the segments is small, meaning there are no segments with abnormal edges, then the target contour can be judged to be in a normal state, and no further segmentation is needed; the result can be output directly. If the range is greater than the threshold... This indicates that the target contour edge has significant differences in certain blocks, thus classifying the target contour as an abnormal state. Further segmentation of each block of the target contour is then necessary. By dividing each block into sixteen parts along the four-part dividing lines, the range 2 is calculated. The condition of the target contour is then re-analyzed, and the range 2 is compared with a threshold to output the judgment result. The segmentation result of the sixteen blocks is as follows: Figure 8 As shown. The specific segmentation process is as follows:
[0095] Find the line containing the sixteenth division point of the target contour, and further divide the triangular matrix along this line. For the upper half of the image, if a pixel is located above the image, retain it; if a pixel is located below the line, set that pixel to 0. The method is as follows: As shown, conversely, the lower half of the image can be segmented. By performing the above operation on each half, the original image can be divided into 16 equal-sized blocks, thus completing the image segmentation.
[0096]
[0097]
[0098] in, This indicates the pixel position of the segmented image. Pixel value at that location, The x-coordinate is The vertical axis corresponding to the 16 equal division lines of the original graph, and These represent the slope and intercept of the line, respectively.
[0099] In summary, the image segmentation steps can be represented as follows:
[0100] Step 21: Divide the image contained in the returned minimum bounding matrix along the midline of the matrix height, and stitch the lower half of the matrix to the right side of the image. At the same time, divide the stitched image into four equal-sized blocks from left to right.
[0101] Step 22: Divide the four matrix blocks along their respective main diagonals to divide the image into eight triangular matrices.
[0102] Step 23: Calculate the difference between the maximum and minimum areas, which is the range 1. Compare the range 1 with the threshold. σ If the range of the block area is greater than this threshold σ Then, iterate through each triangular matrix to find the sixteenth bisector of the target contour. Iterate through all pixels in all upper triangular matrices, determining their positional relationship with the bisector, thus dividing all upper triangular matrices into two parts. Similarly, iterate through all lower triangular matrices, finding the sixteenth bisector, dividing the target contour into sixteen parts along the bisector, calculating the area of each part, and simultaneously calculating the second range. Compare the second range with the threshold. σ If the difference between the two surfaces is still greater than the threshold, the target contour is judged to be in an abnormal state; otherwise, the target contour is considered to be in a normal state, and the judgment result of the target contour is output.
[0103] In this embodiment, the above method is used to segment and detect the collected bottle caps (i.e., instances of the target contour). The following is a result image of the detection of some bottle caps.
[0104] In Example 1, the input is a standard bottle cap. During the segmentation process, the bottle cap already meets the threshold condition when it is first segmented into four pieces. The calculated area difference of the bottle cap is 352, while the threshold for four-piece segmentation is set to 750. Since the threshold setting for four-piece segmentation is relatively strict, if it is less than the threshold, it largely indicates that the bottle cap conforms to the standard. Therefore, no further segmentation is needed for alignment, and it can be directly judged as a normal bottle cap. The input image and judgment result of Example 1 are as follows. Figure 9 As shown.
[0105] In Example 2, the bottle cap has a large pulling range. Because the range calculated when it's divided into four pieces is large (6358 for all four pieces aligned), and because the pull tab in the upper right piece is pulled open, its edge is wider than other pieces, resulting in a larger area, a second division is performed after the first. Even when divided into eight pieces, it still concludes that it's an abnormal bottle cap. Therefore, it needs to be divided into sixteen pieces for a third division. The result of the third division is compared against a threshold, and the conclusion is still that it's an abnormal bottle cap. Therefore, the final output is that the bottle cap is an abnormal bottle cap. The input and judgment results for Example 2 are as follows: Figure 10 As shown.
[0106] In Example 3, due to the shooting angle, the upper right corner of the image is tilted. This causes the area of the upper right block to be smaller than the areas of the other three blocks during the area difference calculation, resulting in a calculated value of 1930. Therefore, it needs to be divided into eight blocks. After division, the result is compared with the threshold, and it is found to be less than the threshold. Therefore, it can be judged as a normal bottle cap. In this experiment, the bottle cap was divided three times to reach the conclusion that it is a normal bottle cap. The input image and result image of Example 3 are shown below. Figure 11 As shown.
[0107] In Example 4, the pull tab on the bottle cap has been pulled open, but because it is not completely separated but rather adhered to the cap, its edges appear approximately circular. Therefore, after the first segmentation, the calculated area difference is 1038, which is not significantly different from the threshold. Subsequent second and third segmentations determine that it is a defective bottle cap. The input image and judgment result for Example 4 are shown below. Figure 12 As shown.
[0108] Please see Figure 13 , Figure 13 This is a schematic diagram of the hardware device in operation according to an embodiment of the present invention. The hardware device specifically includes: a multi-layer image segmentation and target contour defect detection device 401, a processor 402, and a storage device 403.
[0109] A multi-layer image segmentation and target contour defect detection device 401: The multi-layer image segmentation and target contour defect detection device 401 implements the multi-layer image segmentation and target contour defect detection method.
[0110] Processor 402: The processor 402 loads and executes the instructions and data in the storage device 403 to implement the multi-layer image segmentation and target contour defect detection method.
[0111] Storage device 403: The storage device 403 stores instructions and data; the storage device 403 is used to implement the multi-layer image segmentation and target contour defect detection method.
[0112] The beneficial effects of this invention are:
[0113] (1) This invention proposes a multi-layer image segmentation and target contour defect detection method. Image processing methods such as median filtering and flood filling are employed to reduce the impact of noise on image detection performance. Simultaneously, this invention also proposes an image segmentation method that addresses the problems of segmenting images along the midline, along the diagonal, and along arbitrary straight lines. To compare the similarity of different blocks, this invention proposes a method that approximates similarity using area. When the blocks of the target contour are sufficiently small, if the areas of two blocks are similar, it indicates a high degree of similarity between the blocks. Therefore, the condition of the entire target contour can be approximated by calculating the area.
[0114] (2) Compared with previous defect detection methods, the solution proposed in this invention has a faster detection speed. The detection time for a single target contour can be shortened to less than 40ms, meeting the needs of actual industry. To improve the segmentation speed, this invention proposes a method of rotating the segmented image to ensure that the image types of each block are consistent, reducing the types of images to be segmented, thereby improving segmentation efficiency. In addition, this invention also proposes a method of approximating the area of the target contour in each block by counting the number of pixels with a value greater than a threshold, which effectively improves the computation speed.
[0115] (3) This invention completes the segmentation and detection of the target contour in multiple stages. First, the target contour is divided into four parts, then into eight parts, and the detection of the eight parts is completed to determine whether the conditions are met. If the conditions are met, the segmentation is not continued. If the conditions are not met, the target contour is divided into sixteen parts. Compared with the traditional method of segmenting into a fixed number of parts, this invention can provide higher accuracy without increasing the time significantly, and can make more accurate judgments. Compared with the traditional method, this invention does not further subdivide the case where eight parts are sufficient for judgment, saving time without affecting the accuracy and better meeting the needs of actual industrial production.
[0116] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for multi-layer image segmentation and target contour defect detection, characterized in that: include: S1: Input the target image to be detected and preprocess it. The preprocessing includes: image grayscale conversion, binarization, inversion, and finding the minimum outer matrix. S2: Perform segmentation on the preprocessed image; S3: Calculate the area of each block in the segmented image and calculate the range of the areas; S4: Compare the range with the threshold to determine if the range is greater than the threshold. If yes, proceed to step S5. If no, determine that the target image contour is in a normal state. S5: Determine whether the target image contour is completely segmented. If yes, the target image contour is in an abnormal state. If no, return to step S2. In step S2, the image segmentation process is as follows: S21: Divide the image contained in the returned minimum bounding matrix along the midline of the matrix height, and stitch the lower half of the matrix to the right side of the image. At the same time, divide the stitched image into four equal-sized blocks from left to right. S22: Divide the four matrix blocks along their respective main diagonals to divide the image into eight triangular matrices. S23: Calculate the difference between the maximum and minimum areas, i.e., obtain the range 1, and compare it with the threshold. σ If the range is greater than this threshold σ Then, iterate through each triangular matrix, find the sixteenth bisector of the target contour, iterate through all pixels of all upper triangular matrices, determine their positional relationship with the bisector, and thus divide all upper triangular matrices into two parts; similarly, iterate through all lower triangular matrices, find the sixteenth bisector, divide the target contour into sixteen parts along the bisector, calculate the area of each part, and simultaneously calculate the range 2, comparing the range 2 with the threshold. σ If the range is still greater than the threshold, the value of the range is... σ If the condition is met, the target image contour is judged to be in an abnormal state; otherwise, the target image contour is considered to be normal, and the result is output.
2. The method for multi-layer image segmentation and target contour defect detection as described in claim 1, characterized in that: In step S1, the specific implementation steps of preprocessing are as follows: S11: Iterate through all read-in images; S12: Image grayscale processing, converting the RGB image to a grayscale image through color space conversion, and processing the grayscale image with a median filter; S13: Perform threshold transformation on the processed image, binarize the grayscale image into a black and white image, and invert the black and white image. S14: After inverting the image, find the contour of the target image, return the outermost boundary, find the minimum bounding matrix of the boundary, and determine whether the minimum bounding matrix satisfies the segmentation condition. If it cannot be divided equally, the width and height of the minimum bounding rectangle must be changed so that the rectangle can be divided equally.
3. The method for multi-layer image segmentation and target contour defect detection as described in claim 2, characterized in that: In step S12, the image is converted to grayscale using the following formula: In the formula, It is a pixel. The grayscale value after grayscale transformation. These represent the values of pixels in the red, green, and blue channels of an RGB image, respectively.
4. The method for multi-layer image segmentation and target contour defect detection as described in claim 2, characterized in that: In step S13, the binarization formula is: In the formula, Represents the pixels in the original image The corresponding pixel value, Represents the pixel after binarization The corresponding pixel value.
5. The method for multi-layer image segmentation and target contour defect detection as described in claim 2, characterized in that: In step S13, the binarized image is inverted and saved as a new image. The image is then filled with water using the flood fill method. The union of the filled image and the original image is calculated to obtain the filled binary image. The steps are as follows: , As shown: In the formula, Represents the number of pixels after the union operation on the image. The corresponding grayscale value, Represents the pixel after binarization The corresponding pixel value, Represents the pixels after image transformation The corresponding grayscale value, This indicates that the image is inverted. This indicates that the image will be flooded with water.
6. The method for multi-layer image segmentation and target contour defect detection as described in claim 2, characterized in that: The specific implementation process of step S14 is as follows: S14.1: If the height of the matrix does not meet the partitioning condition, increment the height of the matrix by one and proceed to step S14; S14.2: If the matrix width does not meet the partitioning condition, increment the matrix width by one and proceed to step S14; S14.3: If the length and width of the matrix both satisfy the segmentation condition, then return the image contained in the smallest bounding matrix.
7. The method for multi-layer image segmentation and target contour defect detection as described in claim 6, characterized in that: The basic steps for dividing the smallest bounding rectangle into equal parts in step S14 are shown in equation (5): In the formula, They represent the updated minimum outermost matrix at... The starting coordinates on the axis, the original minimum bounding matrix in The starting coordinates on the axis They represent the updated minimum outermost matrix at... The endpoint coordinates on the axis, the original minimum bounding matrix in The endpoint coordinates on the axis Indicates the coordinates of the start and end points of the image. Indicates the coordinates of the start and end points of the image. They represent the updated minimum outermost matrix at... The starting coordinates on the axis, the original minimum bounding matrix in The starting coordinates on the axis These represent the updated minimum outermost matrix at... The endpoint coordinates on the axis, the original minimum bounding matrix in The endpoint coordinates on the axis.
8. The method for multi-layer image segmentation and target contour defect detection as described in claim 1, characterized in that: In step S2, the image segmentation formula is: in, This indicates the pixel position of the segmented image. Pixel value at that location, The x-coordinate is The vertical coordinate corresponding to the 16 equal division lines in the original figure Represents the number of pixels after the union operation on the image. The corresponding grayscale value, These represent the slope and intercept of the line, respectively.
9. A multi-layer image segmentation and target contour defect detection device, characterized in that: include: A processor and a storage device; the processor loads and executes instructions and data in the storage device to implement the multi-layer image segmentation and target contour defect detection method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Binarized contour detection system and method thereof
CN109870117A
Microcrack detection method, device and system and storage medium
CN113822890A