A visual detection method for scratches on metal surfaces
Through computer vision technology, the use of image pixel contrast measurement quantization, grayscale energy function optimization and multi-feature enhancement methods to solve the problem of insufficient efficiency and accuracy in metal surface scratch detection, and achieve high efficiency, Accurate detection of scratches on metal surfaces.
Patent Information
- Application Number
- CN202411387893.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-08
- Publication Date
- 2025-02-07
- Estimated Expiration
- 2044-10-08
AI Technical Summary
Traditional manual detection methods cannot meet the needs of efficient and accurate metal surface scratch detection, and are susceptible to subjective factors, resulting in missed or missed inspection, especially when faced with different paint colors.
Using computer vision technology, visual detection of metal surface scratches is performed through quantization of image pixel contrast, optimization solution of grayscale energy functions, multi-feature enhancement processing and improved residual network.
High-resolution multi-color metal scratch image processing is realized, precisely identifying tiny scratches, reducing the probability of missed detection and false detection, and improving the efficiency and accuracy of detection.
Smart Images

Figure CN118898604B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of metal scratch detection, and in particular to a metal surface scratch visual detection method. Background Art
[0002] Metal materials are widely used in aerospace, automobile manufacturing, mechanical engineering and other fields, and their surface quality directly affects the performance and service life of the product. Scratches on the metal surface are one of the common defects, which may be caused by processing, transportation, assembly and other links. Scratches not only affect the appearance, but may also cause stress concentration, thereby causing fatigue damage or corrosion. Therefore, timely and accurate detection of scratches on the metal surface is of great significance to ensure product quality and improve production efficiency. Traditional manual inspection methods cannot meet the needs of efficient and accurate inspection. Manual inspection is not only time-consuming and labor-intensive, but also easily affected by subjective factors, resulting in missed inspections or false inspections, especially in the face of different paint colors, which can easily cause visual errors. Summary of the invention
[0003] In view of this, the present invention provides a metal surface scratch visual detection method, which realizes high-resolution multi-color metal scratch image processing through computer vision technology, accurately identifies tiny scratches, and reduces the probability of missed detection and false detection.
[0004] To achieve the above object, the present invention provides a method for visually detecting scratches on a metal surface, comprising the following steps:
[0005] S1: Collect metal surface images and perform quantization processing on image pixel contrast, and use the quantization processing result as the grayscale coefficient between pixels;
[0006] S2: constructing a grayscale energy function according to the grayscale coefficient and optimizing the function to obtain a grayscale metal surface image;
[0007] S3: performing enhancement processing on the grayscale metal surface image to obtain an enhanced metal surface image, wherein pixel saliency optimization is an implementation method of the enhancement processing;
[0008] S4: Perform scratch detection on the enhanced metal surface image to identify scratches on the metal surface, wherein the improved residual network is an implementation method of the scratch detection.
[0009] As a further improvement method of the present invention:
[0010] Optionally, in step S1, collecting the metal surface image and performing quantification processing on the image pixel contrast includes:
[0011] Capturing images of metal surfaces , where the representation of the metal surface image is:
[0012] ;
[0013] in:
[0014] Represents metal surface images The pixel value of the pixel at row x and column y, , , X represents the metal surface image The number of pixel rows, Y represents the metal surface image The number of pixel columns;
[0015] Metal surface image The pixels of the image are quantized for contrast, and the quantization process of the image pixel contrast is as follows:
[0016] S11: Acquire metal surface images The pixel value of the pixel in the image is split into the color values of the three color channels R, G, and B; the metal surface image The color values of the pixel in the xth row and yth column in the three color channels are ;
[0017] S12: Calculate the pixel contrast between any two pixels; the pixel contrast between the pixel in the xth row and yth column and the pixel in the ith row and jth column is:
[0018] ;
[0019] in:
[0020] represents the pixel contrast between the pixel in the xth row and the yth column and the pixel in the ith row and the jth column;
[0021] , ;
[0022] S13: quantize the pixel contrast, and use the quantization result as the grayscale coefficient between pixels; the grayscale coefficient between the pixel in the xth row and yth column and the pixel in the ith row and jth column is :
[0023] ;
[0024] in:
[0025] represents an exponential function with a natural constant as base;
[0026] Indicates the preset pixel distance threshold.
[0027] Optionally, in step S2, constructing a grayscale energy function according to the grayscale coefficient includes:
[0028] The grayscale energy function is constructed according to the grayscale coefficients between pixels, where the construction process of the grayscale energy function is:
[0029] S21: extracting pixel contrast from the grayscale coefficients between pixels, and calculating the pixel similarity between different pixels based on the pixel contrast; wherein the pixel similarity between the pixel in the xth row and yth column and the pixel in the ith row and jth column is:
[0030] ;
[0031] in:
[0032] Indicates the degree of pixel similarity between the pixel in the xth row and the yth column and the pixel in the ith row and the jth column;
[0033] represents the control parameters;
[0034] S22: Set the grayscale value of different pixels, where the metal surface image The gray value of the pixel in row x and column y is , the gray value is the parameter to be optimized;
[0035] S23: Calculate the grayscale similarity of different pixels, where the grayscale similarity of the pixel in the xth row and yth column and the pixel in the ith row and jth column is:
[0036] ;
[0037] in:
[0038] Indicates the grayscale similarity between the pixel in the xth row and the yth column and the pixel in the ith row and the jth column;
[0039] S24: constructing a grayscale energy function, wherein the grayscale energy function takes the grayscale value of the pixel as the parameter to be optimized and takes minimizing the energy difference between the grayscale similarity and the pixel similarity as the optimization goal. The constructed grayscale energy function is:
[0040] ;
[0041] ;
[0042] in:
[0043] represents the grayscale energy function; Represents the grayscale matrix to be optimized;
[0044] Represents metal surface images The set of pixel coordinates in ;
[0045] Grayscale energy function An optimization solution is performed to obtain a grayscale metal surface image.
[0046] Optionally, the grayscale energy function Perform optimization and solution to obtain a grayscale metal surface image, including:
[0047] Grayscale energy function Perform optimization and solution, where the optimization and solution process is:
[0048] S241: Initialize and generate color weights of different color channels, where the color weights of the R, G, and B color channels generated by initialization are: , then the color weight The gray value of the corresponding pixel in row x and column y is ;
[0049] S242: Set the current iteration number of the color weight to d and the maximum iteration number to Max. Then the color weight obtained in the dth iteration is , the initial value of d is 0;
[0050] S243: Iterate the color weight, where the iteration formula is:
[0051] ;
[0052] ;
[0053] in:
[0054] represents the learning rate, Set to 0.8;
[0055] Represents the grayscale energy function Corresponding color weight In the embodiment of the present invention, The solution process is to convert the color weight Substitute into the grayscale energy function , the color weight As a variable for the grayscale energy function Take the derivative and weight the color Substituting the derivative result, we get ;
[0056] S244: Set d = d + 1, return to S243, until the maximum number of iterations is reached, and adjust the color weights Normalization is performed and the metal surface image is calibrated using the normalized color weights. The pixels in the grayscale are processed to obtain the grayscale value of the pixel, where the grayscale value of the pixel in the xth row and yth column is ;
[0057] S245: Constructing grayscale metal surface images .
[0058] Optionally, the step S3 of enhancing the grayscale metal surface image includes:
[0059] Grayscale metal surface image Perform enhancement processing, wherein pixel saliency optimization is the implementation method of the enhancement processing, graying the metal surface image The enhanced processing flow is:
[0060] S31: Grayscale metal surface image The pixels in are represented by second-order differences to obtain the second-order difference matrix of pixels; the grayscale metal surface image The second-order difference matrix of the pixel in the xth row and yth column is:
[0061] ;
[0062] ;
[0063] ;
[0064] ;
[0065] ;
[0066] in:
[0067] Represents a grayscale metal surface image The second-order difference matrix of the pixel in the xth row and yth column;
[0068] Represents a grayscale metal surface image The second-order difference values of the pixel in the xth row and the yth column in multiple directions;
[0069] S32: Use a Gaussian filter to perform Gaussian filtering on the second-order difference matrix of the pixels to obtain a second-order difference matrix after Gaussian filtering; wherein the second-order difference matrix The corresponding Gaussian filtering result is:
[0070] ;
[0071] ;
[0072] ;
[0073] ;
[0074] ;
[0075] ;
[0076] ;
[0077] ;
[0078] in:
[0079] Represents the second-order difference matrix The corresponding Gaussian filtering result;
[0080] Represents the second-order derivative of the Gaussian filter in different directions;
[0081] represents the standard deviation of the Gaussian filter; Indicates the step size of Gaussian filtering;
[0082] S33: Perform eigendecomposition on the second-order difference matrix after Gaussian filtering to obtain the two maximum eigenvalues of the pixel, where the grayscale metal surface image The two largest eigenvalues of the pixel in row x and column y are , ;
[0083] S34: Calculate the grayscale metal surface image The saliency value of any pixel in the grayscale metal surface image The saliency value of the pixel in row x and column y is:
[0084] ;
[0085] in:
[0086] Represents a grayscale metal surface image The saliency value of the pixel at row x and column y in ;
[0087] Represents a grayscale metal surface image The gray value of the pixel in the xth row and yth column, Represents a grayscale metal surface image The mean gray value of ;
[0088] S35: Combine the maximum eigenvalue and the significant value of the pixel to construct a multi-feature enhancement function of the pixel, and use the output result of the multi-feature enhancement function as the enhanced pixel value of the pixel, wherein the grayscale metal surface image The enhanced pixel value of the pixel in the xth row and yth column is ;
[0089] S36: Constructing an enhanced metal surface image .
[0090] Optionally, in step S35, the multi-feature enhancement function of the pixel is constructed by combining the maximum eigenvalue and the saliency value of the pixel, including:
[0091] The grayscale metal surface image The output of the multi-feature enhancement function for the pixel in the xth row and yth column is:
[0092]
[0093] in:
[0094] Represents a grayscale metal surface image The output result of the multi-feature enhancement function corresponding to the pixel in the xth row and yth column.
[0095] Optionally, performing scratch detection on the enhanced metal surface image in step S4 includes:
[0096] The enhanced metal surface image U is subjected to scratch detection, wherein the improved residual network is the implementation method of the scratch detection, and the scratch detection process is as follows:
[0097] S41: Acquire an enhanced metal surface image U;
[0098] S42: Extract the deep convolution features of the enhanced metal surface image U at different scales, where the deep convolution features at the kth scale are:
[0099] ;
[0100] in:
[0101] represents the deep convolution feature of the metal surface image U at the kth scale, , K represents the preset maximum scale; in the embodiment of the present invention, ;
[0102] represents the bias parameter, represents the convolution matrix, T represents the transpose;
[0103] represents the Softmax function, Represents the ReLU function;
[0104] S43: Calculate the probability information of scratches on the metal surface image U :
[0105] ;
[0106] in:
[0107] represents the probability mapping matrix, Represents deep convolutional features The probability of scratches, represents information adjustment parameters;
[0108] S44: If the probability information If it is higher than the preset threshold, it means that there are scratches on the metal surface image U.
[0109] Optionally, the process of determining the control parameters in step S21 includes:
[0110] S211: Initialize and generate control parameters , set the upper bound of the control parameter and the lower bound ;
[0111] S212: Set the current iteration number of the control parameter to c, and the maximum iteration number to C. Then the result of the cth iteration of the control parameter is , the initial value of c is 0;
[0112] S213: According to the control parameters Calculate the pixel similarity information:
[0113] ;
[0114] ;
[0115] ;
[0116] in:
[0117] Indicates the control parameters Pixel similarity information, Represents process parameters;
[0118] Indicates the control parameters Under the condition, the pixel similarity between the pixel in the xth row and the yth column and the pixel in the ith row and the jth column;
[0119] S214: if the pixel similarity information reaches a preset information threshold, terminating the iteration of the control parameters;
[0120] If the pixel similarity information is less than the preset information threshold, Step length The reduction process, where represents a fixed step size, Represents a random number between 0 and 1; if the pixel similarity information is greater than the preset information threshold, Step length The process is continued until the maximum number of iterations is reached or the pixel similarity information reaches a preset information threshold.
[0121] In order to solve the above problem, the present invention provides an electronic device, the electronic device comprising:
[0122] A memory storing at least one instruction;
[0123] Communication interface, enabling electronic equipment to communicate; and
[0124] The processor executes the instructions stored in the memory to implement the above-mentioned metal surface scratch visual detection method.
[0125] In order to solve the above problem, the present invention also provides a computer-readable storage medium, in which at least one instruction is stored. The at least one instruction is executed by a processor in an electronic device to implement the above-mentioned metal surface scratch visual detection method.
[0126] Compared with the prior art, the present invention proposes a metal surface scratch visual detection method, which has the following advantages:
[0127] First, this scheme proposes an adaptive grayscale processing method for images. According to the color values of pixels in different color channels, the color contrast between pixels is calculated, and the pixel contrast between pixels is quantified in combination with the position information between pixels to obtain the pixel contrast that represents the pixel color difference. The pixel contrast is mapped to the pixel similarity to obtain the similarity of different pixels in the color channel, and a grayscale energy function is constructed to represent the difference between the grayscale value similarity and the pixel similarity between different pixels. The grayscale value of the pixel is obtained by minimizing the difference, thereby realizing adaptive image grayscale processing.
[0128] At the same time, this scheme performs multi-directional differential filtering on the pixels according to the multi-order differential representation results of the pixels, constructs a second-order differential matrix of the pixels after Gaussian filtering, extracts the maximum eigenvalue representing the pixel information, and performs multi-feature enhancement on the grayscale value of the pixel in combination with the degree of difference between the pixel grayscale and the image grayscale mean to obtain an enhanced metal surface image, thereby realizing multi-feature enhancement processing of pixel differential features in multiple directions and mean difference features, and using a variety of activation functions to perform multi-scale deep convolution feature extraction on the enhanced metal surface image. In the process of deep convolution feature extraction, residual calculation operations are introduced to retain effective information of adjacent scales, improve the smoothness between multi-scale deep convolution features, obtain the probability information of scratches on the metal surface image, and realize visual detection of scratches on the metal surface. BRIEF DESCRIPTION OF THE DRAWINGS
[0129] Figure 1 A schematic diagram of a process for visually detecting scratches on a metal surface provided by an embodiment of the present invention;
[0130] Figure 2 A schematic diagram of the structure of an electronic device for implementing a method for visually detecting scratches on a metal surface provided by an embodiment of the present invention.
[0131] In the figure: 1 electronic device, 10 processor, 11 memory, 12 program, 13 communication interface.
[0132] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0133] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0134] The embodiment of the present application provides a method for visual detection of scratches on a metal surface. The execution subject of the method for visual detection of scratches on a metal surface includes but is not limited to at least one of the electronic devices such as a server and a terminal that can be configured to execute the method provided by the embodiment of the present application. In other words, the method for visual detection of scratches on a metal surface can be executed by software or hardware installed on a terminal device or a server device, and the software can be a blockchain platform. The server includes but is not limited to: a single server, a server cluster, a cloud server or a cloud server cluster, etc.
[0135] Embodiment 1:
[0136] S1: Collecting metal surface images and performing quantization processing on the image pixel contrast, and using the quantization processing result as the grayscale coefficient between pixels.
[0137] In the step S1, the metal surface image is collected and the image pixel contrast is quantified, including:
[0138] Capturing images of metal surfaces , where the representation of the metal surface image is:
[0139] ;
[0140] in:
[0141] Represents metal surface images The pixel value of the pixel at row x and column y, , , X represents the metal surface image The number of pixel rows, Y represents the metal surface image The number of pixel columns;
[0142] Metal surface image The pixels of the image are quantized for contrast, and the quantization process of the image pixel contrast is as follows:
[0143] S11: Acquire metal surface images The pixel value of the pixel in the image is split into the color values of the three color channels R, G, and B; the metal surface image The color values of the pixel in the xth row and yth column in the three color channels are ;
[0144] S12: Calculate the pixel contrast between any two pixels; the pixel contrast between the pixel in the xth row and yth column and the pixel in the ith row and jth column is:
[0145] ;
[0146] in:
[0147] represents the pixel contrast between the pixel in the xth row and the yth column and the pixel in the ith row and the jth column;
[0148] , ;
[0149] S13: quantize the pixel contrast, and use the quantization result as the grayscale coefficient between pixels; the grayscale coefficient between the pixel in the xth row and yth column and the pixel in the ith row and jth column is :
[0150] ;
[0151] in:
[0152] represents an exponential function with a natural constant as base;
[0153] Indicates the preset pixel distance threshold.
[0154] S2: construct a grayscale energy function according to the grayscale coefficient and optimize it to obtain a grayscale metal surface image.
[0155] In the step S2, a grayscale energy function is constructed according to the grayscale coefficient, including:
[0156] The grayscale energy function is constructed according to the grayscale coefficients between pixels, where the construction process of the grayscale energy function is:
[0157] S21: extracting pixel contrast from the grayscale coefficients between pixels, and calculating the pixel similarity between different pixels based on the pixel contrast; wherein the pixel similarity between the pixel in the xth row and yth column and the pixel in the ith row and jth column is:
[0158] ;
[0159] in:
[0160] Indicates the degree of pixel similarity between the pixel in the xth row and the yth column and the pixel in the ith row and the jth column;
[0161] represents the control parameters;
[0162] S22: Set the grayscale value of different pixels, where the metal surface image The gray value of the pixel in row x and column y is , the gray value is the parameter to be optimized;
[0163] S23: Calculate the grayscale similarity of different pixels, where the grayscale similarity of the pixel in the xth row and yth column and the pixel in the ith row and jth column is:
[0164] ;
[0165] in:
[0166] Indicates the grayscale similarity between the pixel in the xth row and the yth column and the pixel in the ith row and the jth column;
[0167] S24: constructing a grayscale energy function, wherein the grayscale energy function takes the grayscale value of the pixel as the parameter to be optimized and takes minimizing the energy difference between the grayscale similarity and the pixel similarity as the optimization goal. The constructed grayscale energy function is:
[0168] ;
[0169] ;
[0170] in:
[0171] represents the grayscale energy function; Represents the grayscale matrix to be optimized;
[0172] Represents metal surface images The set of pixel coordinates in ;
[0173] Grayscale energy function An optimization solution is performed to obtain a grayscale metal surface image.
[0174] The grayscale energy function Perform optimization and solution to obtain a grayscale metal surface image, including:
[0175] Grayscale energy function Perform optimization and solution, where the optimization and solution process is:
[0176] S241: Initialize and generate color weights of different color channels, where the color weights of the R, G, and B color channels generated by initialization are: , then the color weight The gray value of the corresponding pixel in row x and column y is ;
[0177] S242: Set the current iteration number of the color weight to d and the maximum iteration number to Max. Then the color weight obtained in the dth iteration is , the initial value of d is 0;
[0178] S243: Iterate the color weight, where the iteration formula is:
[0179] ;
[0180] ;
[0181] in:
[0182] represents the learning rate, Set to 0.8;
[0183] Represents the grayscale energy function Corresponding color weight In the embodiment of the present invention, The solution process is to convert the color weight Substitute into the grayscale energy function , the color weight As a variable for the grayscale energy function Take the derivative and weight the color Substituting the derivative result, we get ;
[0184] S244: Set d = d + 1, return to S243, until the maximum number of iterations is reached, and adjust the color weights Normalization is performed and the metal surface image is calibrated using the normalized color weights. The pixels in the grayscale are processed to obtain the grayscale value of the pixel, where the grayscale value of the pixel in the xth row and yth column is ;
[0185] S245: Constructing grayscale metal surface images .
[0186] S3: performing enhancement processing on the grayscale metal surface image to obtain an enhanced metal surface image.
[0187] In the step S3, the grayscale metal surface image is enhanced, including:
[0188] Grayscale metal surface image Perform enhancement processing, wherein pixel saliency optimization is the implementation method of the enhancement processing, graying the metal surface image The enhanced processing flow is:
[0189] S31: Grayscale metal surface image The pixels in are represented by second-order differences to obtain the second-order difference matrix of pixels; the grayscale metal surface image The second-order difference matrix of the pixel in the xth row and yth column is:
[0190] ;
[0191] ;
[0192] ;
[0193] ;
[0194] ;
[0195] in:
[0196] Represents a grayscale metal surface image The second-order difference matrix of the pixel in the xth row and yth column;
[0197] Represents a grayscale metal surface image The second-order difference values of the pixel in the xth row and the yth column in multiple directions;
[0198] S32: Use a Gaussian filter to perform Gaussian filtering on the second-order difference matrix of the pixels to obtain a second-order difference matrix after Gaussian filtering; wherein the second-order difference matrix The corresponding Gaussian filtering result is:
[0199] ;
[0200] ;
[0201] ;
[0202] ;
[0203] ;
[0204] ;
[0205] ;
[0206] ;
[0207] in:
[0208] Represents the second-order difference matrix The corresponding Gaussian filtering result;
[0209] Represents the second-order derivative of the Gaussian filter in different directions;
[0210] represents the standard deviation of the Gaussian filter; Indicates the step size of Gaussian filtering;
[0211] S33: Perform eigendecomposition on the second-order difference matrix after Gaussian filtering to obtain the two maximum eigenvalues of the pixel, where the grayscale metal surface image The two largest eigenvalues of the pixel in row x and column y are , ;
[0212] S34: Calculate the grayscale metal surface image The saliency value of any pixel in the grayscale metal surface image The saliency value of the pixel in row x and column y is:
[0213] ;
[0214] in:
[0215] Represents a grayscale metal surface image The saliency value of the pixel at row x and column y in ;
[0216] Represents a grayscale metal surface image The gray value of the pixel in the xth row and yth column, Represents a grayscale metal surface image The mean gray value of ;
[0217] S35: Combine the maximum eigenvalue and the significant value of the pixel to construct a multi-feature enhancement function of the pixel, and use the output result of the multi-feature enhancement function as the enhanced pixel value of the pixel, wherein the grayscale metal surface image The enhanced pixel value of the pixel in the xth row and yth column is ;
[0218] S36: Constructing an enhanced metal surface image .
[0219] In the step S35, the maximum eigenvalue and the saliency value of the pixel are combined to construct a multi-feature enhancement function of the pixel, including:
[0220] The grayscale metal surface image The output of the multi-feature enhancement function for the pixel in the xth row and yth column is:
[0221] ;
[0222] in:
[0223] Represents a grayscale metal surface image The output result of the multi-feature enhancement function corresponding to the pixel in the xth row and yth column.
[0224] S4: Perform scratch detection on the enhanced metal surface image to identify scratches on the metal surface.
[0225] In step S4, scratch detection is performed on the enhanced metal surface image, including:
[0226] The enhanced metal surface image U is subjected to scratch detection, wherein the improved residual network is the implementation method of the scratch detection, and the scratch detection process is as follows:
[0227] S41: Acquire an enhanced metal surface image U;
[0228] S42: Extract the deep convolution features of the enhanced metal surface image U at different scales, where the deep convolution features at the kth scale are:
[0229] ;
[0230] in:
[0231] represents the deep convolution feature of the metal surface image U at the kth scale, , K represents the preset maximum scale; in the embodiment of the present invention, ;
[0232] represents the bias parameter, represents the convolution matrix, T represents the transpose;
[0233] represents the Softmax function, Represents the ReLU function;
[0234] S43: Calculate the probability information of scratches on the metal surface image U :
[0235] ;
[0236] in:
[0237] represents the probability mapping matrix, Represents deep convolutional features The probability of scratches, represents information adjustment parameters;
[0238] S44: If the probability information If it is higher than the preset threshold, it means that there are scratches on the metal surface image U.
[0239] Embodiment 2:
[0240] like Figure 2 , is a schematic diagram of the structure of an electronic device for implementing a method for visually detecting scratches on a metal surface provided by an embodiment of the present invention.
[0241] The electronic device 1 may include a processor 10 , a memory 11 , a communication interface 13 and a bus, and may also include a computer program stored in the memory 11 and executable on the processor 10 , such as a program 12 .
[0242] The memory 11 includes at least one type of readable storage medium, and the readable storage medium includes a flash memory, a mobile hard disk, a multimedia card, a card-type memory (e.g., SD or DX memory, etc.), a magnetic memory, a disk, an optical disk, etc. In some embodiments, the memory 11 may be an internal storage unit of the electronic device 1, such as a mobile hard disk of the electronic device 1. In other embodiments, the memory 11 may also be an external storage device of the electronic device 1, such as a plug-in mobile hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (SecureDigital, SD) card, a flash card (Flash Card), etc. equipped on the electronic device 1. Further, the memory 11 may also include both an internal storage unit of the electronic device 1 and an external storage device. The memory 11 may not only be used to store application software and various types of data installed in the electronic device 1, such as the code of the program 12, etc., but also be used to temporarily store data that has been output or is to be output.
[0243] The processor 10 may be composed of an integrated circuit in some embodiments, for example, a single packaged integrated circuit, or a plurality of packaged integrated circuits with the same or different functions, including one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and a combination of various control chips, etc. The processor 10 is the control core (Control Unit) of the electronic device, and uses various interfaces and lines to connect various components of the entire electronic device, and executes or executes programs or modules (such as a program 12 for realizing visual detection of metal surface scratches) stored in the memory 11, and calls data stored in the memory 11 to execute various functions of the electronic device 1 and process data.
[0244] The communication interface 13 may include a wired interface and / or a wireless interface (such as a WI-FI interface, a Bluetooth interface, etc.), which is generally used to establish a communication connection between the electronic device 1 and other electronic devices, and to achieve connection and communication between internal components of the electronic device.
[0245] The bus may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. The bus is configured to realize connection and communication between the memory 11 and at least one processor 10, etc.
[0246] Figure 2 Only an electronic device with components is shown, and those skilled in the art will understand that Figure 2 The structure shown does not constitute a limitation on the electronic device 1, and may include fewer or more components than shown in the figure, or combine certain components, or arrange the components differently.
[0247] For example, although not shown, the electronic device 1 may also include a power source (such as a battery) for supplying power to various components. Preferably, the power source may be logically connected to the at least one processor 10 through a power management device, so that the power management device can realize functions such as charging management, discharging management, and power consumption management. The power source may also include one or more DC or AC power sources, recharging devices, power failure detection circuits, power converters or inverters, power status indicators, and other arbitrary components. The electronic device 1 may also include a variety of sensors, Bluetooth modules, Wi-Fi modules, etc., which will not be repeated here.
[0248] Optionally, the electronic device 1 may further include a user interface, which may be a display, an input unit (such as a keyboard), or a standard wired interface or a wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, and an OLED (Organic Light-Emitting Diode) touch device. The display may also be appropriately referred to as a display screen or a display unit, which is used to display information processed in the electronic device 1 and to display a visual user interface.
[0249] It should be understood that the embodiment is for illustration only and the scope of the patent application is not limited to this structure.
[0250] The program 12 stored in the memory 11 in the electronic device 1 is a combination of multiple instructions. When running in the processor 10, it can achieve:
[0251] Collecting metal surface images and performing quantization processing on the image pixel contrast, and using the quantization processing result as the grayscale coefficient between pixels;
[0252] According to the gray-scale coefficient, a gray-scale energy function is constructed and optimized to obtain a gray-scale metal surface image;
[0253] Performing enhancement processing on the grayscale metal surface image to obtain an enhanced metal surface image;
[0254] Perform scratch detection on the enhanced metal surface image to identify scratches on the metal surface.
[0255] Specifically, the specific implementation method of the processor 10 for the above instructions can refer to Figure 1 to Figure 2 The description of the relevant steps in the corresponding embodiments will not be repeated here.
[0256] It should be noted that the serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages and disadvantages of the embodiments. And the terms "including", "comprising" or any other variants thereof in this article are intended to cover non-exclusive inclusion, so that a process, device, article or method including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, device, article or method. In the absence of further restrictions, an element defined by the sentence "including a ..." does not exclude the presence of other identical elements in the process, device, article or method including the element.
[0257] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present invention.
[0258] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A method for visually detecting scratches on a metal surface, characterized in that: The method comprises: S1: Collect metal surface images and perform quantization processing on image pixel contrast, and use the quantization processing result as the grayscale coefficient between pixels; Capturing images of metal surfaces , where the representation of the metal surface image is: ; in: Represents metal surface images The pixel value of the pixel at row x and column y, , , X represents the metal surface image The number of pixel rows, Y represents the metal surface image The number of pixel columns; Metal surface image The pixels of the image are quantized for contrast, and the quantization process of the image pixel contrast is as follows: S11: Acquire metal surface images The pixel value of the pixel in the image is split into the color values of the three color channels R, G, and B; the metal surface image The color values of the pixel in the xth row and yth column in the three color channels are , , ; S12: Calculate the pixel contrast between any two pixels; the pixel contrast between the pixel in the xth row and the yth column and the pixel in the ith row and the jth column is ; S13: quantize the pixel contrast, and use the quantization result as the grayscale coefficient between pixels; the grayscale coefficient between the pixel in the xth row and yth column and the pixel in the ith row and jth column is ; S2: constructing a grayscale energy function according to the grayscale coefficient and optimizing the function to obtain a grayscale metal surface image; The construction process of the grayscale energy function is: S21: extracting pixel contrast from the grayscale coefficients between pixels, and calculating the pixel similarity between different pixels based on the pixel contrast; wherein the pixel similarity between the pixel in the xth row and yth column and the pixel in the ith row and jth column is: ; in: Indicates the degree of pixel similarity between the pixel in the xth row and the yth column and the pixel in the ith row and the jth column; represents the control parameters; S22: Set the grayscale value of different pixels, where the metal surface image The gray value of the pixel in row x and column y is , the gray value is the parameter to be optimized; S23: Calculate the grayscale similarity of different pixels, where the grayscale similarity of the pixel in the xth row and yth column and the pixel in the ith row and jth column is: ; in: Indicates the grayscale similarity between the pixel in the xth row and the yth column and the pixel in the ith row and the jth column; S24: constructing a grayscale energy function, wherein the grayscale energy function takes the grayscale value of the pixel as the parameter to be optimized and takes minimizing the energy difference between the grayscale similarity and the pixel similarity as the optimization goal. The constructed grayscale energy function is: ; ; in: represents the grayscale energy function; Represents the grayscale matrix to be optimized; Represents metal surface images The set of pixel coordinates in ; Grayscale energy function Perform optimization and solution to obtain a grayscale metal surface image; Grayscale energy function Perform optimization and solution, where the optimization and solution process is: S241: Initialize and generate color weights of different color channels, where the color weights of the R, G, and B color channels generated by initialization are: , then the color weight The gray value of the corresponding pixel in row x and column y is ; S242: Set the current iteration number of the color weight to d and the maximum iteration number to Max. Then the color weight obtained in the dth iteration is , the initial value of d is 0; S243: iterate the color weight; S244: Set d = d + 1, return to step S243, until the maximum number of iterations is reached, and adjust the color weights Normalization is performed and the color weight obtained by normalization is used to adjust the metal surface image The pixels in the grayscale are processed to obtain the grayscale value of the pixel, where the grayscale value of the pixel in the xth row and yth column is ; S245: Constructing grayscale metal surface images ; S3: performing enhancement processing on the grayscale metal surface image to obtain an enhanced metal surface image; S4: Perform scratch detection on the enhanced metal surface image to identify scratches on the metal surface.
2. A metal surface scratch visual detection method as claimed in claim 1, characterized in that: The grayscale energy function Perform optimization and solve to obtain the grayscale metal surface image, including: Grayscale energy function Perform optimization and solution, where the optimization and solution process is: S241: Initialize and generate color weights of different color channels, where the color weights of the R, G, and B color channels generated by initialization are: , then the color weight The gray value of the corresponding pixel in row x and column y is ; S242: Set the current iteration number of the color weight to d and the maximum iteration number to Max. Then the color weight obtained in the dth iteration is , the initial value of d is 0; S243: iterate the color weight; S244: Set d = d + 1, return to step S243, until the maximum number of iterations is reached, and adjust the color weights Normalization is performed and the color weight obtained by normalization is used to adjust the metal surface image The pixels in the grayscale are processed to obtain the grayscale value of the pixel, where the grayscale value of the pixel in the xth row and yth column is ; S245: Constructing grayscale metal surface images .
3. A metal surface scratch visual detection method as claimed in claim 2, characterized in that: In the step S3, the grayscale metal surface image is enhanced, including: Grayscale metal surface image Enhanced processing is performed, in which the metal surface image is grayed The enhanced processing flow is: S31: Grayscale metal surface image The pixels in are represented by second-order differences to obtain the second-order difference matrix of the pixels; S32: using a Gaussian filter to perform Gaussian filtering on the second-order difference matrix of the pixels to obtain a second-order difference matrix after Gaussian filtering; S33: Perform eigendecomposition on the second-order difference matrix after Gaussian filtering to obtain the two maximum eigenvalues of the pixel, where the grayscale metal surface image The two largest eigenvalues of the pixel in row x and column y are , ; S34: Calculate the grayscale metal surface image The saliency value of any pixel in the grayscale metal surface image The saliency value of the pixel in row x and column y is ; S35: Combine the maximum eigenvalue and the significant value of the pixel to construct a multi-feature enhancement function of the pixel, and use the output result of the multi-feature enhancement function as the enhanced pixel value of the pixel, wherein the grayscale metal surface image The enhanced pixel value of the pixel in the xth row and yth column is ; S36: Constructing an enhanced metal surface image .
4. A metal surface scratch visual detection method as claimed in claim 3, characterized in that: In the step S35, the maximum eigenvalue and the saliency value of the pixel are combined to construct a multi-feature enhancement function of the pixel, including: The grayscale metal surface image The output of the multi-feature enhancement function for the pixel in the xth row and yth column is: ; in: Represents a grayscale metal surface image The output result of the multi-feature enhancement function corresponding to the pixel in the xth row and yth column.
5. A metal surface scratch visual detection method as claimed in claim 1, characterized in that: In step S4, scratch detection is performed on the enhanced metal surface image, including: Scratch detection is performed on the enhanced metal surface image U, where the scratch detection process is as follows: S41: Acquire an enhanced metal surface image U; S42: Extract the deep convolution features of the enhanced metal surface image U at different scales, where the deep convolution feature at the kth scale is ; S43: Calculate the probability information of scratches on the metal surface image U ; S44: If the probability information If it is higher than the preset threshold, it means that there are scratches on the metal surface image U.
6. A metal surface scratch visual detection method as claimed in claim 1, characterized in that: The process of determining the control parameters in step S21 includes: S211: Initialize and generate control parameters , set the upper bound of the control parameter and the lower bound ; S212: Set the current iteration number of the control parameter to c, and the maximum iteration number to C. Then the result of the cth iteration of the control parameter is , the initial value of c is 0; S213: According to the control parameters Calculate the pixel similarity information: ; ; ; in: Indicates the control parameters Pixel similarity information, Represents process parameters; Indicates the control parameters Under the condition, the pixel similarity between the pixel in the xth row and the yth column and the pixel in the ith row and the jth column; S214: if the pixel similarity information reaches a preset information threshold, terminating the iteration of the control parameters; If the pixel similarity information is less than the preset information threshold, Step length The reduction process, where represents a fixed step size, Represents a random number between 0 and 1; if the pixel similarity information is greater than the preset information threshold, Step length The process is continued until the maximum number of iterations is reached or the pixel similarity information reaches a preset information threshold.
Citation Information
Patent Citations
Chip surface scratch defect detection method and device and computer equipment
CN113781402A
Visual detection method for surface defects of water bucket
CN116612112A