Metal part surface quality detection method based on image processing
Through image processing technology, calculation of pixel gradient values, cluster screening, ellipse fitting and inter-class variance analysis, the problem of inaccurate surface detection results of metal parts is solved, and high-precision defect segmentation and quality inspection are achieved.
Patent Information
- Application Number
- CN202411918091.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-25
- Publication Date
- 2025-01-24
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
When detecting the surface quality of metal parts, it is difficult to accurately deal with the inconsistency of local bubble reflection and the depth of the cavity, resulting in inaccurate detection results.
Adopt the surface quality detection method based on image processing, by calculating the gradient values of each pixel point, the clustering analysis cluster is screened, the maximum internal oval is fitted, and its long axis and short shafts are adjusted. Various analysis, accurate identification and division of defective areas.
It improves the segmentation accuracy of defective areas, reduces noise interference, and enhances the reliability and accuracy of detection results. It is especially suitable for automated detection of complex surface quality.
Smart Images

Figure CN119359713A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of metal part detection, and more specifically, to a metal part surface quality detection method based on image processing. Background Art
[0002] With the continuous development of modern manufacturing, the detection of metal parts surface quality has become a key link in the production process. The surface quality of metal parts directly affects their performance, service life and appearance. Therefore, how to efficiently and accurately detect the surface quality of metal parts has become an important issue in the manufacturing industry.
[0003] The application of iterative threshold segmentation algorithm in image surface detection is mainly due to its advantages in image segmentation. Image surface detection aims to identify and extract the surface or edge information of objects in the image. The algorithm optimizes the threshold through an iterative process, so that the image can more accurately distinguish the foreground and background in each round of segmentation, thereby better capturing the surface features in the image.
[0004] The existing Chinese patent application document with publication number CN117764992A discloses a plastic pipe quality detection method based on image processing, including: using an iterative threshold segmentation algorithm to obtain a segmentation threshold sequence for the pipe grayscale image, recording the minimum and maximum data as the first threshold and the second threshold, respectively, to obtain a target connected domain and a main internal connected domain therein, obtaining the directional similarity and extended gradient similarity of the target connected domain, combining the circularity of the target connected domain and the main internal connected domain, obtaining the possibility that the target connected domain is a concave defect, thereby obtaining the optimal segmentation threshold, and judging whether the plastic pipe is qualified according to the optimal segmentation threshold.
[0005] However, the surface of metal parts is affected by many factors such as local bubble reflections and inconsistent depths of voids. If traditional iterative threshold segmentation is still used to detect the surface of metal parts, inaccurate extraction results will result. Summary of the invention
[0006] In order to solve the problem of inaccurate metal part surface detection results, the present invention proposes a metal part surface quality detection method based on image processing.
[0007] The present invention discloses a metal part surface quality detection method based on image processing, comprising: obtaining a preprocessed metal part surface grayscale image; calculating the gradient value of each pixel point, taking the pixel points with non-zero gradient values as marking points, clustering all marking points and screening to obtain a number of clusters to be analyzed, and taking the minimum circumscribed rectangle of the clusters to be analyzed as the area to be analyzed; taking any area to be analyzed as a target area, obtaining the maximum inscribed ellipse of the target area, calculating the preference degree of the ellipse, iteratively adjusting the major axis and the minor axis of the ellipse, traversing to obtain the preference degrees of ellipses of different sizes, and taking the ellipse corresponding to the maximum value of the preference degree as the defect area in the target area; iteratively adjusting the edge points of the target area in a preset direction, and calculating the inter-class variance of the defect area, when the inter-class variance is the largest, obtaining the area to be segmented, and completing the metal part surface quality detection according to the area and number of the area to be segmented.
[0008] First, by calculating the gradient value of each pixel and clustering it, the potential defect area can be accurately marked. Then, by fitting the maximum inscribed ellipse and adjusting the major and minor axes of the ellipse, the positioning of the defect area is further optimized to ensure that the shape and position of the defect can be accurately reflected. Next, the boundary of the area to be segmented is adjusted using the inter-class variance method to find the most representative part in the defect areas of different sizes and shapes. Finally, by combining the area and number of regions, the quality inspection of the metal surface is completed. It not only improves the segmentation accuracy of the defect area, but also effectively reduces noise interference, enhances the reliability and accuracy of the detection results, and is particularly suitable for the automated detection of complex surface quality.
[0009] Preferably, the preprocessing includes: using histogram equalization and contrast stretching to enhance the contrast and brightness of the grayscale image of the metal part surface, using a specific light source and optical system to reduce the reflectiveness of the metal part surface, and combining wavelet decomposition and filtering algorithms to denoise and enhance the grayscale image of the metal part surface.
[0010] Histogram equalization and contrast stretching enhance the contrast and brightness of the image, making the details of the metal surface more visible, especially in the case of uneven lighting conditions or flat grayscale distribution, which can effectively highlight the defective area. The specific light source and optical system effectively reduce the reflection effect of the metal surface, avoid the artifact interference caused by reflected light, and thus more realistically reflect the surface characteristics.
[0011] Preferably, the cluster to be analyzed is a cluster having a number of pixels greater than a preset number of pixels within the cluster.
[0012] Preferably, the degree of preference satisfies the relationship: , Represents an ellipse The degree of preference, Represents the pixel point in the ellipse The Euclidean distance from the center of the ellipse, Represents an ellipse Medium pixel The gradient value of Represents an ellipse The total number of pixels in Represents an exponential function.
[0013] The gradient value reflects the significance of the edge in the image, while the distance represents the geometric relationship between the pixel and the center of the ellipse. The degree of optimization can make the ellipse fitting process more accurately identify defect areas with obvious boundaries and strong features. The higher the degree of optimization, the better the fit between the ellipse and the defect area, and the more accurately the morphology of the defect area can be extracted.
[0014] Preferably, the preferred degree also satisfies the relationship: , Represents an ellipse The degree of preference, Represents the pixel point in the ellipse The Euclidean distance from the center of the ellipse, Represents an ellipse Medium pixel The gradient value of Represents pixel Neighborhood pixels The gradient value of Represents an ellipse The total number of pixels in Represents an exponential function.
[0015] By comprehensively considering the gradient value of each pixel, the Euclidean distance from the center of the ellipse, and the gradient value of its neighborhood pixels, the sensitivity of the ellipse fitting process to local features is enhanced. This calculation method can not only evaluate the geometric matching degree between the ellipse and the defect area, but also effectively capture the edge information around the pixel, thereby improving the boundary recognition accuracy of the defect area. Specifically, the introduction of neighborhood gradients makes the optimization degree more detailed in reflecting the local changes and texture information in the image, which can effectively reduce the interference of background noise and weak edges on the ellipse fitting results, and enhance the ellipse's ability to fit the real defect area.
[0016] Preferably, the method of obtaining ellipses of different sizes includes: taking half of the length of the largest circumscribed rectangle as the major axis of the ellipse, taking half of the width of the largest circumscribed rectangle as the minor axis of the ellipse, iterating the major axis and the minor axis from large to small according to a preset iteration step, stopping the iteration when the major axis or the minor axis iterates to a preset length, and obtaining major axes of several sizes and minor axes of several sizes; selecting a major axis of any size and a minor axis of any size to combine to obtain an ellipse, and traversing the combination process to obtain ellipses of different sizes.
[0017] First, the size of the maximum circumscribed rectangle is used to ensure that the ellipse can cover the target area. Then, the axis length is gradually reduced through iteration to flexibly adapt to defects or feature areas of different scales, ensuring a good fit for target objects of various sizes. This helps to obtain more accurate fitting results when processing complex shapes and improves the accuracy of defect detection or image segmentation.
[0018] Preferably, the preset direction is an 8-neighborhood direction.
[0019] Preferably, the method of completing the surface quality inspection of metal parts based on the area and number of the areas to be divided includes: taking a weighted sum of the areas and numbers of the areas to be divided, and normalizing the result of the weighted summation to obtain a maintenance priority; retaining metal parts with a maintenance priority greater than a preset maintenance threshold as defective parts, and when the ratio of the number of defective parts to the total number of metal parts exceeds the defect rate threshold, generating and sending an alarm signal to complete the surface quality inspection of metal parts.
[0020] Beneficial effects of the present invention: The present invention first enhances the grayscale contrast and brightness of the metal surface and removes noise at the same time, providing clear image data for subsequent processing. Then, the gradient information of each pixel in the image is calculated, and the areas where defects may exist are screened out through a clustering algorithm. After ellipse fitting and optimization, these areas can accurately identify the shape and location of the defects. By performing detailed edge adjustment and inter-class variance analysis on the target area, defects and normal areas can be accurately distinguished, and efficient defect segmentation and evaluation can be achieved. Finally, a comprehensive analysis is performed based on the area and number of the areas to be segmented, and an alarm signal is generated in combination with the defect rate threshold to quickly identify whether there are quality problems with metal parts, optimize the defect detection process in the production process, and improve production efficiency and the reliability of product quality control. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] By reading the following detailed description with reference to the accompanying drawings, the above and other objects, 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-limiting manner, and the same or corresponding reference numerals represent the same or corresponding parts, wherein: Figure 1It is a flow chart of a metal parts surface quality detection method based on image processing according to an embodiment of the present invention. DETAILED DESCRIPTION
[0022] 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.
[0023] 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.
[0024] The present invention provides a metal part surface quality detection method based on image processing. Figure 1 As shown, the metal part surface quality detection method based on image processing includes steps S1 to S4, which are described in detail below.
[0025] S1, obtaining a grayscale image of the metal part surface after preprocessing.
[0026] In one embodiment, an industrial camera is used to capture images of the surface of a metal part. First, it is necessary to ensure that the camera's resolution and focal length are adapted to the surface details of the metal part, so as to accurately capture surface textures, scratches, depressions and other features. After image acquisition, the acquired color image is grayed to obtain an initial grayscale image of the metal part surface. By converting the RGB value of each pixel in the image into a single grayscale value, the image is made more concise and the contrast of the surface texture is highlighted, which is convenient for subsequent image analysis and defect detection. Graying can not only reduce the amount of calculation, but also enhance the features of the image, so that the algorithm can more efficiently extract and analyze subtle changes and defects on the metal surface during subsequent surface defect detection, quality assessment or automated classification.
[0027] The initial metal part surface grayscale image is preprocessed to obtain the metal part surface grayscale image. The preprocessing includes using histogram equalization and contrast stretching to enhance the contrast and brightness of the metal part surface grayscale image, using a specific light source and optical system to reduce the reflectiveness of the metal part surface, and combining wavelet decomposition and filtering algorithms to denoise and enhance the metal part surface grayscale image.
[0028] S2, calculate the gradient value of each pixel point, take the pixel points with non-zero gradient values as marking points, cluster all marking points and screen to obtain a number of clusters to be analyzed, and take the minimum circumscribed rectangle of the clusters to be analyzed as the area to be analyzed.
[0029] It should be noted that, under normal circumstances, the pixel distribution on the surface of metal parts is uniform, and there is no obvious difference in brightness or color. Therefore, in the grayscale image of the metal surface, the gradient value of the normal area is close to 0, which means that there is no change in the grayscale value. However, when bubbles, voids or other defects appear on the surface, the grayscale value of the metal surface will change, resulting in a gradient value greater than 0 in the local area. Based on this feature, by traversing each pixel point in the grayscale image of the metal surface, calculating its gradient value, and extracting the pixel points with a gradient value greater than 0. In this way, the area containing defects can be effectively segmented, thereby reducing the amount of calculation in subsequent processing and focusing on analyzing the parts that may have defects.
[0030] In one embodiment, a clustering algorithm is used to cluster the marked points to obtain a plurality of clusters, and the clusters are screened to obtain clusters to be analyzed, where the clusters to be analyzed are clusters in which the number of pixels in the clusters is greater than a preset number of pixels.
[0031] In the cluster analysis results, if the number of suspected defective pixels in a cluster is less than 3, it is considered that the pixel changes in the cluster may be caused by noise rather than real defects, where the number of pixels less than 3 is an empirical value that can be set by technicians in this field. Therefore, in this case, the cluster can be discarded to avoid misjudging noise as a defect and ensure the accuracy of subsequent analysis results.
[0032] The minimum bounding rectangle of the cluster to be analyzed is taken as the area to be analyzed.
[0033] S3, obtain the maximum inscribed ellipse of the target area, calculate the optimization degree of the ellipse, iteratively adjust the major axis and minor axis of the ellipse, traverse to obtain the optimization degrees of ellipses of different sizes, and take the ellipse corresponding to the maximum optimization degree as the defect area in the target area.
[0034] It should be noted that, since bubbles or voids usually appear in a circular or elliptical shape on the surface of metal parts, the boundary of the defect can be clearly identified by fitting the edge of the defect (i.e., a circular or elliptical outline) in the target area.
[0035] In one embodiment, the preference level satisfies the relationship: , Represents an ellipse The degree of preference, Represents the pixel point in the ellipse The Euclidean distance from the center of the ellipse, Represents an ellipse Medium pixel The gradient value of Represents an ellipse The total number of pixels in Represents an exponential function.
[0036] Iteratively adjust the major axis and minor axis of the ellipse, and traverse to obtain ellipses of different sizes, wherein obtaining ellipses of different sizes includes: taking half of the length of the largest circumscribed rectangle as the major axis of the ellipse, taking half of the width of the largest circumscribed rectangle as the minor axis of the ellipse, iterating the major axis and the minor axis from large to small according to a preset iteration step, stopping the iteration when the major axis or the minor axis iterates to a preset length, and obtaining major axes of several sizes and minor axes of several sizes; optionally combining a major axis of one size and a minor axis of one size to obtain an ellipse, and traversing the combination process to obtain ellipses of different sizes.
[0037] For example, the length and width of the minimum circumscribed rectangle are 32 and 16 respectively, then the major axis of the initial ellipse is 16, the minor axis is 8, the iteration step is set to 2, the iteration stop condition of the major axis is that the major axis reaches one-quarter of its own length, and the iteration stop condition of the minor axis is that the minor axis reaches one-quarter of its own length, that is, the iterative lengths of the major axis are 14, 12, 10, 8, 6 and 4, and the iterative lengths of the minor axis are 6, 4 and 2. The major axis and the minor axis are combined in pairs to obtain ellipses of different sizes, so as to calculate the preferred degrees corresponding to ellipses of different sizes, and the ellipse corresponding to the maximum preferred degree is taken as the defect area in the target area.
[0038] In one embodiment, the preference also satisfies the relationship: , Represents an ellipse The degree of preference, Represents the pixel point in the ellipse The Euclidean distance from the center of the ellipse, Represents an ellipse Medium pixel The gradient value of Represents pixel Neighborhood pixels The gradient value of Represents an ellipse The total number of pixels in Represents an exponential function.
[0039] S4, iteratively adjust the edge points of the target area in the preset direction, and calculate the inter-class variance of the defect area. When the inter-class variance is the largest, the area to be segmented is obtained, and the surface quality inspection of the metal part is completed according to the area and number of the area to be segmented.
[0040] It should be noted that although the bubble or void defect area on the surface of the metal part has been determined through image processing, it is still difficult to accurately segment the defect location using the iterative threshold segmentation method directly. This is because the grayscale values of most pixels in the defect area are relatively consistent, and there is no significant grayscale difference with the surrounding normal area. Therefore, in order to better segment the defect area, it is necessary to appropriately expand the range of the defect area to include some normal areas. Doing so can increase the grayscale difference of the defect area, making it easier to effectively segment the defect area and improve the accuracy of the segmentation result.
[0041] In one embodiment, the edge points of the target area in a preset direction are iteratively adjusted, and the preset direction is an 8-neighborhood direction. The inter-class variance of the defect area is calculated at each traversal, and when the inter-class variance is the largest, the area to be segmented is obtained.
[0042] The area and number of the segmented regions are weightedly summed, and the result of the weighted summation is normalized to obtain the maintenance priority; the metal parts with maintenance priority greater than the preset maintenance threshold are retained as defective parts. When the ratio of the number of defective parts to the total number of metal parts exceeds the defect rate threshold, an alarm signal is generated and sent to complete the surface quality inspection of the metal parts.
[0043] 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.
[0044] 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. A metal parts surface quality detection method based on image processing, characterized in that: include: Obtaining a grayscale image of the metal part surface after preprocessing; Calculate the gradient value of each pixel point, take the pixel points with non-zero gradient value as the marking point, cluster all the marking points and screen to obtain a number of clusters to be analyzed, and take the minimum circumscribed rectangle of the clusters to be analyzed as the area to be analyzed; Take any area to be analyzed as the target area, obtain the maximum inscribed ellipse of the target area, calculate the optimization degree of the ellipse, iteratively adjust the major axis and minor axis of the ellipse, traverse to obtain the optimization degrees of ellipses of different sizes, and take the ellipse corresponding to the maximum optimization degree as the defect area in the target area; Iteratively adjust the edge points of the target area in the preset direction and calculate the inter-class variance of the defective area. When the inter-class variance is the largest, the area to be segmented is obtained, and the surface quality inspection of the metal part is completed according to the area and number of the area to be segmented.
2. The metal parts surface quality detection method based on image processing according to claim 1 is characterized in that: The pre-processing comprises: Histogram equalization and contrast stretching are used to enhance the contrast and brightness of the grayscale image on the metal surface. A specific light source and optical system are used to reduce the reflectiveness of the metal surface. Wavelet decomposition and filtering algorithms are used to denoise and enhance the grayscale image on the metal surface.
3. The metal parts surface quality detection method based on image processing according to claim 1 is characterized in that: The cluster to be analyzed is a cluster in which the number of pixels in the cluster is greater than a preset number of pixels.
4. The metal parts surface quality detection method based on image processing according to claim 1 is characterized in that: The preference degree satisfies the relationship: , Represents an ellipse The degree of preference, Represents the pixel point in the ellipse The Euclidean distance from the center of the ellipse, Represents an ellipse Medium pixel The gradient value of Represents an ellipse The total number of pixels in Represents an exponential function.
5. The metal parts surface quality detection method based on image processing according to claim 1 is characterized in that: The preference also satisfies the relationship: , Represents an ellipse The degree of preference, Represents the pixel point in the ellipse The Euclidean distance from the center of the ellipse, Represents an ellipse Medium pixel The gradient value of Represents pixel Neighborhood pixels The gradient value of Represents an ellipse The total number of pixels in Represents an exponential function.
6. The metal parts surface quality detection method based on image processing according to claim 1 is characterized in that: The obtaining of ellipses of different sizes comprises: Taking half of the length of the largest circumscribed rectangle as the major axis of the ellipse, taking half of the width of the largest circumscribed rectangle as the minor axis of the ellipse, iterating the major axis and the minor axis from large to small according to a preset iteration step, stopping the iteration when the major axis or the minor axis iterates to a preset length, and obtaining major axes of several sizes and minor axes of several sizes; An ellipse is obtained by combining a major axis of any size and a minor axis of any size, and ellipses of different sizes are obtained by traversing the combination process.
7. The metal parts surface quality detection method based on image processing according to claim 1 is characterized in that: The preset direction is an 8-neighborhood direction.
8. The metal parts surface quality detection method based on image processing according to claim 1 is characterized in that: The metal part surface quality inspection according to the area and number of the areas to be segmented includes: Perform weighted summation on the area and number of the segmented regions, and normalize the weighted summation result to obtain the maintenance priority; The metal parts with a maintenance priority greater than the preset maintenance threshold are defective parts. When the ratio of the number of defective parts to the total number of metal parts exceeds the defect rate threshold, an alarm signal is generated and sent to complete the surface quality inspection of the metal parts.
Citation Information
Patent Citations
Plastic pipe quality detection method based on image processing
CN117764992A
Gluing sensor adhesive tape detection teaching method
CN110068274A
Zipper cloth tape defect detection method based on artificial intelligence
CN115222709A
Perovskite cell surface coating film detection method and system based on machine vision
CN117392469A
Power adapter quality detection method based on image features
CN117495849A
Cited By
Storage tank body defect detection method and system based on image processing
CN120318257A
Shaft part forging forming monitoring method and system
CN120656006A
A method and system for monitoring the forging of a shaft part
CN120656006B
Plate spraying effect detection method and system based on image processing
CN121190465A
Steel plate hole automatic identification method and system based on multi-model fusion
CN121686107A