A method for detecting scratches on a steel sheet surface based on dynamic programming
Through a method based on dynamic programming, the accuracy and speed issues of scratch detection on the steel plate surface are solved, effective detection of fine scratches and discontinuous scratches is achieved, detection efficiency and noise resistance are improved, and labor costs are reduced.
Patent Information
- Application Number
- CN202311062151.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-21
- Publication Date
- 2025-10-21
- Estimated Expiration
- 2043-08-21
AI Technical Summary
In the existing technology, scratch detection on the surface of steel plates relies on manual inspection, which is prone to fatigue and inaccurate. The detection parameters of traditional methods are unstable, and it is difficult to collect training samples for deep learning methods, making it difficult to meet industrial detection requirements.
A dynamic programming-based method is used to capture steel plate images through a camera, perform grayscale conversion, Gaussian filtering, and binarization processing, construct an energy map, and trace back the optimal path. Combined with morphological operations and gradient solution, continuous scratch areas are screened out, and the same scratch is spliced through straight line fitting and angle judgment.
It achieves stable detection of fine scratches and discontinuous scratches on the surface of steel plates with fast detection speed, strong anti-noise ability, no need for sample training, saving labor costs and improving production efficiency.
Smart Images

Figure CN117078639B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image detection, and in particular to a steel plate surface scratch detection method based on dynamic programming. Background Art
[0002] During industrial manufacturing, defects such as scratches often appear on steel plate surfaces. Currently, steel plate defect detection relies primarily on manual labor, which is prone to fatigue and low accuracy, making it inadequate for current manufacturing needs. With the advancement of visual inspection technology, more and more surface defect detection tasks are being performed using this technology. Detection methods are generally categorized into two types: traditional methods and deep learning methods.
[0003] Traditional scratch detection techniques primarily rely on filtering algorithms. For example, Chinese patent CN115359044B authorizes a method for detecting scratches on metal surfaces based on image enhancement. This method involves obtaining the low-frequency gain coefficient, high-frequency gain coefficient, cutoff frequency, and spectrum of a grayscale image, filtering the spectrum to obtain an optimal enhancement image and enhanced grayscale image, and then performing scratch detection. For example, Chinese patent CN110378902B authorizes a method for detecting scratches in a high-noise background. This method automatically selects one of three filtering methods, LOG, Gauss, or Gabor, to filter the image based on different scenarios. The method then performs false detection elimination and scratch screening.
[0004] Deep learning scratch detection technology is usually a supervised algorithm. For example, the deep learning-based method for detecting small scratches and overprint deviations in printed products authorized by Chinese patent CN111524120B uses the GoogleNet detection model to predict defect locations and the GoogleNet binary classification model to classify defects and false detections, thereby reducing the false detection rate.
[0005] Traditional scratch detection methods have problems such as unstable detection parameters and difficulty in detecting discontinuous scratches, while deep learning-based detection methods have the problem of difficulty in collecting training samples, making it difficult to meet industrial detection requirements. Summary of the Invention
[0006] The purpose of the present invention is to address the deficiencies of the prior art and provide a method for detecting scratches on a steel plate surface based on dynamic programming.
[0007] The object of the present invention is to achieve the following technical solution: a method for detecting scratches on a steel plate surface based on dynamic programming, comprising the following steps:
[0008] Step 1: Capture steel plate images through a camera;
[0009] Step 2: The collected original image of the steel plate is subjected to grayscale conversion, Gaussian filtering, image convolution, and binarization processing in sequence to obtain a preprocessed image.
[0010] Step 3: Perform dynamic programming on the pre-processed image to obtain an image energy map; and trace back the optimal path from the maximum energy value in the energy map.
[0011] Step 4. During the path processing and scratch screening process, the energy values in the optimal path are arranged into a row of pixels; the arranged path energy values are subjected to Sobel gradient solution to obtain energy gradient values; the energy gradient values are binarized according to a preset threshold to generate a mask, where the area less than the threshold is an invalid area, and the area above the threshold is a valid area. In order to merge locally discontinuous scratch points into complete scratches, a morphological closing operation (first dilation and then corrosion) is performed on the mask to obtain a locally continuous mask; in order to screen out scratches that meet the requirements, the locally continuous mask is screened. The effective area of the mask is screened according to the preset minimum continuous length value, the minimum area enclosed by the gradient curve and the above-mentioned preset threshold, and the steel plate scratch is obtained based on the mapping relationship between the screened mask and the pixel points of the original steel plate image.
[0012] Furthermore, the dynamic programming in step 3 includes both row and column directions. The row direction tends to detect horizontal scratches, while the column direction tends to detect vertical scratches. When detecting horizontal scratches, the image needs to be transposed and its column direction detected.
[0013] Furthermore, the energy diagram construction formula in step 3 is as follows:
[0014] M(u,v)=e(u,v)+max(M(u-1,v-1)×Q u-1 ,M(u,v-1)×Q u ,M(u+1,v-1)×Q u+1 )
[0015] Where: M(u,v) represents the image energy map; e(u,v) represents the preprocessed image;
[0016] Where: Q i represents the direction weight, k represents directional sensitivity; p n Indicates the number of samples before statistics; p i Represents the number of one direction in the first n samples; u and v represent the coordinates of the image.
[0017] Furthermore, when the maximum value in the optimal path in step three is less than a preset value, it is considered that the current image has no scratch defect in this direction.
[0018] Furthermore, the gradient curve in step 4 is a curve formed by energy gradient values in a rectangular coordinate system; the local optimal path is obtained by the mapping relationship between the effective area in the local continuous mask and the optimal path.
[0019] Furthermore, based on the scratch obtained in step 4 and the preset scratch width, the corresponding area of the preprocessed image in step 2 is shielded, and step 3 is re-executed to obtain a new image energy map and find the second scratch.
[0020] Step 5: To optimize the detection results, segments that may belong to the same scratch are spliced together. A straight line is fitted to the scratch to obtain a baseline segment, and its straightness is evaluated. If the straightness exceeds a threshold, the scratch is not included in the splicing.
[0021] The angle between the two reference line segments of each scratch is calculated for each pair of scratches involved in the stitching. If the angle is less than a preset value, the process proceeds to the next step. The closest point determination is performed for each scratch combination using the above angle determination. If the closest point of each scratch is both the scratch start or end point and the distance is less than a preset value, the process proceeds to the next step. The closest points of each scratch combination using the above determination are connected and the angle between them and the two reference line segments is calculated. If the angle between the connecting line and both reference line segments is less than the preset angle, the two scratches are considered to belong to the same scratch and include the connecting line.
[0022] The present invention has the following beneficial effects:
[0023] Most scratches on steel plates are thin, straight, and slightly curved. Based on these characteristics, the dynamic planning process introduces directional factors to improve the directional consistency of each point on the optimal path, making it closer to the scratch shape. Thin scratches can be difficult to image, leading to localized scratch discontinuities. Therefore, a morphological closing operation is added to the scratch screening process to process the mask. This merges valid, closely discontinuous points in the mask to create a locally continuous mask, effectively merging discontinuous scratch regions. Minimum continuous length and minimum area are set to filter scratches to prevent interference from localized bright spots. Finally, segments belonging to the same scratch are spliced based on scratch shape and angle attributes, resulting in improved scratch detection.
[0024] The present invention is a universal steel plate scratch detection method. Based on the idea of dynamic programming, the method can stably detect fine scratches and discontinuous scratches on the surface of steel plates. It has the advantages of fast detection speed, strong anti-noise ability, and no need for sample training, saving labor costs and improving production efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] Figure 1 It is a flow chart of the present invention.
[0026] Figure 2 is the original image of the steel plate obtained in the embodiment of the present invention.
[0027] Figure 3 is a pre-processed image obtained in an embodiment of the present invention.
[0028] Figure 4 is the gradient curve obtained in the embodiment of the present invention.
[0029] Figure 5 This is the steel plate scratch detection result in the embodiment of the present invention.
[0030] Figure 6 This is the result of scratch splicing of steel plates in an embodiment of the present invention. DETAILED DESCRIPTION
[0031] In order to further illustrate the technical means and effects adopted by the present invention to achieve the predetermined invention purpose, the following is a detailed description with reference to the accompanying drawings and specific embodiments. The present invention proposes a method for detecting scratches on a steel plate surface based on dynamic programming, and its specific implementation, structure, features and effects are described as follows:
[0032] like Figure 1 As shown, a steel plate surface scratch detection method based on dynamic programming includes the following steps:
[0033] Step 1: Get the original image of the steel plate through the camera and get the following Figure 2 Original image shown.
[0034] Step 2: First, grayscale the collected original image of the steel plate, and perform Gaussian filtering with a kernel of 3×3 on the grayscale image.
[0035] The convolution operation is performed on the Gaussian filtered image, and the calculation formula is as follows:
[0036]
[0037] Wherein, dst represents the image after convolution; u and v are image coordinates; u' and v' represent the coordinates on the convolution kernel; cols and rows represent the convolution kernel size; kernel represents the convolution kernel, and in the embodiment, the kernel is [-1,-1,-1,-1,8,-1,-1,-1-1]; src represents the image to be convolved; u anchor 、v anchor is the convolution kernel anchor point coordinate.
[0038] The convolution result is then binarized to eliminate the background noise. The calculation formula is as follows:
[0039]
[0040] Here, thresh represents the noise floor threshold, and its value is 20.
[0041] According to the above image preprocessing, we can get Figure 3 The preprocessed image is shown.
[0042] Step 3: Perform dynamic image programming on the preprocessed image. Column-wise dynamic programming tends to detect vertical scratches, while row-wise dynamic programming tends to detect horizontal scratches. During horizontal scratch detection, the image needs to be transposed and column-wise dynamic programming employed.
[0043] The direction factor is introduced in the dynamic planning process. The directions of the first n paths are counted as a reference for the next path direction. The directions are divided into left, center, and right. Assuming that the first n paths turn right the most times, the next step is more likely to turn right. At the same time, sensitivity is introduced to control the influence of the direction factor. When the sensitivity value is 0, the direction factor is not used as a reference.
[0044] The column-wise dynamic programming calculation formula is as follows:
[0045] M(u,v)=e(u,v)+max(M(u-1,v-1)×Q u-1 ,M(u,v-1)×Q u ,M(u+1,v-1)×Q u+1 )
[0046] Where: M(u,v) represents the energy map; e(u,v) represents the preprocessed image;
[0047] Where: Q i represents the direction weight, k represents directional sensitivity; p n Indicates the number of samples before statistics; p i Represents the number of one direction in the first n samples; u and v represent the coordinates of the image.
[0048] According to the above process, the image energy map is obtained. The maximum value of the last row in the energy map is detected and judged whether it is less than the preset threshold. If the maximum value of the last row is less than the preset threshold, it is considered that there is no scratch defect on the image. Otherwise, the optimal path is backtracked upwards from the maximum value position as the starting point. The backtracking method is calculated as follows:
[0049]
[0050] Where: p j is a set of path points.
[0051] Step 4: Arrange the energy values in the above optimal path into a row of pixels and perform Sobel gradient solution to obtain Figure 4 The gradient curve is shown.
[0052] To filter noise and merge locally discontinuous scratch points into complete scratches, the gradient curve values are first binarized to generate a mask, where points in the gradient curve less than a threshold are set to 0, and points greater than or equal to the threshold are set to 255. A morphological closing operation (dilation followed by erosion) is then performed on the mask. During the operation, the kernel sizes of the two operations are the same, resulting in a locally continuous mask. In this embodiment, the morphological operation kernel is 10.
[0053] Finally, to filter out the expected scratches, the locally continuous mask is processed. The effective area of the mask is filtered based on the preset minimum continuous length value, the minimum area enclosed by the gradient curve and the preset threshold. The steel plate scratch is obtained based on the mapping relationship between the filtered mask and the pixels of the original steel plate image.
[0054] The above-mentioned gradient curve is a curve formed by energy gradient values in a rectangular coordinate system. When the gradient curve and the preset threshold value enclose multiple discontinuous regions, the area thereof is the sum of the multiple regions.
[0055] When scratches are detected, the corresponding area on the pre-processed image is zeroed and shielded, where the shielding width is determined by the preset value, and then the pre-processed image is dynamically re-planned, and scratches are searched back and forth in sequence until all are detected. Figure 5 In the embodiment, the preset value is 3 pixels.
[0056] Step 5: To optimize the detection results, segments that may belong to the same scratch are spliced together. First, the scratch is evaluated for straightness. A least-squares linear fit is performed on the points on the scratch to obtain a straight line. The fitted straight line is intercepted at the scratch's starting and ending points using a nearest neighbor method as a reference line segment. The mean Euclidean distance between each point in the current scratch and the reference line segment is then calculated. If the mean exceeds a preset value, the scratch is excluded from the splicing. In this embodiment, the preset value is 10 pixels.
[0057] The scratches involved in the splicing are combined in pairs to calculate the angle between the two baseline segments. When the angle is less than the preset value, the subsequent judgment is made. In the embodiment, the preset value is 10 degrees, and the angle is an acute angle. The nearest point judgment is made on the scratch combination judged by the above angle. When the nearest points of the two scratches are both the starting point or the end point of the scratch and the distance is less than the preset value, the subsequent judgment is made. In the embodiment, the preset value is 30 pixels. The nearest points of the scratch combination judged by the above judgment are connected, and the angle with the two baseline segments is calculated. When the angle between the connecting line and the two baseline segments is less than the preset angle, the two scratches are considered to belong to the same scratch and their nearest two points are connected. In the embodiment, the preset value is 10 degrees, and the angle is an acute angle. The splicing result is as follows. Figure 6 shown.
[0058] The above embodiments are only for illustrating the technical concept and features of the present invention, and the purpose is to enable people familiar with this technology to quickly understand the content of the invention and implement it. It does not limit the present invention. All equivalent improvements made according to the present invention should be included in the scope of protection of the present invention.
Claims
1. A method for detecting scratches on a steel plate surface based on dynamic programming, characterized in that: The steps include: (1) Collect the original image of the steel plate through the camera; (2) Preprocessing the collected original image of the steel plate to obtain a preprocessed image; (3) Perform dynamic programming on the pre-processed image to obtain the image energy map and trace back the optimal path, including: 3.1) Introducing the direction factor, the image energy map is constructed as follows: ; in: Represents the image energy map; represents the preprocessed image; represents the direction weight, ; Indicates directional sensitivity; Before statistics The number of samples; Before The number of samples in one direction, and Represents the coordinates of the image; 3.2) Use the maximum energy value of the image energy map to trace back the optimal path; (4) The energy value in the optimal path is solved by Sobel gradient to obtain the energy gradient value, and the energy gradient value is binarized according to the preset parameters to generate a mask, and then the mask is morphologically closed to obtain a locally continuous mask; the locally continuous mask is screened to select the mask that simultaneously meets the preset minimum continuous length value and the minimum area value enclosed by the gradient curve and the preset threshold. Finally, the steel plate scratch is obtained based on the mapping relationship between the screened mask and the original steel plate image; (5) Splice the steel plate scratches obtained in step 4.
2. The steel plate surface scratch detection method based on dynamic programming according to claim 1, characterized in that: In step (2), preprocessing includes: grayscale, Gaussian filtering, image convolution, and binarization.
3. The steel plate surface scratch detection method based on dynamic programming according to claim 1, characterized in that: In step (4), the gradient curve is a curve composed of energy gradient values.
Citation Information
Patent Citations
A scratch detection method under high noise background
CN110378902B
Deep learning-based methods for detecting minor scratches and misregistration in printed materials
CN111524120B
A method for detecting scratches on metal parts based on image enhancement
CN115359044B
Fine scratch detection method and device, electronic equipment and computer readable storage medium
CN112258448A
Surface flaw inspecting system and flaw method, and computer program
JP2008203198A