Product surface paint layer color difference detection method and system
By converting images to the LAB color space and combining Gaussian blur, Otsu's method, and K-means clustering, the efficiency and accuracy problems of color difference detection in complex industrial scenarios are solved, achieving efficient and accurate color difference detection.
Patent Information
- Application Number
- CN202511209073.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-27
- Publication Date
- 2025-11-21
AI Technical Summary
Existing technologies struggle to achieve efficient and accurate color difference detection of product surface paint layers in complex industrial scenarios. They are prone to false detections or missed detections, especially when there is interference from multiple colors or local color differences. Furthermore, they consume a lot of computing resources and cannot meet the needs of real-time detection.
A method combining LAB color space conversion with Gaussian blur, Otsu's method, and K-means clustering is used for foreground segmentation and region merging for noise reduction, achieving high-precision color difference detection.
It achieves efficient and accurate paint color difference detection, enabling real-time and rapid detection of subtle differences in complex industrial scenarios, significantly improving detection efficiency and quality assessment accuracy.
Smart Images

Figure CN120997519A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to color difference detection, specifically to a method and system for detecting color difference in paint layers on product surfaces, belonging to the field of industrial appearance inspection technology. Background Technology
[0002] With advancements in industrial manufacturing technology, the quality of the paint layer on a product's surface directly impacts its appearance and market competitiveness. Color difference in the paint layer is a common quality issue during production, potentially leading to batch discrepancies, increased customer complaints, and even damage to brand image. Traditional color difference detection relies primarily on manual visual inspection or spectrophotometer measurement. However, manual inspection is inefficient, subjective, and prone to visual fatigue, while spectrophotometers are only suitable for small-area spot measurements, making comprehensive and efficient surface color difference detection difficult.
[0003] In recent years, computer vision-based color difference detection methods have been increasingly applied in industrial production. For example, Chinese invention patent CN119779998A proposes a color difference detection method based on the LAB color space. This method calculates the color difference by comparing the LAB values of sampling points with the LAB values of the standard color difference. However, this method has certain limitations in complex industrial scenarios: on the one hand, the number of sampling points may lead to errors in color difference calculation; on the other hand, this method relies on high computing resources, making it difficult to meet real-time detection requirements. Furthermore, existing methods often lack robustness when dealing with multi-color interference or local color differences, leading to false detections or missed detections.
[0004] Therefore, how to effectively detect subtle differences in the surface color of products in complex industrial scenarios has become an urgent problem to be solved in the field of industrial appearance inspection. Summary of the Invention
[0005] To address the aforementioned shortcomings of existing technologies, the present invention aims to provide a method and system for detecting color differences in paint layers on product surfaces. This invention converts the original image to a LAB color space image and integrates foreground segmentation techniques such as Gaussian blur and Otsu's method with K-means clustering combined with region merging and denoising methods to achieve high-precision and high-efficiency paint color difference detection. It can detect subtle differences in product surface color in real time and quickly in complex industrial scenarios.
[0006] The technical solution of this invention is implemented as follows: A method for detecting color difference in paint layer on product surface, comprising the following steps:
[0007] Step S1, Color Space Conversion: The selected area of the surface of the product to be inspected is acquired by the photographic equipment and used as the original image. The original image is converted from the RGB color space to the LAB color space to obtain the LAB image.
[0008] Step S2, Foreground Segmentation: Convert the LAB image to a grayscale image, process the grayscale image using Gaussian blur, then perform threshold segmentation using Otsu's method to obtain a binarized image, then process the binarized image using morphological closing operation, and finally obtain the foreground mask through connected component analysis, selecting the connected component with the largest area as the foreground mask to be detected, thereby realizing the extraction of the object to be detected;
[0009] Step S3, Color Grading: Obtain the coordinates of all foreground pixels in the foreground mask to be detected, extract the LAB values of all foreground pixels corresponding to the coordinates in the LAB image, then set the number of cluster centers, use the K-means algorithm to cluster the LAB values of all foreground pixels in the foreground mask to be detected, obtain cluster labels and cluster centers, and realize color grading of all foreground pixels in the foreground mask to be detected.
[0010] Step S4, Denoising: Set a minimum area and use a region merging denoising function to optimize the cluster labels, eliminate noise with too small an area, and automatically integrate areas smaller than the minimum area into the surrounding color level areas to achieve denoising of the cluster label array.
[0011] Step S5, color difference calculation: Calculate the color difference between cluster centers, set a color difference threshold, and take cluster center pairs whose distance is greater than the color difference threshold as significant color difference pairs;
[0012] Step S6, Visualization Processing: Cover each color region with a mask of the same color, and the mask colors of different color regions are different, thereby generating a visualization result of color grading; then retain the mask of the color region corresponding to the cluster center with significant color difference pairs, and remove the mask of the color region corresponding to the cluster center without significant color difference pairs, thereby generating a visualization result of regions with significant color difference.
[0013] Further, the original image described in step S1 is converted from the RGB color space to the LAB color space in the following way to obtain the first pure color image to be detected;
[0014] First, normalize the original red, green, and blue components r, g, and b of each pixel in the original image to R, G, and B in the range [0,1] using the following formula:
[0015]
[0016] Then, through a linear transformation, the normalized R, G, and B are converted into the three components X, Y, and Z of the XYZ color space, as shown in the following formula:
[0017]
[0018] Then, the L, a, and b of the image are calculated using the following formula:
[0019]
[0020] Among them, X ref_white Y ref_white With Z ref_white The tristimulus values of white in the XYZ color space are a set of predefined reference values used to normalize X, Y, and Z. Through the above steps, the conversion from RGB image to LAB color space is completed, and the L, a, and b values of each pixel are obtained for subsequent color difference calculation.
[0021] Furthermore, the specific process of foreground segmentation in step S2 is as follows:
[0022] The red, green, and blue components (R, G, B) of the LAB image corresponding to the color image are converted to grayscale values using grayscale conversion. The grayscale conversion formula is as follows:
[0023] Gray(p)=0.299R(p)+0.587G(p)+0.114B(p);
[0024] Next, Gaussian blurring is applied to the grayscale image. A Gaussian kernel function G(x,y) is defined to smooth the grayscale image. The Gaussian kernel formula is: Where σ is the Gaussian blur radius, controlling the degree of blurring, and (x,y) are the coordinates of the pixel; the grayscale image Gray is convolved with the Gaussian kernel G to obtain the blurred grayscale image Gray. blur The calculation formula is as follows:
[0025]
[0026] Then, threshold segmentation is performed using the Otsu method, and the gray-level histogram of the blurred gray-level image is statistically analyzed to obtain the binarized image.
[0027] A morphological closing operation is performed on the binarized image using an elliptical structuring element B. The binary image is first dilated and then eroded to fill foreground holes and smooth the boundaries. The closing operation formula is as follows:
[0028]
[0029] The expansion ⊕ is defined as: (Bin⊕B)(p)=max (x,y)∈B Bin(p+x,p+y); Corrosion Defined as:
[0030] For the binarized image after the closing operation, all connected regions are labeled, the pixel area of each connected region is calculated, and the connected region with the largest area is selected as the foreground mask to be detected for the paint layer on the product surface. The calculation formula is as follows:
[0031]
[0032] Where A k Foreground mask to be detected, Region k This represents the k-th connected region, thus completing the foreground segmentation process of the image.
[0033] Furthermore, the specific operation of the Otsu method for threshold segmentation to obtain a binarized image is as follows:
[0034] Calculate the grayscale histogram of the blurred grayscale image and perform normalization. The normalization formula is:
[0035]
[0036] Where i is the grayscale value, N is the total number of pixels in the image, and p i Let n be the probability distribution of a pixel with gray value i appearing in the entire image. i This represents the number of pixels with a grayscale value of i.
[0037] Then, iterating through all possible thresholds T∈[0,255], the image pixels are divided into foreground (gray level 0~T) and background (gray level T+1~255). The formula for calculating the mean gray level of the foreground and background classes is as follows:
[0038]
[0039] Where μ0 is the average gray level of the foreground; μ1 is the average gray level of the background; w0 is the probability of the foreground pixel; and w1 is the probability of the background pixel.
[0040] Calculate the between-class variance:
[0041]
[0042] Where, μ total The total grayscale value is then selected to minimize the inter-class variance. Maximum threshold T * As the optimal segmentation threshold:
[0043] Finally, image binarization is performed, dividing the image into foreground 0 and background 1, thus obtaining the binarized image.
[0044] Further, in step S3, based on the color differences in the image to be detected, the K-means clustering algorithm is used to cluster the LAB values of the foreground pixels to obtain cluster labels and cluster centers. The specific steps are as follows:
[0045] Set the number of cluster centers to K, and the LAB value x of the pixels within the foreground mask to be detected. i =(L i ,a i ,b i Perform K-means clustering to divide the pixels into K categories {c1, c2, ..., c3}. K The objective function formula for clustering is:
[0046]
[0047] Wherein, the center vector μ of the Kth category k for: N k For category c k The number of pixels within; the number of cluster centers μ k The L, a, and b values are used as representative values for the corresponding color category regions. After obtaining the cluster center labels and cluster centers, the cluster labels are filled into an array of the same size as the original image, thus realizing the K-means clustering operation.
[0048] Further, in step S4, the specific process of the noise reduction processing is as follows:
[0049] A minimum region area is set, and then the cluster labels are optimized using a region merging denoising function: For each non-background cluster label, the mask corresponding to the label is obtained, and connected component analysis is performed on the mask; for connected components with an area smaller than the minimum region area, a dilation operation is performed on them, and the formula for the dilation operation is: D(X)=X⊕B; where D(X) represents the dilated image region, X is the original connected component region, ⊕ represents the dilation operation, and B is the structuring element; the part that exceeds the original region after dilation is obtained, and the surrounding labels corresponding to the exceeding part are counted. The label with the most occurrences is taken as the new label of the connected component with an area smaller than the minimum region area, thereby achieving denoising of the cluster label array.
[0050] Furthermore, in step S5, the specific process of color difference calculation is as follows:
[0051] For each pair of cluster centers, the Euclidean distance between the L, a, and b components is calculated using the LAB color difference calculation formula to quantify the color difference between the two regions. The color values of the cluster centers of the two regions are set as (L1, a1, b1) and (L2, a2, b2), respectively, and the formula for calculating their color difference ΔE is as follows:
[0052]
[0053] Then, a color difference threshold γ is set. Cluster center pairs with ΔE≥γ are considered significant color difference pairs, indicating that there is a significant color difference between the regions containing these two color levels; cluster center pairs with ΔE<γ are considered non-significant color difference pairs, indicating that there is no significant color difference between the regions containing these two color levels.
[0054] Furthermore, in step S6, the specific operation of visualization processing is to define a basic color array containing multiple colors, select or adjust the color array according to the number of cluster centers, and ensure that each color level region has a corresponding visual color label after color grading.
[0055] Each pixel is filled with a mask of the corresponding color according to its cluster label to generate a visualization result of color grading; areas with significant color difference pairs are marked with special colors to generate a visualization result of areas with significant color difference.
[0056] The LAB image is normalized and then converted into a more intuitive RGB image for visualization.
[0057] This invention also provides a product surface paint layer color difference detection system for performing the aforementioned industrial production image color difference detection method, comprising a color space conversion module, a foreground segmentation module, a color grading module, an image denoising module, and a visualization output module connected in sequence;
[0058] The color space conversion module is used to convert the image to be detected from the RGB color space to the LAB color space to obtain an image to be detected that can more accurately describe the differences between colors.
[0059] The foreground segmentation module is used to extract the main body region in the image, generate a foreground mask and filter background interference, so that subsequent detection focuses only on the main body region.
[0060] The color grading module is used to perform cluster analysis on LAB pixels in the foreground area, divide color categories and optimize regional continuity, and grade the color of the main area.
[0061] The image denoising module is located after the color grading module. It is used to remove the color levels represented by meaningless, excessively small areas and assimilate them to the nearby color levels, so that the regions after color grading are more coherent and more in line with the actual situation of color difference detection result judgment.
[0062] The visualization output module is used to generate detection results containing the following: visualization comparison between the original image and LAB space, grayscale display of the foreground segmentation mask, mask coverage of color clustering regions, and highlighting of regions with significant color differences; the visualization output module also outputs a detection report, which includes the location distribution, area ratio, and color difference value information of the color grading regions.
[0063] Furthermore, the foreground segmentation module includes a grayscale processing unit, a binarization unit, a morphological optimization unit, and a connected component analysis unit;
[0064] The grayscale processing unit is used to convert the LAB three-dimensional color image into a single-channel grayscale image to obtain an image without color interference and retaining only the core contrast features of the foreground and background.
[0065] The binarization unit is used to convert the grayscale image into a binary mask to obtain the foreground and background regions that are initially separated.
[0066] The morphological optimization unit is used to bridge the gaps in the foreground region to obtain a binary image with continuous closed boundaries.
[0067] The connected component analysis unit is used to scan and mark all connected regions, filter the main region with the largest area, and obtain the final foreground target mask.
[0068] Compared with the prior art, the present invention has the following beneficial effects:
[0069] This invention achieves accurate characterization of color differences by converting the original image to a LAB color space image. It integrates foreground segmentation techniques using multiple algorithms such as Gaussian blur and Otsu's method to effectively separate the detection area and reduce background interference. Employing K-means clustering combined with region merging denoising, it can achieve pixel-level color grading and color difference detection even without a standard color chart of the product's paint layer. A well-designed visualization process allows operators to clearly and intuitively observe the color differences in the product's paint layer. This invention's detection method is accurate and efficient, significantly improving detection efficiency and quality assessment accuracy, and has good industrial application value. Attached Figure Description
[0070] Figure 1 This is a flowchart of a product surface paint layer color difference detection method according to the present invention;
[0071] Figure 2 This is a schematic diagram of the composition of a product surface paint layer color difference detection system according to the present invention;
[0072] Figure 3 These are visualization results obtained at different stages in a certain embodiment of the present invention. Detailed Implementation
[0073] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention are described in detail below. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the scope of protection of this invention. Based on the technical solutions proposed in this invention, any modifications, equivalent substitutions, and improvements made by those skilled in the art without creative effort should be included within the scope of protection of this invention.
[0074] Example 1
[0075] like Figure 1 As shown, the product surface paint layer color difference detection method provided by the present invention achieves automated detection of product surface paint layer color difference through innovative color space conversion, accurate foreground segmentation, intelligent cluster analysis and optimized color difference calculation and other key technologies.
[0076] The specific solution includes the following steps:
[0077] Step S1, Color Space Conversion: The selected area of the surface of the product to be inspected is acquired by the photographic equipment and used as the original image. The original image is converted from the RGB color space to the LAB color space to obtain the LAB image and the height and width of the image are recorded.
[0078] It should be noted that the BGR color space is the default image reading format for image processing libraries such as OpenCV, but its color channel order is different from that of the regular RGB format; the RGB color space is one of the most commonly used color representation methods, but it has perceptual non-uniformity in color difference detection.
[0079] The process of converting the image of the product to be inspected into the RGB color space and then into the LAB color space uses the following formula:
[0080]
[0081] First, the original red, green, and blue components r, g, and b of each pixel in the original image are normalized to R, G, and B in the range [0,1]. Then, through linear transformation, the normalized R, G, and B are converted into the three components X, Y, and Z of the XYZ color space. Finally, the L, a, and b values of each pixel are calculated to complete the conversion from the RGB image to the LAB color space.
[0082] It should be noted that the color difference calculation in the LAB color space is highly consistent with human visual perception, making it particularly suitable for precise color difference analysis in industrial inspection. Therefore, this invention first converts the image from BGR format to RGB format, and then further converts it to the LAB color space to obtain more accurate color difference detection results.
[0083] Step S2, Foreground Segmentation: Convert the LAB image to a grayscale image, process the grayscale image using Gaussian blur, then perform threshold segmentation using Otsu's method to obtain a binarized image, then process the binarized image using morphological closing operation, and finally obtain the foreground mask through connected component analysis, selecting the connected component with the largest area as the foreground mask to be detected, thereby realizing the extraction of the object to be detected;
[0084] In step S2, the specific process of grayscale conversion for the foreground segmentation algorithm based on OTSU's threshold segmentation method is as follows:
[0085] The red, green, and blue components (R, G, B) of a LAB color image are converted to grayscale values using grayscale conversion. The grayscale conversion formula is as follows:
[0086] Gray(p)=0.299R(p)+0.587G(p)+0.114B(p);
[0087] The grayscale image is then smoothed using a Gaussian kernel function G(x,y). The formula for the Gaussian kernel function is:
[0088]
[0089] Where σ is the Gaussian blur radius, controlling the degree of blurring, and (x,y) are the coordinates of the pixel; then, the grayscale image Gray is convolved with the Gaussian kernel G to obtain the blurred grayscale image Gray. blur The formula is:
[0090]
[0091] Calculate the grayscale histogram of the blurred grayscale image and perform normalization. The normalization formula is:
[0092]
[0093] Where i is the grayscale value, N is the total number of pixels in the image, and p i Let n be the probability distribution of a pixel with gray value i appearing in the entire image. i This represents the number of pixels with a grayscale value of i.
[0094] Then, iterating through all possible thresholds T∈[0,255], the image pixels are divided into foreground (gray level 0~T) and background (gray level T+1~255). The formula for calculating the mean gray level of the foreground and background classes is as follows:
[0095]
[0096] Where μ0 is the average gray level of the foreground; μ1 is the average gray level of the background; w0 is the probability of the foreground pixel; and w1 is the probability of the background pixel.
[0097] Calculate the between-class variance:
[0098]
[0099] Where, μ total The total grayscale value is then selected to minimize the inter-class variance. Maximum threshold T * As the optimal segmentation threshold:
[0100] Finally, image binarization is performed, dividing the image into foreground 0 and background 1, thus obtaining the binarized image.
[0101] The binarized image is morphologically closed, using an elliptical structuring element B (major semi-axis r). a short half-axis r b For binary images, dilation followed by erosion fills foreground holes and smooths boundaries. The closing operation formula is:
[0102]
[0103] The expansion ⊕ is defined as: (Bin⊕B)(p)=max (x,y)∈B Bin(p+x,p+y); Corrosion Defined as: Compared to rectangles, elliptical structural elements are better able to maintain the natural shape of the product's surface coating;
[0104] For the binary image after the closing operation, all connected regions are labeled, the pixel area of each connected region is calculated, and the connected region with the largest area is selected as the foreground mask to be detected for the paint layer on the product surface. The calculation formula is as follows:
[0105]
[0106] Where A k Foreground mask to be detected, Region k This represents the k-th connected region, thus completing the foreground segmentation process of the image.
[0107] Step S3, Color Grading: Obtain the coordinates of all foreground pixels in the foreground mask to be detected, extract the LAB values of all foreground pixels corresponding to the coordinates in the LAB image, then set the number of cluster centers, use the K-means algorithm to cluster the LAB values of all foreground pixels in the foreground mask to be detected, obtain cluster labels and cluster centers, and realize color grading of all foreground pixels in the foreground mask to be detected.
[0108] In step S3, based on the color differences in the image of the product to be detected, K-means clustering is used to cluster the foreground pixels to obtain cluster labels and cluster centers. The specific steps are as follows:
[0109] Set the number of cluster categories to K, and the LAB value x of the pixels within the foreground mask to be detected. i =(L i ,a i ,b i K-means clustering is performed, with the objective function formula as follows:
[0110]
[0111] Wherein, the center vector μ of the Kth category k for: N k For category c k The K-means clustering algorithm calculates the number of pixels within a given area; it uses the L, a, and b values corresponding to each cluster center as the feature representative values of the corresponding color category; after completing the cluster center calculation and pixel classification, it maps the category label of each pixel to a two-dimensional array with the same size as the original image. This process is the complete implementation flow of the K-means clustering algorithm.
[0112] Step S4, Denoising: Set a minimum region area, use a region merging denoising function to optimize the cluster labels, eliminate noise points with excessively small areas, and automatically integrate regions smaller than the minimum region area into surrounding color-level regions, thus achieving denoising of the cluster label array. The specific process is as follows:
[0113] Based on actual testing requirements and factors such as the image resolution of the product surface paint layer, a minimum region area is set. Then, a region merging and denoising function is used to optimize the cluster labels: connected component analysis is performed on each non-background cluster label to obtain its corresponding region mask. For regions with an area smaller than a set threshold, a morphological dilation operation is performed: the dilation operation formula is: D(X)=X⊕B; where D(X) represents the dilated image region, X is the original connected component region, ⊕ represents the dilation operation, and B is the structuring element. The main neighbor labels of the newly added regions after dilation are counted, and these labels are assigned to the original small regions. The neighborhood label statistics adopt the mode principle to ensure the rationality of region fusion.
[0114] Step S5, Color Difference Calculation: Calculate the color difference between cluster centers, set a color difference threshold, and identify cluster center pairs with a distance greater than the threshold as significant color difference pairs. The specific process is as follows:
[0115] For each pairwise combination of cluster centers, the color difference value is calculated based on the LAB color space. The Euclidean distance between the L, a, and b components is calculated to quantify the color difference between the two regions. The color values of the cluster centers of the two regions are denoted as (L1, a1, b1) and (L2, a2, b2), respectively, and the formula for calculating their color difference ΔE is:
[0116]
[0117] Then, based on the quality standards and industry specifications of the product's surface paint layer, a judgment threshold γ is set. When ΔE ≥ γ, the cluster center pair is judged to have a significant color difference and marked as an abnormal area; when ΔE < γ, it is judged to be within the normal color difference range. The abnormal area is then marked, which is the final test result.
[0118] Step S6, Visualization Processing: Cover each color region with a mask of the same color, and the mask colors of different color regions are different, thereby generating a visualization result of color grading; then retain the mask of the color region corresponding to the cluster center with significant color difference pairs, and remove the mask of the color region corresponding to the cluster center without significant color difference pairs, thereby generating a visualization result of regions with significant color difference.
[0119] The specific process of visualization is as follows:
[0120] Define a basic color array, which can contain multiple colors such as red, green, blue, and yellow. Select or adjust the color array based on the number of cluster centers to ensure that each color level region has a corresponding visual color label after color grading. Fill each pixel with a mask of the corresponding color according to its cluster label to generate the visualization result of color grading; use special color annotations for regions with significant color difference pairs to generate visualization results for regions with significant color difference. Normalize the LAB image and convert the normalized LAB image into a more intuitive RGB image for visualization.
[0121] This invention proposes a method for detecting color difference in product surface paint layers based on color clustering grading. The method first converts the original image to the LAB color space for more accurate color differentiation. Then, it integrates Gaussian blur and the OTSU algorithm to segment the foreground of the detection region, effectively reducing background interference. Next, it innovatively employs K-means clustering combined with region merging for noise reduction, achieving pixel-level color grading and color difference detection without a standard color chart. Finally, it uses visualization processing to present the detection results intuitively. This method offers high detection accuracy and significantly improved efficiency, demonstrating significant industrial application value.
[0122] Figure 3These are the corresponding visualization results obtained at different stages in a certain embodiment of the present invention. From left to right and from top to bottom, they are: the original image, the LAB image obtained by color space conversion in step S1, the result image obtained by foreground segmentation in step S2, the visualization result image of color grading in step S6, and the visualization result image of color difference detection in step S6 where there are significant color difference regions. In this embodiment, three cluster centers are set, represented by green, blue, and red respectively. The two cluster centers corresponding to green and red have significant color difference pairs, while the two cluster centers corresponding to blue and green, as well as the two cluster centers corresponding to blue and red, do not have significant color difference. In order to highlight and visualize the significant color difference pairs, the color level corresponding to the blue cluster center, which does not have significant color difference with other cluster centers, is expressed using the original image color, thus obtaining the fifth corresponding color difference detection result image.
[0123] Example 2
[0124] like Figure 2 As shown, the present invention also provides an image color difference detection system for industrial production, used to perform a product surface paint layer color difference detection method as described in Embodiment 1. The system includes a color space conversion module, a foreground segmentation module, a color grading module, an image denoising module, and a visualization output module connected in sequence.
[0125] The color space conversion module is used to convert the image to be detected from the RGB color space to the LAB color space, so as to obtain an image to be detected that can more accurately describe the differences between colors;
[0126] The foreground segmentation module extracts the main subject region from the image, generates a foreground mask, and filters background interference, ensuring that subsequent detection focuses only on the main subject region. The foreground segmentation module includes a grayscale processing unit, a binarization unit, a morphological optimization unit, and a connected component analysis unit. The grayscale processing unit converts the LAB 3D color image into a single-channel grayscale image, obtaining an image free of color interference and retaining only the core contrast features of the foreground and background. The binarization unit converts the grayscale image into a binary mask, obtaining initially separated foreground and background regions. The morphological optimization unit bridges gaps within the foreground region, obtaining a binary image with continuous closed boundaries. The connected component analysis unit scans and marks all connected regions, selecting the largest main subject region to obtain the final foreground target mask.
[0127] The color grading module is used to perform cluster analysis on LAB pixels in the foreground area, classify color categories and optimize regional continuity, and grade the colors of the main body area.
[0128] The image denoising module is set after the color grading module. It is used to remove the color levels represented by meaningless, excessively small areas and assimilate them to the nearby color levels, so that the regions after color grading are more coherent and more in line with the actual situation of color difference detection results.
[0129] The visualization output module generates detection results containing the following: a visual comparison between the original image and the LAB space, grayscale display of the foreground segmentation mask, mask coverage of color clustering regions, and highlighted marks of regions with significant color differences. The visualization output module also outputs a detection report, including the location distribution, area percentage, and color difference values of the color grading regions.
[0130] Example 3
[0131] To verify the technical effectiveness of the proposed color difference detection method for product surface paint layers, 115 images of the instrument surface paint layers with resolutions ranging from 1280×1280 to 2560×2560 were selected as the experimental dataset. All images were collected in actual industrial scenarios, including typical scenarios such as paint layer uniformity differences, color differences caused by local damage, and color differences under illumination interference. Detailed data information is shown in Table 1. This method does not require a model training process and directly performs the color difference detection process on the input images.
[0132] Table 1. Color Difference Defect Data Set
[0133]
[0134] The experimental environment consisted of a Windows 10 operating system, an Intel Core i9-14900 CPU, an NVIDIA RTX 4090 GPU, and 64GB of RAM; the software environment was Python 3.12.
[0135] The experiment compared three existing color difference detection methods. The first method extracts the color range in the HSV space and performs detection using adaptive threshold segmentation in the LAB space, requiring manual setting of threshold parameters. The second method acquires images using a line scan camera and calculates the color difference value using a LAB color appearance model, primarily used for continuous production line strip product inspection. The third method selects fixed sampling points in the LAB space and determines the color difference by comparing them with standard color difference values, suitable for uniform surface inspection. The experiment used the mean Intersection over Union (mIOU) and average detection time as evaluation metrics. The IOU is used to assess the degree of overlap between the detected color difference area and the true area, calculated using the following formula:
[0136]
[0137] Among them, A predA represents the area of the color difference region predicted by the model. ture This represents the area of the true color difference region. After image acquisition, areas in each data set that are manually identified as having color differences are labeled, and the area of these labeled color difference regions is calculated as the true color difference region area A. ture The average intersection-union ratio (IOU) refers to the average value of the IOUs obtained from detecting all the data.
[0138] The detection time is the total time from image input to output detection result, measured in milliseconds (ms). The average detection time refers to the average time taken to detect each data image, reflecting the real-time performance of the method. The three existing methods mentioned above are compared with the method of this invention; the experimental data are shown in Table 2.
[0139] Table 2. Comparative Experiment Results
[0140]
[0141] Analysis shows that the mIOU of this invention reaches 0.88, which is 12 percentage points higher than the HSV+LAB adaptive threshold method, whose detection accuracy is limited due to its reliance on manually set thresholds; it is 6 percentage points higher than the machine vision+LAB color appearance model method, mainly due to the optimization of the boundary continuity of the color difference region by the region merging and denoising step; and it is 24 percentage points higher than the LAB sampling point comparison method, which, compared to the discrete sampling method, can more completely cover the color difference region, avoid missed detections, and thus more accurately identify subtle color differences. The average detection time of this invention is 782.10ms, which is slightly higher than the sampling point comparison method, but much lower than the machine vision+LAB color appearance model method and the HSV+LAB adaptive threshold method, achieving a balance between detection accuracy and efficiency. Table 2 shows that the method proposed in this invention is superior to the comparative methods in detecting color differences in the paint layer on the product surface, with more complete identification of subtle color differences and more accurate boundary positioning of color difference regions.
[0142] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A method for detecting color difference in a product surface paint layer, characterized in that, Includes the following steps: Step S1, Color Space Conversion: The selected area of the surface of the product to be inspected is acquired by the photographic equipment and used as the original image. The original image is converted from the RGB color space to the LAB color space to obtain the LAB image. Step S2, Foreground Segmentation: Convert the LAB image to a grayscale image, process the grayscale image using Gaussian blur, then perform threshold segmentation using Otsu's method to obtain a binarized image, then process the binarized image using morphological closing operation, and finally obtain the foreground mask through connected component analysis, selecting the connected component with the largest area as the foreground mask to be detected, thereby realizing the extraction of the object to be detected; Step S3, Color Grading: Obtain the coordinates of all foreground pixels in the foreground mask to be detected, extract the LAB values of all foreground pixels corresponding to the coordinates in the LAB image, then set the number of cluster centers, use the K-means algorithm to cluster the LAB values of all foreground pixels in the foreground mask to be detected, obtain cluster labels and cluster centers, and realize color grading of all foreground pixels in the foreground mask to be detected. Step S4, Denoising: Set a minimum area and use a region merging denoising function to optimize the cluster labels, eliminate noise with too small an area, and automatically integrate areas smaller than the minimum area into the surrounding color level areas to achieve denoising of the cluster label array. Step S5, color difference calculation: Calculate the color difference between cluster centers, set a color difference threshold, and take cluster center pairs whose distance is greater than the color difference threshold as significant color difference pairs; Step S6, Visualization Processing: Cover each color region with a mask of the same color, and the mask colors of different color regions are different, thereby generating a visualization result of color grading; then retain the mask of the color region corresponding to the cluster center with significant color difference pairs, and remove the mask of the color region corresponding to the cluster center without significant color difference pairs, thereby generating a visualization result of regions with significant color difference.
2. The method for detecting color difference in a product surface paint layer according to claim 1, characterized in that, The original image described in step S1 is converted from the RGB color space to the LAB color space to obtain the first pure color image to be detected; First, normalize the original red, green, and blue components r, g, and b of each pixel in the original image to R, G, and B in the range [0,1] using the following formula: Then, through a linear transformation, the normalized R, G, and B are converted into the three components X, Y, and Z of the XYZ color space, as shown in the following formula: Then, the L, a, and b values of the image are calculated using the following formula: Among them, X ref_white Y ref_white With Z ref_white The tristimulus values of white in the XYZ color space are a set of predefined reference values used to normalize X, Y, and Z. Through the above steps, the conversion from RGB image to LAB color space is completed, and the L, a, and b values of each pixel are obtained for subsequent color difference calculation.
3. The method for detecting color difference in a product surface paint layer according to claim 1, characterized in that, The specific process of foreground segmentation in step S2 is as follows: The red, green, and blue components (R, G, B) of the LAB image corresponding to the color image are converted to grayscale values using grayscale conversion. The grayscale conversion formula is as follows: Gray(p)=0.299R(p)+0.587G(p)+0.114B(p); Next, Gaussian blurring is applied to the grayscale image. A Gaussian kernel function G(x,y) is defined to smooth the grayscale image. The Gaussian kernel formula is: Where σ is the Gaussian blur radius, controlling the degree of blurring, and (x,y) are the coordinates of the pixel; the grayscale image Gray is convolved with the Gaussian kernel G to obtain the blurred grayscale image Gray. blur The calculation formula is as follows: Then, threshold segmentation is performed using the Otsu method, and the gray-level histogram of the blurred gray-level image is statistically analyzed to obtain the binarized image. A morphological closing operation is performed on the binarized image using an elliptical structuring element B. The binary image is first dilated and then eroded to fill foreground holes and smooth the boundaries. The closing operation formula is as follows: Among them, expansion Defined as: corrosion Defined as: B)(p)=min (x,y)∈B Bin(p+x,p+y); For the binarized image after the closing operation, all connected regions are labeled, the pixel area of each connected region is calculated, and the connected region with the largest area is selected as the foreground mask to be detected for the paint layer on the product surface. The calculation formula is as follows: Where A k Foreground mask to be detected, Region k This represents the k-th connected region, thus completing the foreground segmentation process of the image.
4. The method for detecting color difference in product surface paint layer images according to claim 3, characterized in that, The specific operation of Otsu's method for threshold segmentation to obtain a binarized image is as follows: Calculate the grayscale histogram of the blurred grayscale image and perform normalization. The normalization formula is: Where i is the grayscale value, N is the total number of pixels in the image, and p i Let n be the probability distribution of a pixel with gray value i appearing in the entire image. i This represents the number of pixels with a grayscale value of i. Then, iterating through all possible thresholds T∈[0,255], the image pixels are divided into foreground and background classes. The formula for calculating the gray-scale mean of the foreground and background classes is as follows: Where μ0 is the average gray level of the foreground; μ1 is the average gray level of the background; w0 is the probability of the foreground pixel; and w1 is the probability of the background pixel. Calculate the between-class variance: Where, μ total The total grayscale value is then selected to minimize the inter-class variance. Maximum threshold T * As the optimal segmentation threshold: Finally, image binarization is performed, dividing the image into foreground 0 and background 1, thus obtaining the binarized image.
5. The method for detecting color difference in the paint layer on a product surface according to claim 1, characterized in that, In step S3, based on the color differences in the image to be detected, the K-means clustering algorithm is used to cluster the LAB values of the foreground pixels to obtain cluster labels and cluster centers. The specific steps are as follows: Set the number of cluster centers to K, and the LAB value x of the pixels within the foreground mask to be detected. i =(L i ,a i ,b i Perform K-means clustering to divide the pixels into K categories {c1, c2, ..., c3}. K The objective function formula for clustering is: Wherein, the center vector μ of the Kth category k for: N k For category c k The number of pixels within; the number of cluster centers μ k The L, a, and b values are used as representative values for the corresponding color category regions. After obtaining the cluster center labels and cluster centers, the cluster labels are filled into an array of the same size as the original image, thus realizing the K-means clustering operation.
6. The method for detecting color difference in a product surface paint layer according to claim 1, characterized in that, In step S4, the specific process of the noise reduction is as follows: Set a minimum region area, and then use a region merging and denoising function to optimize the cluster labels: For each non-background cluster label, obtain the mask corresponding to that label, and perform connected component analysis on the mask; for connected components with an area smaller than the minimum region area, perform a dilation operation on them, the formula for which is: Where D(X) represents the dilated image region, and X is the original connected region. This represents the expansion operation, where B is the structuring element. The expansion operation retrieves the portion that extends beyond the original region, and the surrounding labels corresponding to the expanded portion are counted. The label that appears most frequently is taken as the new label for the connected component whose area is smaller than the area of the smallest region, thus achieving noise reduction of the clustered label array.
7. The method for detecting color difference in a product surface paint layer according to claim 1, characterized in that, In step S5, the specific process of color difference calculation is as follows: For each pair of cluster centers, the Euclidean distance between the L, a, and b components is calculated using the LAB color difference calculation formula to quantify the color difference between the two regions. The color values of the cluster centers of the two regions are set as (L1, a1, b1) and (L2, a2, b2), respectively, and the formula for calculating their color difference ΔE is as follows: Then, a color difference threshold γ is set. Cluster center pairs with ΔE≥γ are considered significant color difference pairs, indicating that there is a significant color difference between the regions containing these two color levels; cluster center pairs with ΔE<γ are considered non-significant color difference pairs, indicating that there is no significant color difference between the regions containing these two color levels.
8. The method for detecting color difference in a product surface paint layer according to claim 1, characterized in that, In step S6, the specific operation of visualization processing is to define a basic color array containing multiple colors, select or adjust the color array according to the number of cluster centers, and ensure that each color level region has a corresponding visual color label after color grading. Each pixel is filled with a mask of the corresponding color according to its cluster label to generate a visualization result of color grading; areas with significant color difference pairs are marked with special colors to generate a visualization result of areas with significant color difference. The LAB image is normalized and then converted into a more intuitive RGB image for visualization.
9. A product surface paint layer color difference detection system, used to execute the image color difference detection method for industrial production as described in any one of claims 1-8, characterized in that, It includes a color space conversion module, a foreground segmentation module, a color grading module, an image denoising module, and a visualization output module connected in sequence; The color space conversion module is used to convert the image to be detected from the RGB color space to the LAB color space to obtain an image to be detected that can more accurately describe the differences between colors. The foreground segmentation module is used to extract the main body region in the image, generate a foreground mask and filter background interference, so that subsequent detection focuses only on the main body region. The color grading module is used to perform cluster analysis on LAB pixels in the foreground area, divide color categories and optimize regional continuity, and grade the color of the main area. The image denoising module is located after the color grading module. It is used to remove the color levels represented by meaningless, excessively small areas and assimilate them to the nearby color levels, so that the regions after color grading are more coherent and more in line with the actual situation of color difference detection result judgment. The visualization output module is used to generate detection results containing the following: visualization comparison between the original image and LAB space, grayscale display of the foreground segmentation mask, mask coverage of color clustering regions, and highlighting of regions with significant color differences; the visualization output module also outputs a detection report, which includes the location distribution, area ratio, and color difference value information of the color grading regions.
10. A product surface paint layer color difference detection system according to claim 9, characterized in that, The foreground segmentation module includes a grayscale processing unit, a binarization unit, a morphological optimization unit, and a connected component analysis unit; The grayscale processing unit is used to convert the LAB three-dimensional color image into a single-channel grayscale image to obtain an image without color interference and retaining only the core contrast features of the foreground and background. The binarization unit is used to convert the grayscale image into a binary mask to obtain the foreground and background regions that are initially separated. The morphological optimization unit is used to bridge the gaps in the foreground region to obtain a binary image with continuous closed boundaries. The connected component analysis unit is used to scan and mark all connected regions, filter the main region with the largest area, and obtain the final foreground target mask.
Citation Information
Patent Citations
A method and system for detecting color difference of thin-film solar cells
CN119779998A
Cited By
Asphalt pavement patching area detection and color matching analysis method and system
CN121640282A
Methods and Systems for Detection and Color Matching Analysis of Asphalt Pavement Repair Areas
CN121640282B
Seed lesion grain identification method based on image identification and intelligent screening system
CN121921579A
Seed disease granule recognition method based on image recognition and intelligent screening system
CN121921579B
A method and system for separating foreground and background layers of a paint microscopic image
CN122473219A