Material surface color difference detection method based on image processing
Through the image processing method, the color distribution of each channel of the image is calculated, the target color is extracted and the color difference detection is performed, which solves the problems of inaccurate and unstable color difference detection in the prior art, and realizes the color difference detection with high accuracy and high stability under complex color backgrounds.
Patent Information
- Application Number
- CN202411857641.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-17
- Publication Date
- 2025-04-25
AI Technical Summary
The prior art has problems such as artificial fatigue, inability to quantify, inability to determine the direction of color deviation, susceptible to ambient light, and the inability to screen the color in the detection field of view in the material surface chromatic aberration detection, resulting in inaccurate and unstable detection results.
Using an image-based processing method, the color distribution of each channel in the image is calculated, the target color is extracted, and the noise interference is prevented, so as to achieve accurate color difference detection under complex color backgrounds. Specific steps include camera white balance, CCM calibration, image acquisition, standard color acquisition, target color extraction, color space conversion and color difference calculation.
It improves the stability and accuracy of inspection, can quickly distinguish materials such as lead-free and lead-based solder, and is suitable for the inspection of complex surface products, reducing the dependence on the environment.
Smart Images

Figure CN119887639A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the field of industrial visual color detection, in particular to a material surface color difference detection method based on image processing. Background Art
[0002] During the production process of materials, the content ratio of the material components will change with factors such as production formula and operational errors in the production process, and different content ratios determine key indicators such as material hardness and wear resistance. Among them, the color of the material is also determined by the content ratio of the material components. Therefore, testing whether the color of the material surface is consistent with the standard color is the most economical and fastest way to determine whether the material component content is qualified.
[0003] Take solder, which is widely used in PCB manufacturing, as an example: lead-containing solder is soft and prone to cracking of the solder layer. Although lead-free solder is brittle, it produces less slag after melting, has good anti-oxidation properties, reliable welding quality, and a higher melting point than lead-free solder. In terms of color, the surface of lead-containing solder looks bright white, while lead-free solder is light yellow. Therefore, in order to distinguish between lead-free and lead-containing solders, the surface color detection method can be used to classify them.
[0004] At present, the color difference detection of material surface mainly relies on manual observation, handheld colorimeter detection and other methods, but manual observation and handheld colorimeter detection have many problems:
[0005] 1. Human workers are very prone to fatigue and their sensitivity to color difference will continue to decrease.
[0006] 2. Manual detection cannot quantify color difference.
[0007] 3. Manual detection cannot determine in which direction the color deviates.
[0008] 4. Manual detection is easily affected by changes in ambient light.
[0009] 5. The handheld colorimeter cannot screen the colors within the detection field of view, but can only calculate the average value of all colors within the entire detection field of view, which leads to a large gap between the result and the actual color.
[0010] At present, there is an urgent need for a detection method that can replace manual observation and handheld colorimeter, and is suitable for detection of pure colors, dark patterns, gradients, lasers, etc., and has high robustness and high accuracy. Summary of the invention
[0011] The technical problem to be solved by the present invention is to provide a material surface color difference detection method based on image processing in view of the deficiencies of the above-mentioned prior art. The material surface color difference detection method based on image processing realizes the function of extracting the target color under a complex color background by calculating the color distribution of each channel in the image, prevents the influence of noise on the color difference detection result, greatly increases the stability, can quickly perform quality differentiation detection of lead-free and lead-containing solders, etc., and improves the accuracy of products for complex surface products.
[0012] In order to solve the above technical problems, the technical solution adopted by the present invention is:
[0013] A material surface color difference detection method based on image processing includes the following steps.
[0014] Step 1: White balance the camera.
[0015] Step 2: Camera CCM calibration.
[0016] Step 3, obtaining an image of the identified object: using a camera calibrated with white balance and CCM to photograph the surface of the identified object to be detected by color difference, to obtain an image of the identified object.
[0017] Step 4, obtaining standard color: obtaining the standard color of the surface of the object to be identified without color difference, and recording the grayscale values of the three RGB channels in the standard color as R-std, G-std and B-std respectively.
[0018] Step 5, extract target color: classify all colors in the recognition object image obtained in step 3, and find out the target colors close to the standard colors R-std, G-std and B-std in turn, and mark them as R-Target, G-Target and B-Target respectively.
[0019] Step 6, color space conversion: convert both the standard color and the target color to the CIELAB color space; wherein the values of the standard color in the CIELAB color space are denoted as Lstd, a*std, and b*std; and the values of the target color in the CIELAB color space are denoted as Ltarget, a*target, and b*target.
[0020] Step 7, calculate color difference: calculate the color difference value ΔE between the actual color of the surface of the object to be identified and the standard color. The specific calculation formula is:
[0021]
[0022] Step 8, color difference detection: When the color difference ΔE detected in step 7 does not exceed the set color difference threshold, it is determined that the surface of the object to be identified has no color difference; otherwise, it is determined that the surface of the object to be identified has color difference.
[0023] In step 1, the camera white balance method includes the following steps:
[0024] Step 1-1, Place the white balance paper: Place the white balance paper under the camera.
[0025] Step 1-2, Light Adjustment: Adjust the camera light source to the set brightness.
[0026] Step 1-3, adjust the maximum grayscale of the three channels, specifically including the following steps:
[0027] Step 1-3A, obtain RGB three-channel grayscale array: use the dimmed camera to shoot the white balanced paper below to obtain a color image; then, extract the grayscale values of the RGB three channels for all pixels in the color image, and record them in the corresponding three-channel grayscale arrays Rw, Gw, and Bw.
[0028] Step 1-3B, find the maximum grayscale of the three channels: find the maximum values of the three channel arrays Rw, Gw, and Bw respectively, and record them as Max[Rw], Max[Gw], and Max[Bw] respectively.
[0029] Step 1-3C, determine the maximum grayscale of the three channels: Find the maximum grayscale of the three channels in step 1-3B, and compare and determine according to the following formula:
[0030] Max[Rw]=a(1-1)
[0031] Max[Gw]=b (1-2)
[0032] Max[Bw]=c (1-3)
[0033] Where a, b and c are all set grayscale constants.
[0034] When step 1-3B searches for the maximum grayscale of the three channels and satisfies formulas (1-1) to (1-3), jump to step 1-4; otherwise, go to step 1-3D.
[0035] Step 1-3D, adjust the maximum grayscale of the three channels: adjust the camera exposure value, and repeat steps 1-3A to 1-3D until the maximum grayscale of the three channels meets formulas (1-1) to (1-3) at the same time.
[0036] Step 1-4, calculate the mean grayscale value of the three channels: for the three-channel grayscale arrays Rw, Gw, and Bw that satisfy formulas (1-1) to (1-3), calculate the mean respectively, and record them as Mean[Rw], Mean[Gw], and Mean[Bw] respectively; then, record the maximum value among Mean[Rw], Mean[Gw], and Mean[Bw] as Max[MeanW].
[0037] Step 1-5, calculate white balance parameters: White balance parameters include R channel white balance ratio Mean[Wr], G channel white balance ratio Mean[Wg] and B channel white balance ratio Mean[Wb]. The specific calculation formula is:
[0038]
[0039] Step 1-5, camera white balance: Apply the white balance parameters calculated in step 1-5 to the camera. After that, the images obtained by the camera are respectively calculated as follows in the RGB channels:
[0040] R=Rw×Mean[Wr]
[0041] G=Gw×Mean[Wg]
[0042] B=Bw×Mean[Wb]
[0043] Where Rw, Gw and Bw are the grayscale values of the RGB three channels corresponding to the color image directly captured by the camera.
[0044] R, G, and B are the grayscale values of the RGB three channels corresponding to the camera white balance.
[0045] In step 1-2, the brightness is set to 60% of the peak brightness; in step 1-3C, a=180±5, b=180±5, c=180±5.
[0046] In step 2, the camera CCM calibration method is: use a 3x3 CCM calibration matrix to correct the color in the color image taken by the camera after white balance; the 3x3 CCM calibration matrix is obtained by fitting the inverse matrix using the least squares method.
[0047] In step 2, the method of obtaining the CCM calibration matrix by fitting the inverse matrix using the least squares method includes the following steps:
[0048] Step 2-1: Use a 24-color card that meets international standards, use a white-balanced camera to obtain all images of the 24 colors, and obtain the average RGB value Mean[R,G,B] of all color images in turn, as shown below:
[0049]
[0050] Where R1, G1 and B1 are the RGB three-channel grayscale values of the image corresponding to the first color card in the international standard 24 color cards.
[0051] R2, G2 and B2 are the RGB three-channel grayscale values of the image corresponding to the second color card in the international standard 24 color cards.
[0052] R 24 , G 24 and B 24 They are respectively the RGB three-channel grayscale values of the image corresponding to the 24th color card in the international standard 24 color card.
[0053] Step 2-2, obtain the color value Std[R,G,B] of the international standard 24 color card:
[0054]
[0055] Where R'1, G'1 and B'1 are the RGB three-channel grayscale values of the image corresponding to the first color card in the international standard 24 color cards.
[0056] R'2, G'2 and B'2 are the RGB three-channel grayscale values of the image corresponding to the second color card in the international standard 24 color cards.
[0057] R' 24 , G' 24 and B' 24 They are respectively the RGB three-channel grayscale values of the image corresponding to the 24th color card in the international standard 24 color card.
[0058] Step 2-3: Use the least squares method to obtain the 3x3 CCM calibration matrix, as follows:
[0059] Mean[R,G,B]×CCM=Std[R,G,B]
[0060] CCM=inv(Mean[R,G,B] T ×Mean[R,G,B])×Mean[R,G,B] T ×Std[R,G,B]
[0061] It turns out that:
[0062]
[0063] In the formula, a 11 、a 12 、a 13 , b 11 , b 12 , b 13 、c 11、c 12 、c 13 are matrix elements.
[0064] Step 2-4: Apply the CCM calibration matrix to the color image after white balance, specifically:
[0065] R MN ′=R MN ×a 11 +G MN ×a 12 +B MN ×a 13
[0066] G MN ′=R MN ×b 11 +G MN ×b 12 +B MN ×b 13
[0067] B MN ′=R MN ×c 11 +G MN ×c 12 +B MN ×c 13
[0068] In the formula, R MN ', G MN ' and B MN 'Respectively represent the RGB three-channel grayscale values of the pixel at the Mth row and Nth column in the image after CCM calibration.
[0069] R MN , G MN and B MN They are the RGB three-channel grayscale values of the pixel in the Mth row and Nth column in the image before CCM calibration.
[0070] In step 5, the methods for finding R-Target, G-Target and B-Target are similar, wherein the method for finding R-Target includes the following steps:
[0071] Step 5-1, obtain the grayscale distribution of the R channel: obtain the grayscale value of each pixel in the image of the identified object on the R channel.
[0072] Step 5-2, grayscale frequency statistics: create a one-dimensional array R with a length of 256, which represents grayscale distribution values from 0 to 255; then, perform frequency statistics on the grayscale values of all pixels on the R channel obtained in step 5-1 at the corresponding grayscale distribution values of array R, so as to obtain the number of pixels of the identified object image corresponding to each grayscale value.
[0073] Step 5-3, draw a one-dimensional discrete function R(X): according to the grayscale frequency counted in step 5-2, draw a one-dimensional discrete function R(X) and smooth it; wherein the function independent variable X represents the grayscale value of 0 to 255, and the function dependent variable R(X) represents the number of pixels corresponding to the grayscale value X; the one-dimensional discrete function R(X) has multiple peaks and multiple troughs.
[0074] Step 5-4, find the trough: calculate the first-order derivative R'(X) and the second-order derivative R"(X) of the one-dimensional discrete function R(X); all points that satisfy R'(X)=0 and R"(X)>0 are the trough points to be found; suppose there are n trough points, and they are arranged in ascending order as follows: X1, X2, ..., X c , X c+1 ,……,X n ; Among them, 1≤c≤n.
[0075] Step 5-5, grayscale segmentation: According to the trough found in step 5-4, the array R is divided into n+1 segments, from small to large: the first segment 0~X1, the second segment X1~X2, the third segment X2~X3, ..., the cth segment Xc-1~Xc, the c+1th segment Xc~Xc+1, ..., the n+1th segment Xn~255; each segment corresponds to a color in the image of the identified object, totaling n+1 colors.
[0076] Step 5-6, calculate the average gray value of each color: for the n+1 colors in step 5-5, calculate the corresponding average gray value respectively.
[0077] Step 5-7, find R-Target: compare the average grayscale values of the n+1 colors calculated in step 5-6 with R-std, and record the average grayscale value of the color closest to R-std as R-Target.
[0078] In step 5-3, the one-dimensional discrete function R(X) is smoothed using the Gaussian filter model; in step 5-6, the average gray value Rgray of the c+1 segment c+1 The calculation formula is:
[0079]
[0080] In the formula, R(X c ) indicates that the gray value in the recognized object image is X c The number of pixels.
[0081] R(X c +1) indicates that the gray value of the recognized object image is X c +1 number of pixels.
[0082] R(X c+1 ) indicates that the gray value in the recognized object image is X c+1 The number of pixels.
[0083] In step 6, the color space conversion method includes the following steps:
[0084] Step 6-1, normalization: divide the standard color R-std, G-std and B-std, and the actual color R-Target, G-Target and B-Target by 255 to obtain the standard color normalization values r0, g0 and b0, and the actual color normalization values r1, g1 and b1.
[0085] Step 6-2, inverse gamma operation: perform inverse gamma operation on both the standard color normalization value and the actual color normalization value.
[0086] Among them, the inverse gamma values of the standard color normalization values r0, g0 and b0 are: Gamma_r0, Gamma_g0, Gamma_b0 respectively.
[0087] The inverse gamma values of the actual color normalization values r1, g1, and b1 are Gamma_r1, Gamma_g1, and Gamma_b1, respectively.
[0088] Step 6-3, XYZ color space conversion: convert the inverse gamma value of the standard color to the XYZ color space to obtain X0, Y0 and Z0, and convert the inverse gamma of the actual color to the XYZ color space to obtain X1, Y and Z1.
[0089] Step 6-4, CIELAB color space conversion: Convert both the standard color and the actual color from the XYZ color space to the CIELAB color space using the following formula (6-4A) or (6-4B).
[0090]
[0091]
[0092] in:
[0093]
[0094] Where F(W) is a piecewise function, and or or or or or
[0095] Xn0, Yn0 and Zn0 are the ideal white tristimulus values of standard colors respectively.
[0096] Xn1, Yn1 and Zn1 are the ideal white tristimulus values of the actual color.
[0097] In step 6-2, the inverse gamma operation formula of the standard color normalization value and the actual color normalization value is:
[0098]
[0099] Wherein, x is any value among r0, g0, b0, r1, g1 and b1.
[0100] In step 6-4, the ideal white tristimulus values of the standard color and the actual color are related to the emission properties of the surface of the object to be identified, specifically:
[0101] A. When the surface of the object to be identified is a diffuse reflective material surface, the ideal white tristimulus values of the standard color and the actual color are:
[0102]
[0103] B. When the surface of the object to be identified is a mirror-reflective material surface, the ideal white tristimulus values of the standard color and the actual color are:
[0104]
[0105] The present invention has the following beneficial effects:
[0106] 1. The present invention realizes the function of extracting target color under complex color background (such as pure color, dark pattern, gradient, laser, etc.) by calculating the color distribution of each channel in the image, preventing the influence of noise on the color difference detection result, greatly increasing the stability, and being able to quickly distinguish the quality of lead-free and lead-containing solders, and improve the accuracy of products for complex surface products.
[0107] 2. The present invention uses a simple 3x3 CCM color correction matrix calculated by the least squares method to fit the inverse matrix to perform color correction on the image obtained by the camera, thereby reducing the computing pressure caused by the CCM correction on the computing unit after each photo is taken, achieving a balance between computing performance and color correction, eliminating inconsistent results caused by hardware inconsistency between different devices, and ensuring that the color obtained by each device is consistent with the international standard color card.
[0108] 3. The present invention uses automatic color calculation and segmentation processing instead of manually fixed values, so it is less affected by the environment. In addition, the present invention can filter out interference colors in dark patterns, gradients, and lasers by classifying all colors in the image and automatically searching for close target colors according to target parameters. BRIEF DESCRIPTION OF THE DRAWINGS
[0109] Figure 1 The flowchart of a material surface color difference detection method based on image processing of the present invention is shown.
[0110] Figure 2 A schematic diagram of a one-dimensional discrete function R(X) plotted in the present invention is shown. DETAILED DESCRIPTION
[0111] The present invention will be further described in detail below in conjunction with the accompanying drawings and specific preferred embodiments.
[0112] like Figure 1 As shown, a material surface color difference detection method based on image processing includes the following steps.
[0113] Step 1: Camera white balance, preferably including the following steps.
[0114] Step 1-1, Place the white balance paper: Place the white balance paper under the camera.
[0115] Step 1-2, dimming: adjust the camera light source to a set brightness, preferably 60% of the peak brightness.
[0116] Step 1-3, adjusting the maximum grayscale of the three channels, specifically includes the following steps.
[0117] Step 1-3A, obtain RGB three-channel grayscale array: use the dimmed camera to shoot the white balanced paper below to obtain a color image; then, extract the grayscale values of the RGB three channels for all pixels in the color image, and record them in the corresponding three-channel grayscale arrays Rw, Gw, and Bw.
[0118] Step 1-3B, find the maximum grayscale of the three channels: find the maximum values of the three channel arrays Rw, Gw, and Bw respectively, and record them as Max[Rw], Max[Gw], and Max[Bw] respectively.
[0119] Step 1-3C, determine the maximum grayscale of the three channels: Find the maximum grayscale of the three channels in step 1-3B, and compare and determine according to the following formula:
[0120] Max[Rw]=a(1-1)
[0121] Max[Gw]=b (1-2)
[0122] Max[Bw]=c (1-3)
[0123] Wherein, a, b and c are all set grayscale constants. In this embodiment, preferably a=180±5, b=180±5, c=180±5.
[0124] When step 1-3B searches for the maximum grayscale of the three channels and satisfies formulas (1-1) to (1-3), jump to step 1-4; otherwise, go to step 1-3D.
[0125] Step 1-3D, adjust the maximum grayscale of the three channels: adjust the camera exposure value, and repeat steps 1-3A to 1-3D until the maximum grayscale of the three channels meets formulas (1-1) to (1-3) at the same time.
[0126] Step 1-4, calculate the mean grayscale value of the three channels: for the three-channel grayscale arrays Rw, Gw, and Bw that satisfy formulas (1-1) to (1-3), calculate the mean respectively, and record them as Mean[Rw], Mean[Gw], and Mean[Bw] respectively; then, record the maximum value among Mean[Rw], Mean[Gw], and Mean[Bw] as Max[MeanW].
[0127] Step 1-5, calculate white balance parameters: White balance parameters include R channel white balance ratio Mean[Wr], G channel white balance ratio Mean[Wg] and B channel white balance ratio Mean[Wb]. The specific calculation formula is:
[0128]
[0129] Step 1-5, camera white balance: Apply the white balance parameters calculated in step 1-5 to the camera. After that, the images obtained by the camera are respectively calculated as follows in the RGB channels:
[0130] R=Rw×Mean[Wr]
[0131] G=Gw×Mean[Wg]
[0132] B=Bw×Mean[Wb]
[0133] Where Rw, Gw and Bw are the grayscale values of the RGB three channels corresponding to the color image directly captured by the camera.
[0134] R, G, and B are the grayscale values of the RGB three channels corresponding to the camera white balance.
[0135] Step 2, camera CCM calibration: preferably, a 3x3 CCM calibration matrix is used to correct the colors in the color image taken by the camera after white balance; wherein, the 3x3 CCM calibration matrix is preferably obtained by fitting the inverse matrix using the least squares method.
[0136] The above method of obtaining the CCM calibration matrix by fitting the inverse matrix using the least squares method preferably includes the following steps.
[0137] Step 2-1: Use a 24-color card that meets international standards, use a white-balanced camera to obtain all images of the 24 colors, and obtain the average RGB value Mean[R,G,B] of all color images in turn, as shown below:
[0138]
[0139] Where R1, G1 and B1 are the RGB three-channel grayscale values of the image corresponding to the first color card in the international standard 24 color cards.
[0140] R2, G2 and B2 are the RGB three-channel grayscale values of the image corresponding to the second color card in the international standard 24 color cards.
[0141] R 24 , G 24 and B 24 They are respectively the RGB three-channel grayscale values of the image corresponding to the 24th color card in the international standard 24 color card.
[0142] The present invention uses a 24-color card that complies with international standards. Compared with the traditional method of using visible light of different wavelengths to obtain standard colors, the use of the color card does not rely on the production process of the light source, is simpler, more efficient and has lower costs.
[0143] Step 2-2, obtain the color value Std[R,G,B] of the international standard 24 color card:
[0144]
[0145] Where R'1, G'1 and B'1 are the RGB three-channel grayscale values of the image corresponding to the first color card in the international standard 24 color cards.
[0146] R'2, G'2 and B'2 are the RGB three-channel grayscale values of the image corresponding to the second color card in the international standard 24 color cards.
[0147] R' 24 , G' 24 and B' 24 They are respectively the RGB three-channel grayscale values of the image corresponding to the 24th color card in the international standard 24 color card.
[0148] Step 2-3: Use the least squares method to obtain the 3x3 CCM calibration matrix, as follows:
[0149] Mean[R,G,B]×CCM=Std[R,G,B]
[0150] CCM=inv(Mean[R,G,B] T×Mean[R,G,B])×Mean[R,G,B] T ×Std[R,G,B]
[0151] It turns out that:
[0152]
[0153] In the formula, a 11 、a 12 、a 13 , b 11 , b 12 , b 13 、c 11 、c 12 、c 13 are matrix elements.
[0154] Step 2-4: Apply the CCM calibration matrix to the color image after white balance, specifically:
[0155] R MN ′=R MN ×a 11 +G MN ×a 12 +B MN ×a 13
[0156] G MN ′=R MN ×b 11 +G MN ×b 12 +B MN ×b 13
[0157] B MN ′=R MN ×c 11 +G MN ×c 12 +B MN ×c 13
[0158] In the formula, R MN ', G MN ' and B MN 'Respectively represent the RGB three-channel grayscale values of the pixel at the Mth row and Nth column in the image after CCM calibration.
[0159] R MN , G MN and B MN They are the RGB three-channel grayscale values of the pixel in the Mth row and Nth column in the image before CCM calibration.
[0160] Step 3, obtaining an image of the identified object: using a camera calibrated with white balance and CCM to photograph the surface of the identified object to be detected by color difference, to obtain an image of the identified object.
[0161] Step 4, obtaining standard color: obtaining the standard color of the surface of the object to be identified without color difference, and recording the grayscale values of the three RGB channels in the standard color as R-std, G-std and B-std respectively.
[0162] Step 5, extract target color: classify all colors in the recognition object image obtained in step 3, and find out the target colors close to the standard colors R-std, G-std and B-std in turn, and mark them as R-Target, G-Target and B-Target respectively.
[0163] The above-mentioned methods for searching R-Target, G-Target and B-Target are similar. In this embodiment, R-Target is taken as an example for detailed description. The searching method preferably includes the following steps.
[0164] Step 5-1, obtain the grayscale distribution of the R channel: obtain the grayscale value of each pixel in the image of the identified object on the R channel.
[0165] Step 5-2, grayscale frequency statistics: create a one-dimensional array R with a length of 256, which represents grayscale distribution values from 0 to 255; then, perform frequency statistics on the grayscale values of all pixels on the R channel obtained in step 5-1 at the corresponding grayscale distribution values of array R, so as to obtain the number of pixels of the identified object image corresponding to each grayscale value.
[0166] Step 5-3, draw a one-dimensional discrete function R(X): according to the grayscale frequency counted in step 5-2, draw a one-dimensional discrete function R(X) and preferably use a Gaussian filter model exp(X) for smoothing; wherein the function independent variable X represents a grayscale value of 0 to 255, and the function dependent variable R(X) represents the number of pixels corresponding to the grayscale value X; Figure 2 As shown, the one-dimensional discrete function R(X) has multiple peaks and multiple valleys.
[0167] Step 5-4, find the trough: calculate the first-order derivative R'(X) and the second-order derivative R"(X) of the one-dimensional discrete function R(X); all points that satisfy R'(X)=0 and R"(X)>0 are the trough points to be found; suppose there are n trough points, and they are arranged in ascending order as follows: X1, X2, ..., X c , X c+1 ,……,X n ; where 1≤c≤n.
[0168] The above-mentioned method for finding the trough preferably includes the following steps.
[0169] Step 5-4A, find the first-order derivative g(X) of R(X), and take the solution with g(X) value of 0. Because the function solution may not be unique, the solution corresponding to g(X)=0 is placed in the array X', and the array values are sorted from small to large;
[0170] Step 5-4B, find the second-order derivative h(X) of R(X), and take the solution with a positive h(X) value. Because the function solution may not be unique, put the solution corresponding to h(X)=0 into the array "X", and sort the array values from small to large;
[0171] g(X)=R'(X)
[0172] h(X)=R”(X)=g'(X)
[0173] Step 5-4C, take the intersection of X' and X", the intersection array is X, when the independent variable of R(X) is the value in array X, the function value of R(X) is the trough of the image, the array values are sorted from small to large, that is:
[0174] X=X'∩X"=[X1,X2,...,X n ]
[0175] Step 5-5, grayscale segmentation: According to the trough found in step 5-4, the array R is divided into n+1 segments, from small to large: the first segment 0~X1, the second segment X1~X2, the third segment X2~X3, ..., the cth segment Xc-1~Xc, the c+1th segment Xc~Xc+1, ..., the n+1th segment Xn~255; each segment corresponds to a color in the image of the identified object, totaling n+1 colors.
[0176] Step 5-6, calculate the average gray value of each color: For the n+1 colors in step 5-5, calculate the corresponding average gray value. Among them, the average gray value Rgray of the c+1 segment c+1 The calculation formula is:
[0177]
[0178] In the formula, R(X c ) indicates that the gray value in the recognized object image is X c The number of pixels.
[0179] R(X c +1) indicates that the gray value of the recognized object image is X c +1 number of pixels.
[0180] R(X c+1 ) indicates that the gray value in the recognized object image is Xc+1 The number of pixels.
[0181] Step 5-7, find R-Target: compare the average grayscale values of the n+1 colors calculated in step 5-6 with R-std, and record the average grayscale value of the color closest to R-std as R-Target.
[0182] Generally, colorimeters do not process the collected image data when calculating color difference, but take the average value of all colors in the field of view, which results in accuracy only when measuring the surface of pure-color products. When measuring complex surfaces with dark patterns, gradients, lasers, etc., mixed colors will be mixed into the target color to be measured, resulting in deviation in the results. The present invention extracts the target color, and can filter out interference colors in dark patterns, gradients, and lasers by classifying all colors in the image and automatically searching for close target colors according to target parameters.
[0183] Step 6, color space conversion: convert both the standard color and the target color to the CIELAB color space; wherein the values of the standard color in the CIELAB color space are denoted as Lstd, a*std, and b*std; and the values of the target color in the CIELAB color space are denoted as Ltarget, a*target, and b*target.
[0184] The above-mentioned color space conversion method preferably includes the following steps.
[0185] Step 6-1, normalization: divide the standard color R-std, G-std and B-std, and the actual color R-Target, G-Target and B-Target by 255 to obtain the standard color normalization values r0, g0 and b0, and the actual color normalization values r1, g1 and b1.
[0186] Step 6-2, anti-gamma operation: both the standard color and the actual color normalization value are subjected to anti-gamma operation, and the preferred calculation formula is:
[0187]
[0188] Wherein, x is any value among r0, g0, b0, r1, g1 and b1.
[0189] After the inverse gamma operation is completed, the inverse gamma values of the standard color normalization values r0, g0, and b0 are: Gamma_r0, Gamma_g0, Gamma_b0 respectively.
[0190] The inverse gamma values of the actual color normalization values r1, g1, and b1 are Gamma_r1, Gamma_g1, and Gamma_b1, respectively.
[0191] Step 6-3, XYZ color space conversion
[0192] Convert the inverse gamma value of the standard color to the XYZ color space to obtain X0, Y0, and Z0. Convert the inverse gamma of the actual color to the XYZ color space to obtain X1, Y, and Z1. The specific calculation formula is as follows:
[0193]
[0194] Step 6-4, CIELAB color space conversion: Convert both the standard color and the actual color from the XYZ color space to the CIELAB color space using the following formula (6-4A) or (6-4B).
[0195]
[0196] in:
[0197]
[0198] Where F(W) is a piecewise function, and or or or or or
[0199] Xn0, Yn0 and Zn0 are the ideal white tristimulus values of standard colors respectively.
[0200] Xn1, Yn1 and Zn1 are the ideal white tristimulus values of the actual color.
[0201] The ideal white tristimulus values of the above standard colors and actual colors are related to the surface emission properties of the object to be identified, specifically:
[0202] A. When the surface of the object to be identified is a diffuse reflective material surface, the ideal white tristimulus values of the standard color and the actual color are:
[0203]
[0204] B. When the surface of the object to be identified is a mirror-reflective material surface, the ideal white tristimulus values of the standard color and the actual color are:
[0205]
[0206] Step 7, calculate color difference: calculate the color difference value ΔE between the actual color of the surface of the object to be identified and the standard color. The specific calculation formula is:
[0207]
[0208] Step 8, color difference detection: When the color difference ΔE detected in step 7 does not exceed the set color difference threshold, it is determined that the surface of the object to be identified has no color difference; otherwise, it is determined that the surface of the object to be identified has color difference.
[0209] The preferred embodiments of the present invention are described in detail above; however, the present invention is not limited to the specific details in the above embodiments. Within the technical concept of the present invention, various equivalent transformations can be made to the technical solutions of the present invention, and these equivalent transformations all belong to the protection scope of the present invention.
Claims
1. A material surface color difference detection method based on image processing, characterized in that: The steps include: Step 1: White balance the camera; Step 2: Camera CCM calibration; Step 3, obtaining an image of the identified object: using a camera calibrated with white balance and CCM to shoot the surface of the identified object to be detected by color difference, to obtain an image of the identified object; Step 4, obtaining standard color: obtaining the standard color of the surface of the object to be identified without color difference, and recording the grayscale values of the three channels of RGB in the standard color as R-std, G-std and B-std respectively; Step 5, extracting the target color: classify all the colors in the recognition object image obtained in step 3, and find the target colors close to the standard colors R-std, G-std and B-std in turn, and mark them as R-Target, G-Target and B-Target respectively; Step 6, color space conversion: convert both the standard color and the target color to the CIELAB color space; wherein the values of the standard color in the CIELAB color space are respectively recorded as Lstd, a*std and b*std; the values of the target color in the CIELAB color space are respectively recorded as Ltarget, a*target and b*target; Step 7, calculate color difference: calculate the color difference value ΔE between the actual color of the surface of the object to be identified and the standard color. The specific calculation formula is: Step 8, color difference detection: When the color difference ΔE detected in step 7 does not exceed the set color difference threshold, it is determined that the surface of the object to be identified has no color difference; otherwise, it is determined that the surface of the object to be identified has color difference.
2. The material surface color difference detection method based on image processing according to claim 1 is characterized in that: In step 1, the camera white balance method includes the following steps: Step 1-1, place the white balance paper: Place the white balance paper under the camera; Step 1-2, light adjustment: adjust the camera light source to the set brightness; Step 1-3, adjust the maximum grayscale of the three channels, specifically including the following steps: Step 1-3A, obtain RGB three-channel grayscale array: use the dimmed camera to shoot the white-balanced paper below to obtain a color image; then, extract the grayscale values of the RGB three channels for all pixels in the color image, and record them in the corresponding three-channel grayscale arrays Rw, Gw, and Bw; Step 1-3B, find the maximum grayscale of the three channels: find the maximum values of the three channel arrays Rw, Gw, and Bw respectively, and record them as Max[Rw], Max[Gw], and Max[Bw] respectively; Step 1-3C, determine the maximum grayscale of the three channels: Find the maximum grayscale of the three channels in step 1-3B, and compare and determine according to the following formula: Max[Rw]=a(1-1) Max[Gw]=b (1-2) Max[Bw]=c (1-3) In the formula, a, b and c are all set grayscale constants; When step 1-3B searches for the maximum grayscale of the three channels and satisfies formulas (1-1) to (1-3), jump to step 1-4; otherwise, go to step 1-3D; Step 1-3D, adjust the maximum grayscale of the three channels: adjust the camera exposure value, and repeat steps 1-3A to 1-3D until the maximum grayscale of the three channels meets formulas (1-1) to (1-3) at the same time; Step 1-4, calculate the mean grayscale value of the three channels: for the three-channel grayscale arrays Rw, Gw, and Bw that satisfy formulas (1-1) to (1-3), calculate the mean value respectively, and record them as Mean[Rw], Mean[Gw], and Mean[Bw] respectively; then, record the maximum value among Mean[Rw], Mean[Gw], and Mean[Bw] as Max[MeanW]; Step 1-5, calculate white balance parameters: White balance parameters include R channel white balance ratio Mean[Wr], G channel white balance ratio Mean[Wg] and B channel white balance ratio Mean[Wb]. The specific calculation formula is: Step 1-5, camera white balance: Apply the white balance parameters calculated in step 1-5 to the camera. After that, the images obtained by the camera are respectively calculated as follows in the RGB channels: R=Rw×Mean[Wr] G=Gw×Mean[Wg] B=Bw×Mean[Wb] In the formula, Rw, Gw and Bw are the grayscale values of the RGB three channels corresponding to the color image directly captured by the camera; R, G, and B are the grayscale values of the RGB three channels corresponding to the camera white balance.
3. The material surface color difference detection method based on image processing according to claim 2 is characterized in that: In step 1-2, the brightness is set to 60% of the peak brightness; in step 1-3C, a=180±5, b=180±5, c=180±5.
4. The material surface color difference detection method based on image processing according to claim 1 is characterized in that: In step 2, the camera CCM calibration method is: use a 3x3 CCM calibration matrix to correct the color in the color image taken by the camera after white balance; the 3x3 CCM calibration matrix is obtained by fitting the inverse matrix using the least squares method.
5. The material surface color difference detection method based on image processing according to claim 4 is characterized in that: In step 2, the method of obtaining the CCM calibration matrix by fitting the inverse matrix using the least squares method includes the following steps: Step 2-1: Use a 24-color card that meets international standards, use a white-balanced camera to obtain all images of the 24 colors, and obtain the average RGB value Mean[R,G,B] of all color images in turn, as shown below: Where, R1, G1 and B1 are the RGB three-channel grayscale values of the image corresponding to the first color card in the international standard 24 color cards; R2, G2 and B2 are the RGB three-channel grayscale values of the image corresponding to the second color card in the international standard 24 color cards; R 24 , G 24 and B 24 They are the RGB three-channel grayscale values of the image corresponding to the 24th color card in the international standard 24 color cards; Step 2-2, obtain the color value Std[R,G,B] of the international standard 24 color card: Where, R'1, G'1 and B'1 are the RGB three-channel grayscale values of the image corresponding to the first color card in the international standard 24 color cards; R'2, G'2 and B'2 are the RGB three-channel grayscale values of the image corresponding to the second color card in the international standard 24 color cards; R' 24 , G' 24 and B' 24 They are the RGB three-channel grayscale values of the image corresponding to the 24th color card in the international standard 24 color card; Step 2-3: Use the least squares method to obtain the 3x3 CCM calibration matrix, as follows: Mean[R,G,B]×CCM=Std[R,G,B] CCM=inv(Mean[R,G,B] T ×Mean[R,G,B])×Mean[R,G,B] T ×Std[R,G,B] It turns out that: In the formula, a 11 、a 12 、a 13 , b 11 , b 12 , b 13 、c 11 、c 12 、c 13 are matrix elements; Step 2-4: Apply the CCM calibration matrix to the color image after white balance, specifically: R MN ′=R MN ×a 11 +G MN ×a 12 +B MN ×a 13 G MN ′=R MN ×b 11 +G MN ×b 12 +B MN ×b 13 B MN ′=R MN ×c 11 +G MN ×c 12 +B MN ×c 13 In the formula, R MN ', G MN ' and B MN ' are the RGB three-channel grayscale values of the pixel point in the Mth row and Nth column of the image after CCM calibration; R MN , G MN and B MN They are the RGB three-channel grayscale values of the pixel in the Mth row and Nth column in the image before CCM calibration.
6. The material surface color difference detection method based on image processing according to claim 1 is characterized in that: In step 5, the methods for finding R-Target, G-Target and B-Target are similar, wherein the method for finding R-Target includes the following steps: Step 5-1, obtain the grayscale distribution of the R channel: obtain the grayscale value of each pixel in the image of the identified object on the R channel; Step 5-2, grayscale frequency statistics: create a one-dimensional array R with a length of 256, which represents grayscale distribution values from 0 to 255; then, the grayscale values of all pixels on the R channel obtained in step 5-1 are counted at the corresponding grayscale distribution values of the array R, so as to obtain the number of pixels of the identified object image corresponding to each grayscale value; Step 5-3, draw a one-dimensional discrete function R(X): according to the grayscale frequency counted in step 5-2, draw a one-dimensional discrete function R(X) and smooth it; wherein the function independent variable X represents the grayscale value of 0 to 255, and the function dependent variable R(X) represents the number of pixels corresponding to the grayscale value X; the one-dimensional discrete function R(X) has multiple peaks and multiple troughs; Step 5-4, find the trough: calculate the first-order derivative R'(X) and the second-order derivative R"(X) of the one-dimensional discrete function R(X); all points that satisfy R'(X)=0 and R"(X)>0 are the trough points to be found; suppose there are n trough points, and they are arranged in ascending order as follows: X1, X2, ..., X c , X c+1 ,……,X n ; Among them, 1≤c≤n; Step 5-5, grayscale segmentation: According to the trough found in step 5-4, the array R is divided into n+1 segments, from small to large, the first segment 0 to X1, the second segment X1 to X2, the third segment X2 to X3, ..., the cth segment Xc-1 to Xc, the c+1th segment Xc to Xc+1, ..., the n+1th segment Xn to 255; each segment corresponds to a color in the image of the identified object, for a total of n+1 colors; Step 5-6, calculate the average gray value of each color: for the n+1 colors in step 5-5, calculate the corresponding average gray value respectively; Step 5-7, find R-Target: compare the average grayscale values of the n+1 colors calculated in step 5-6 with R-std, and record the average grayscale value of the color closest to R-std as R-Target.
7. The material surface color difference detection method based on image processing according to claim 6 is characterized in that: In step 5-3, the one-dimensional discrete function R(X) is smoothed using the Gaussian filter model; in step 5-6, the average gray value Rgray of the c+1 segment c+1 The calculation formula is: In the formula, R(X c ) indicates that the gray value in the recognized object image is X c The number of pixels; R(X c +1) indicates that the gray value of the recognized object image is X c +1 number of pixels; R(X c+1 ) indicates that the gray value in the recognized object image is X c+1 The number of pixels.
8. The material surface color difference detection method based on image processing according to claim 1 is characterized in that: In step 6, the color space conversion method includes the following steps: Step 6-1, normalization: divide the standard color R-std, G-std and B-std, and the actual color R-Target, G-Target and B-Target by 255 to obtain the standard color normalization values r0, g0 and b0, and the actual color normalization values r1, g1 and b1; Step 6-2, inverse gamma operation: perform inverse gamma operation on both the standard color normalization value and the actual color normalization value; wherein, the inverse gamma values of the standard color normalization values r0, g0 and b0 are respectively: Gamma_r0, Gamma_g0, Gamma_b0; the inverse gamma values of the actual color normalization values r1, g1 and b1 are respectively: Gamma_r1, Gamma_g1, Gamma_b1; Step 6-3, XYZ color space conversion: convert the inverse gamma value of the standard color to the XYZ color space to obtain X0, Y0 and Z0, and convert the inverse gamma of the actual color to the XYZ color space to obtain X1, Y and Z1; Step 6-4, CIELAB color space conversion: convert both the standard color and the actual color from the XYZ color space to the CIELAB color space using the following formula (6-4A) or (6-4B); in: Where F(W) is a piecewise function, and or or or or or Xn0, Yn0 and Zn0 are the ideal white tristimulus values of standard colors respectively; Xn1, Yn1 and Zn1 are the ideal white tristimulus values of the actual color.
9. The material surface color difference detection method based on image processing according to claim 8, characterized in that: In step 6-2, the inverse gamma operation formula of the standard color normalization value and the actual color normalization value is: Wherein, x is any value among r0, g0, b0, r1, g1 and b1.
10. The material surface color difference detection method based on image processing according to claim 8, characterized in that: In step 6-4, the ideal white tristimulus values of the standard color and the actual color are related to the emission properties of the surface of the object to be identified, specifically: A. When the surface of the object to be identified is a diffuse reflective material surface, the ideal white tristimulus values of the standard color and the actual color are: B. When the surface of the object to be identified is a mirror-reflective material surface, the ideal white tristimulus values of the standard color and the actual color are:
Citation Information
Patent Citations
A method for detecting the appearance color of an ultra-thin flexible IC substrate
CN109003268A
Method, system and device for detecting color difference based on machine vision and storage medium
CN109141640A
Color difference analysis / detection method and system for fair-faced concrete
CN111681289A
Self-adaptive color correction method and system
CN119130870A
Color difference analysis / detection method and system for fair-faced concrete
WO2021248915A1