Steel surface scratch detection method based on machine vision
By using machine vision technology, combined with Gaussian function fitting and geometric morphology features, the problems of accuracy and efficiency in steel surface scratch detection have been solved, and efficient scratch information extraction under complex backgrounds has been achieved.
Patent Information
- Application Number
- CN202510059924.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-15
- Publication Date
- 2025-11-04
- Estimated Expiration
- 2045-01-15
AI Technical Summary
Existing technologies are inefficient and susceptible to subjective factors in detecting scratches on steel surfaces, making it difficult to accurately obtain key information about scratches in complex environments.
A machine vision-based detection method is adopted to acquire images of the steel surface through a camera, perform preprocessing to suppress background texture, fit gray-level gradient data using a Gaussian function, and combine geometric features and adaptive threshold segmentation to accurately locate the scratch edge and calculate its length, width and area.
It improves the accuracy and efficiency of scratch detection in complex backgrounds, ensures accurate acquisition of scratch information, and reduces false detections and missed detections.
Smart Images

Figure CN119991593B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of image processing, and in particular to a steel surface scratch detection method based on machine vision. BACKGROUND
[0002] In modern manufacturing, the quality of the steel surface directly affects the performance and reliability of the final product. Traditional defect detection methods rely on manual inspection, which is low in efficiency and easily affected by subjective factors, making it difficult to ensure consistency and accuracy. With the development of machine vision technology, vision-based automated detection systems have gradually become the mainstream method for steel surface defect detection.
[0003] In the prior art, adaptive image processing or image filtering algorithms are often used for scratch detection. For example, the patent with publication number CN117197138B discloses using the positional relationship characteristics of the shooting angle and the heat dissipation hole to realize adaptive changes of the matching template in the template matching process, thereby improving the accuracy and robustness of the scratch on the computer host shell. The patent with publication number CN115690105B discloses obtaining the surface defect probability of the milling cutter grayscale image according to the calculated surface roughness complexity factor in the sub-image, and detecting the milling cutter surface scratch according to the surface defect probability. The patent with publication number CN115359044B discloses obtaining the optimal enhancement graph by filtering the frequency spectrum graph through the low-frequency gain coefficient, high-frequency gain coefficient, cutoff frequency, and other data of the grayscale image.
[0004] Based on the length, width, and area of the scratch on the planar image, the key information must accurately obtain the scratch edge position. This work is particularly heavy when the planar image is taken with uneven texture and uneven care in Beijing. Therefore, developing an efficient and simple image processing algorithm is a key technical challenge in this field. SUMMARY
[0005] The technical problem to be solved by the present application is to solve the problems existing in the prior art in the background art, and to provide a steel surface scratch detection method based on machine vision.
[0006] The technical solution adopted by the present application to solve the technical problem is: a steel surface scratch detection method based on machine vision, comprising the following steps:
[0007] S1, obtaining a steel surface image through a camera;
[0008] S2, preprocessing the steel surface image obtained in step S1 to obtain a scratch structure region;
[0009] S3, fitting the horizontal direction gray scale gradient data of the image by using Gaussian function: the horizontal direction gray scale value variation law of the image is described by the horizontal direction gradient of the image, the horizontal direction gradient of the image is calculated by using first-order central difference, and the calculation formula is as follows:
[0010] (1)
[0011] In formula (1), is the gray scale gradient value of the horizontal direction i-th column, and are the i-th column and the j-th column in the same horizontal direction respectively;
[0012] The position information of the scratch is judged by the fitted Gaussian curve;
[0013] S4, the horizontal edge position and the horizontal center point position of the scratch are judged by the fitted Gaussian curve;
[0014] S5, the horizontal direction scratch edge position of the detected scratch region is corrected, and the calculation formula is as follows:
[0015]
[0016] In formula (2), is the edge position of the i-th row of the image, is the edge position of the j-th row of the image, is the new value obtained after correction, is the total number of the horizontal direction scratch sub-regions of the detected scratch region, is the number parameter of adjacent correction positions, the edge positions of both sides in the i-th sub-region are re-corrected, and the size of i is modified to modify the smoothing range of the current sub-region correction; The image is further processed by morphological opening operation, and the length and area of the scratch are calculated;
[0017] S6, the real scratch width is calculated by the direction of the scratch region.
[0018] Further, the S2 is further preprocessed, specifically: the image is grayed, the background texture region in the image is suppressed by using the relative total variation algorithm, and the scratch structure region in the image is enhanced.
[0019] Further, the S2 is further preprocessed, specifically: the image is grayed, the background texture region in the image is suppressed by using the relative total variation algorithm, and the scratch structure region in the image is enhanced.
[0020] Further, in the enhanced image scratch structure region, the image is regionally segmented by an adaptive threshold segmentation method, a method based on geometric morphological features is used to filter the preliminarily segmented non-scratch connected regions in the image, and a connected region that does not meet the constraint range is regarded as a non-scratch region connected region, and the gray value in the region before the region segmentation is replaced by the average value of the gray values of the non-connected region pixels.
[0021] Further, the constraint range of the geometric morphological features is specifically:
[0022]
[0023] wherein, is the area of the connected region, is the aspect ratio of the connected region, is the area ratio of the connected region, is the circularity of the connected region;
[0024] The gray value processing calculation formula of the non-scratch connected region is:
[0025] (3)
[0026] In formula (3), is the gray value of the pixel point position , is the pixel point in the region , is the gray value of the position of any point in the region R, denotes the sum of the gray values of all pixel point positions in the region R, denotes the number of .
[0027] Further, the S3 further comprises: assuming that the distribution of the horizontal direction gradient near the scratch edge in the image is a normal distribution, the horizontal direction gradient of the scratch position is expressed as a linear superposition of two Gaussian functions, and the calculation formula of the Gaussian function is:
[0028] (4)
[0029] In formula (4), and are the peak values of the horizontal gradient of the edges on both sides of the scratch, and are the positions of the two peak values, and are the standard deviations of the two Gaussian curves.
[0030] Further, the S6 is specifically: calculating the intersection point of the line connecting the center points of the adjacent sub-regions and the normal line of the line, recording the distance between the two intersection points as the actual width of the scratch of the current sub-region.
[0031] The present application has the advantages that: the present application uses the relative total variation algorithm to suppress the background texture and geometric shape filter, which can improve the processing efficiency of extracting the scratch region in a complex background, and based on the calculation of the gray gradient, the Gaussian function fitting is used to determine the scratch edge; and the present application uses the scratch path method to determine the actual width of the scratch, which makes the definition of the scratch width more accurate. BRIEF DESCRIPTION OF DRAWINGS
[0032] The present application will be further described below in conjunction with the drawings and examples.
[0033] Figure 1 is a flowchart of the steel surface scratch detection method based on machine vision of the present application.
[0034] Figure 2 is a steel original image obtained in the embodiment of the present application; wherein, Figure 2 (a) is a steel original image containing point-like interference obtained in the embodiment of the present application; Figure 2 (b) is a steel original image containing group-like interference obtained in the embodiment of the present application.
[0035] Figure 3 is a preprocessed image obtained in the embodiment of the present application; wherein, Figure 3 (a) is a preprocessed image containing point-like interference obtained in the embodiment of the present application; Figure 3 (b) is a preprocessed image containing group-like interference obtained in the embodiment of the present application.
[0036] Figure 4 is a Gaussian fitting curve in the horizontal direction obtained in the embodiment of the present application.
[0037] Figure 5 is a scratch region detected in the embodiment of the present application; wherein, Figure 5 (a) is a scratch region detected in the embodiment of the present application; Figure 5 (b) is a scratch region detected in the embodiment of the present application.
[0038] Figure 6 is a scratch region detected in the embodiment of the present application; wherein, Figure 6 (a) is a scratch region detected in the embodiment of the present application; Figure 6 (b) is a scratch region detected in the embodiment of the present application.
[0039] Figure 7 is the scratch region detected by the triangle threshold algorithm in the embodiment of the present application; wherein, Figure 7 (a) is the image detection region containing point-like interference; Figure 7 (b) is the image detection region containing group-like interference.
[0040] Figure 8 is the schematic diagram of the method for calculating the actual width of the scratch in the embodiment of the present application. DETAILED DESCRIPTION
[0041] The present application will now be further described in detail with reference to the drawings. These drawings are simplified schematic diagrams and only schematically show the basic structure of the present application, and thus only show the components related to the present application.
[0042] As shown in Figure 1 , a steel surface scratch detection method based on machine vision comprises the following steps: step one, obtaining a steel surface image through a camera; step two, performing a grayscale processing on the surface image to obtain an original image as shown in Figure 2 ; using a relative total variation algorithm to suppress the background texture of the image, and enhancing the scratch structure region in the image.
[0043] In the scratch structure region of Figure 2 , a self-adaptive threshold segmentation method is used to preliminarily segment the image, a method based on geometric morphological features is used to filter the non-scratch region preliminarily segmented in the image, the connected region not satisfying the constraint range is regarded as a non-scratch connected region, and the gray value in the region before the region segmentation is replaced by the average value of the gray values of the non-connected region pixel points.
[0044] The constraint range of the geometric features is as follows:
[0045]
[0046] wherein, is the area of the connected region, is the aspect ratio of the connected region, is the area ratio of the connected region, is the circularity of the connected region.
[0047] The calculation formula of the gray value processing of the non-scratch connected region is as follows:
[0048] (3)
[0049] In formula (3), is the gray value of the pixel point at position , and is the region The pixels in For any point in region R The grayscale value at the position, This represents the sum of the gray values at all pixel locations within region R. express The quantity.
[0050] Connected region geometry filtering reduces the impact of interfering regions on the subsequently extracted horizontal grayscale gradient data (which may reduce the accuracy of Gaussian function fitting), thereby improving the accuracy of Gaussian function fitting. The original image being processed contains point-like, clumped, and strip-like defects, among which point-like and clumped defects are non-scratch connected regions; after processing, only the strip-like scratch defect portions are retained.
[0051] Based on the image preprocessing described above, the following is obtained: Figure 3 The preprocessed image shown.
[0052] Step 3: Fit the horizontal gray-level gradient data distribution of the image using a Gaussian function: First, describe the variation of gray-level values in the horizontal direction of the image using the horizontal gradient. Calculate the horizontal gradient using the first-order central difference formula as follows:
[0053] (1)
[0054] In equation (1), For the horizontal direction The grayscale gradient value of the column. and The first in the same horizontal direction Columns and For ease of calculation, the calculated gradient values are normalized.
[0055] The horizontal gray-level gradient data structure of the image is fitted using a Gaussian function, and the location information of the scratch is determined from the fitted Gaussian curve.
[0056] Assuming the distribution of the horizontal gradient near the scratch edge in the image is normally distributed, the horizontal gradient at the scratch location is represented as a linear superposition of two Gaussian functions, where the expression for the Gaussian function is:
[0057] (4)
[0058] In equation (4), and These represent the peak values of the horizontal gradients on both sides of the scratch. and These are the positions of the two peaks. and These are the standard deviations of the two Gaussian curves.
[0059] Equation (1) calculates the horizontal gray-level gradient, obtaining the relationship between the horizontal gray-level gradient value and the corresponding horizontal position. Equation (4) uses the data from Tables 1 and 2 to perform Gaussian curve fitting. The distribution of the horizontal gray-level gradient at the scratch can be determined by the fitted Gaussian curve, thereby obtaining the edge position of the scratch in the horizontal direction.
[0060] Table 1 Figure 3 (a) Fitted curve parameters in each horizontal direction
[0061]
[0062] Table 2 Figure 3 (b) Fitted curve parameters in each horizontal direction
[0063]
[0064] Step 4: Based on the above process, obtain the fitted Gaussian curves for each horizontal direction of the image. The distance between the two peaks in the Gaussian curve can be regarded as the width of the image in that horizontal direction. From this, calculate the edge position and horizontal center point position of the scratch in each horizontal direction. An example of the fitted Gaussian curve in the horizontal direction is shown below. Figure 4 As shown, where, =1.05, =0.76, =35.13, =47.74, =1.45, =1.68; the detected scratch area is as follows Figure 5 As shown.
[0065] Instead of using the background texture suppression and geometric filtering steps described above, the detection results obtained using the Otsu algorithm and triangular thresholding algorithm are used, such as... Figure 6 and Figure 7 As shown, the detection area includes dot-like or cluster-like false detection areas in the image background.
[0066] Step 5: Because there may be burrs on the edges of the horizontal scratch sub-regions, it is necessary to correct the positions of the edges on both sides of the sub-regions to make the transition between the upper and lower sub-regions in the image smoother. Specifically, the correction of the horizontal scratch edge positions of the detected scratch regions is calculated using the following formula:
[0067]
[0068] In equation (2), For the image number The edge position of the line, the edge position of the first row of the image, the edge position of the second row of the image, the new value obtained after the correction, the total number of scratch sub-regions in the horizontal direction of the scratch region, the number of adjacent correction positions, the two side edge positions in the sub-region are re-corrected by modifying the size of the correction range of the current sub-region, and the preset value in the embodiment is 3.
[0069] The image is then subjected to a morphological opening operation to calculate the scratch length and area: the line connecting all the center points (horizontal center position) of the sub-regions is taken as the scratch length, and the scratch area is the sum of the areas of the corrected sub-regions.
[0070] Step six: calculate the real scratch width by the direction of the scratch region: in order to obtain the real width information of the scratch in the image, rather than the horizontal direction of the scratch length, as shown in Figure 8 , , , , , , , , , , , , , , , , ,
[0071] The above ideal embodiments according to the present application are used as an inspiration, and through the above description, relevant personnel can make various changes and modifications without deviating from the technical idea of the present application. The technical scope of the present application is not limited to the content of the specification, and must be determined according to the scope of the claims.
Claims
1. A method for detecting scratches on steel surfaces based on machine vision, characterized in that, Includes the following steps: S1. Acquire images of the steel surface using a camera; S2. Preprocess the steel surface image obtained in step S1 to obtain the scratch structure area; S3. Fitting the horizontal gray-level gradient data of the image using a Gaussian function: The horizontal gradient of the image describes the variation of gray-level values in the horizontal direction. The first-order central difference is used to calculate the horizontal gradient of the image, and the calculation formula is as follows: (1) In equation (1), For the horizontal direction The grayscale gradient value of the column. and The first in the same horizontal direction Columns and List; The location information of the scratch is determined by the fitted Gaussian curve; S4. Determine the horizontal edge position and horizontal center point position of the scratch using the fitted Gaussian curve; S5. Correct the horizontal edge position of the detected scratch area using the following formula: In equation (2), For the image number The edge position of the line, For the image number The edge position of the line, for The new value obtained after correction To detect the total number of horizontal scratch sub-regions within the scratched area, The parameter representing the number of adjacent correction positions will be... The positions of the two side edges in each sub-region were re-corrected by modifying... The size is adjusted to modify the smoothing range of the current sub-region correction; Then, perform morphological opening operations on the image to calculate the scratch length and area; S6. Calculate the actual scratch width based on the direction of the scratch area; Specifically, in S2, the steel surface image is preprocessed by: converting the image to grayscale, using the relative total variation algorithm to suppress the background texture area in the image, and enhancing the scratch structure area in the image. Within the enhanced image scratch structure region, the image is segmented using an adaptive threshold segmentation method. A method based on geometric morphology features is used to filter the initially segmented non-scratched connected regions in the image. Connected regions that do not meet the constraints are regarded as non-scratched connected regions. The gray values in the region before region segmentation are replaced with the average gray values of the pixels in the non-connected regions. S3 further includes: assuming the distribution of the horizontal gradient near the scratch edge in the image is normally distributed, and representing the horizontal gradient at the scratch location as a linear superposition of two Gaussian functions, the formula for calculating the Gaussian function being: (4) In equation (4), and These represent the peak values of the horizontal gradients on both sides of the scratch. and These are the positions of the two peaks. and These are the standard deviations of the two Gaussian curves; Specifically, S6 involves: calculating the line connecting the center points of adjacent sub-regions and drawing the normal to that line; calculating the intersection points of the lines connecting the left and right sides of the adjacent sub-regions with the normal; and recording the distance between the two intersection points as the actual width of the scratch in the current sub-region.
2. The method for detecting scratches on steel surfaces based on machine vision according to claim 1, characterized in that: The specific range of constraints on the geometric morphological features is as follows: in, The area of the connected region. The aspect ratio of the connected region. The ratio of the areas of connected regions. The circularity of the connected region; The formula for calculating the grayscale value of non-scratch connected regions is: (3) In equation (3), The pixel position is grayscale value, For the region The pixels in For any point in region R The grayscale value at the position, This represents the sum of the gray values at all pixel locations within region R. express The quantity.
Citation Information
Patent Citations
A method for detecting scratches on metal parts based on image enhancement
CN115359044B
A computer vision-based method for detecting milling cutter scratches
CN115690105B
Computer host shell scratch detection method based on image features
CN117197138B