A method and system for extracting the main color of a laser-marked sample color block

CN117351099BActive Publication Date: 2026-08-11HUAZHONG UNIV OF SCI & TECH
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-10-20
Publication Date
2026-08-11

AI Technical Summary

Technical Problem

但是,该算法在大面积高分辨率图像的颜色提取方面,仍存在时间复杂度较高的问题;造成这一问题的主要原因是该算法需要对整幅图像进行逐像素的扫描和颜色空间的划分,对大尺寸的图像处理速度会受较大影响

Benefits of technology

[0033]1.本发明在保留八叉树算法拟色效果好的基础上,对其进行改进,通过非均匀量化方法对八叉树结构中的叶子节点进行划分,基于信息熵确定分割阈值,能够提高划分后结果的信息增益,进而保证划分子节点的纯度,节点划分更高效,从而提高算法的效率。本发明适用于色彩相近但不均匀区域的主色提取,计算复杂度低,且具有较高精度。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117351099B_ABST
    Figure CN117351099B_ABST
Patent Text Reader

Abstract

This invention belongs to the field of laser marking color extraction, and specifically discloses a method and system for extracting the main color of a laser-marked sample color block. The method includes: S1 capturing an image of the laser-marked sample to be processed; S2 initializing an octree by inserting the RGB values ​​of the pixels in the image into each node of the octree; S3 dividing each node of the octree, pruning the octree when the number of leaf nodes exceeds a threshold; when dividing each node: constructing histograms based on the RGB values ​​of the pixels in the node, and selecting the RGB value with the largest percentage of pixels as the candidate threshold, and selecting the threshold with the largest information gain; dividing the node into two parts according to the segmentation threshold; S4 repeating S3 until the required number of iterations is reached; S5 averaging the RGB values ​​of the pixels in all leaf nodes of the octree to obtain the main color of the sample color block. This invention can improve the accuracy and efficiency of extracting the main color of a laser-marked sample color block.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of laser marking color extraction, and more specifically, relates to a method and system for extracting the main color of a laser-marked sample color block. Background Technology

[0002] Currently, in research on the color reproducibility of laser marking, using deep learning tools such as neural networks to find the mapping relationship between process parameters and marking colors is a common method. Supervised learning and other methods all require experiments to obtain datasets, which involves acquiring the color values ​​of laser-marked sample patches on metal surfaces.

[0003] Traditional color extraction methods involve randomly selecting several points on a color patch using a spectrophotometer and averaging the results to obtain the RGB value of the color patch. While simple and easy to implement, this method is highly subjective and random, easily affected by uneven color distribution, and prone to losing key color information. This interferes with subsequent research on the reproducibility of laser marking colors and is detrimental to the industrial application of laser-induced coloring technology on metal surfaces. Image-based theme color extraction using digital image technology can extract the dominant color from the surface of a color patch, eliminating random errors caused by manual point selection, and is suitable for large-scale color extraction processing of laser-induced colored samples. However, research on color extraction of laser-inducing surface coloring samples on metal surfaces based on digital image technology is relatively lacking.

[0004] The main methods for extracting thematic colors from images include median segmentation, octree algorithm, and KMeans clustering algorithm. Among these three algorithms, the octree algorithm has the greatest advantage in terms of high computational efficiency, low memory consumption, and the best color palette output when processing small image resolutions. Specifically, it uses an octree data structure to store color values ​​and achieves color quantization by building the octree and outputting a color palette. Building the octree involves three steps: search, insertion, and color merging. However, this algorithm still suffers from high time complexity when extracting colors from large-area, high-resolution images. The main reason for this is that the algorithm needs to scan the entire image pixel by pixel and divide the color space, which significantly impacts the processing speed of large images. Summary of the Invention

[0005] In view of the above-mentioned defects or improvement needs of the existing technology, the present invention provides a method and system for extracting the main color of laser-marked sample color blocks, the purpose of which is to improve the accuracy and calculation efficiency of extracting the main color of laser-marked sample color blocks.

[0006] To achieve the above objectives, according to a first aspect of the present invention, a method for extracting the main color of a laser-marked sample color patch is proposed, comprising the following steps:

[0007] S1. Photograph the laser-marked sample to obtain the image to be processed corresponding to the color block;

[0008] S2. Initialize the octree and insert the RGB values ​​of all pixels in the image to be processed into each node of the octree;

[0009] S3. Divide the nodes on the octree. When the number of leaf nodes exceeds the threshold, prune the octree.

[0010] The partitioning of each node includes the following steps:

[0011] The candidate threshold is determined based on the distribution of RGB values ​​of pixels in the node;

[0012] Calculate the information gain of node partitioning using each candidate threshold, and select the candidate threshold with the largest information gain as the segmentation threshold.

[0013] The node is divided into two parts according to the segmentation threshold, thus completing one division of the node;

[0014] S4. Repeat step S3 until the preset number of iterations is reached to obtain the final octree;

[0015] S5. Average the RGB values ​​of the pixels in all leaf nodes of the octree to obtain the main color of the laser marking sample color block.

[0016] As a further preferred embodiment, in step S3, the candidate threshold is determined based on the RGB value distribution of the pixels in the node, specifically as follows:

[0017] Based on the R, G, and B values ​​of the pixels in the node, construct R, G, and B histograms respectively. In the three histograms, select the R, G, and B values ​​with the largest proportion of pixels as the candidate thresholds.

[0018] As a further preferred embodiment, step S3 involves pruning the octree, including the following steps:

[0019] Select a bottom-level non-leaf node, merge its child nodes, use the average of the pixel RGB values ​​of all child nodes as the RGB value of the pixel in the non-leaf node, and then clear the child nodes.

[0020] As a further preferred option, the quantity threshold is set to 256.

[0021] As a further preferred embodiment, step S2 specifically includes the following steps:

[0022] Initialize the octree and divide the RGB color space into eight regions, with each region corresponding to a node in the octree.

[0023] Traverse all pixels in the image to be processed and insert the RGB value of each pixel into the corresponding octree node.

[0024] As a further preferred embodiment, step S1 specifically includes the following steps:

[0025] The laser-marked sample was photographed to obtain a digital image, which was then preprocessed.

[0026] Based on the arrangement of color blocks on the laser-marked sample, the preprocessed digital image is divided into multiple regions accordingly;

[0027] Extract the region contour information to obtain the image to be processed corresponding to the color block.

[0028] As a further preferred option, preprocessing the digital image includes: denoising, grayscale conversion, and binarization.

[0029] As a further preferred method, the region contour information is extracted using the OpenCV contour extraction function to obtain the ROI region, thereby obtaining the image to be processed corresponding to the color block.

[0030] According to a second aspect of the present invention, a main color extraction system for laser-marked sample color blocks is provided, comprising a processor, the processor being used to execute the above-described laser-marked sample color block main color extraction method.

[0031] According to a third aspect of the present invention, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the above-described method for extracting the main color of a laser-marked sample color block.

[0032] In summary, compared with the prior art, the above-described technical solutions conceived by this invention mainly possess the following technical advantages:

[0033] 1. This invention, while retaining the good color matching effect of the octree algorithm, improves upon it by using a non-uniform quantization method to divide the leaf nodes in the octree structure. Based on information entropy, the segmentation threshold is determined, which improves the information gain of the segmented results, thereby ensuring the purity of the divided child nodes and making node segmentation more efficient, thus improving the algorithm's efficiency. This invention is suitable for extracting the primary color from regions with similar but uneven colors, with low computational complexity and high accuracy.

[0034] 2. This invention determines the threshold of leaf nodes by using a non-uniform quantization method based on image histograms, which can yield a better threshold. Furthermore, the depth of the octree can be reduced by continuously adjusting the threshold, thereby improving the efficiency of the algorithm.

[0035] 3. This invention applies image processing technology to the field of laser-induced coloring of metal surfaces, reducing the color sampling error caused by uneven color of laser-induced colored samples, optimizing the dataset quality of laser-induced coloring of metal surfaces, and significantly improving the time complexity compared to the traditional uniform quantization octree color quantization algorithm. Attached Figure Description

[0036] Figure 1 This is a flowchart of the method for extracting the main color of a laser-marked sample color block according to an embodiment of the present invention;

[0037] Figure 2 Images (a) to (c) are the RGB three-channel histograms of all pixels within a node according to an embodiment of the present invention;

[0038] Figure 3 This is a schematic diagram of a sample image from an embodiment of the present invention. Detailed Implementation

[0039] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention. Furthermore, the technical features involved in the various embodiments of this invention described below can be combined with each other as long as they do not conflict with each other.

[0040] This invention provides a method for extracting the main color of a laser-marked sample color patch, such as... Figure 1 As shown, it includes the following steps:

[0041] S1. Photograph the laser-marked sample to obtain the image to be processed corresponding to the color block.

[0042] Laser-marked samples are obtained through metal laser-induced coloring. Each sample contains multiple color patches, all of the same color, but the colors are not uniform due to limitations in the process. Therefore, the RGB data of the color patch images are characterized by low dimensionality and relatively concentrated and uniform distribution. To address this characteristic of the induced coloring RGB data, a method for extracting the main color of color patches from metal laser-induced surface coloring images based on an improved octree algorithm is proposed.

[0043] Furthermore, S1 includes the following steps:

[0044] S11. Use a high-resolution, high-color-reproduction industrial camera to photograph the laser-marked sample and obtain a digital image;

[0045] S12. Preprocess the digital image, including: denoising, grayscale conversion and binarization of the digital image;

[0046] S13. Based on the arrangement of the color blocks on the laser-marked sample, the preprocessed digital image is divided into different regions containing only the same color, that is, the same number of regions as the number of color blocks on the sample are obtained.

[0047] S14. Extract the region contour information using the OpenCV contour extraction function to obtain the pixel information within the ROI region, thereby obtaining the image to be processed corresponding to each color block.

[0048] It should be noted that the binarized image is only used to extract region contours, thereby determining the contours of the image to be processed corresponding to each color block. When extracting the dominant color using the improved octree algorithm, the image to be processed is restored to color. The following uses an image corresponding to a specific color block as an example to illustrate how to extract the dominant color using the improved octree algorithm.

[0049] S2. Initialize the octree and insert all pixels of the image to be processed into the nodes of the octree.

[0050] Furthermore, S2 includes the following steps:

[0051] Initialize an octree with eight nodes; divide the RGB color space into eight regions, each region corresponding to a node in the octree.

[0052] Traverse all pixels in the image to be processed and insert the RGB value of each pixel into the corresponding octree node;

[0053] Specifically, the RGB color space is a three-dimensional color space composed of the three dimensions of RGB. In some embodiments, during the initial division, each channel of the RGB three channels is divided into two cases, namely 0~127 and 128~256, thereby dividing the RGB color space into 2... 3 In each region, the colors of the pixels can be roughly clustered in the color space.

[0054] S3. Divide the nodes on the octree. When the number of leaf nodes exceeds the threshold, prune the octree.

[0055] Furthermore, S3 includes the following steps:

[0056] S31. Based on the R, G, and B values ​​of the pixels in the node, construct R, G, and B histograms respectively, and select the R, G, and B values ​​with the largest proportion of pixels as candidate thresholds. Taking the R value as an example, count the number of pixels with each R value in the node, construct a histogram, and the R value containing the most pixels is the candidate threshold; thus, based on the three histograms of R, G, and B, three candidate thresholds can be obtained.

[0057] S32. Calculate the information gain of node segmentation using the three candidate thresholds respectively, that is, evaluate the effect of segmenting nodes using each candidate threshold. The larger the information gain, the better the effect. Select the candidate threshold with the largest information gain as the segmentation threshold.

[0058] S33. Divide the pixels in the node into two parts according to the segmentation threshold to complete the first division of the node.

[0059] S34. Repeat steps S31 to S33 to continuously divide each node in the octree until the number of leaf nodes (i.e. nodes without child nodes) in the octree is greater than the number threshold (set to 256), then proceed to step S35.

[0060] S35. Select a bottom-level non-leaf node (generally, select the node one level above the leaf node that has recently exceeded the quantity threshold), merge the child nodes of the non-leaf node, use the average of the pixel RGB values ​​in all child nodes as the RGB value of the pixel in the non-leaf node, and clear the child nodes. The non-leaf node then becomes a leaf node.

[0061] To facilitate understanding, an example is given below: When traversing the RGB values ​​(112, 95, 168) of the inserted pixel, it is first assigned to one of the eight nodes in the first layer. Then, a three-channel histogram is calculated for all pixels within that node. The highest-frequency RGB value is selected as the candidate for the bisection threshold. The information gain of different partitioning results for the RGB three channels is calculated, and the node with the highest information gain is selected as the segmentation threshold, dividing it into two parts. The calculated three-channel histogram for the node is shown below. Figure 2 As shown, it's easy to see that the R channel is set to 128, the G channel to 111, and the B channel to 80. After calculating the information gain, we find that the G channel has the highest information gain when segmenting nodes. Therefore, we use this as the segmentation threshold to divide the nodes. Nodes with a G value less than 111 are assigned as the first child node, and nodes with a G value not less than 111 are assigned as the second child node, completing one division of the node. At this point, the pixel RGB value (112, 95, 168) is assigned to the first child node.

[0062] S4. Repeat step S3 until the preset number of iterations is reached to obtain the final octree.

[0063] S5. Average the RGB values ​​of the pixels in all leaf nodes of the octree to obtain the main color of the laser marking sample color block.

[0064] The traditional octree color quantization algorithm, proposed by M. Gervautz and W. Purgathofer (ASimple Method for Color Quantization: Octtree Quantization), boasts significant advantages: ingenious design, high efficiency, low memory consumption, optimal color palette selection, and superior display quality. As the name suggests, an octree is a tree-like structure with a root node having eight child nodes, where each node stores the three color channels information for color clustering.

[0065] In octree algorithms, if the number of leaf nodes exceeds the maximum allowed number of colors, a merging operation is required to reduce the number of leaf nodes. Whether or not to perform the merging operation depends on a threshold. Traditional octree algorithms use uniform quantization to determine the binary splitting threshold for each leaf node (the median of the colors in the node is used as the splitting threshold). This method does not require target directionality during node partitioning. Unlike this method, this invention uses an information entropy-based approach, which can improve the information gain of the partitioned result, thereby ensuring the "purity" of the partitioned child nodes and making node partitioning more efficient.

[0066] Digital images of color patches from metal laser-induced coloring experimental samples were used to verify the effectiveness of the improved octree quantization algorithm, such as... Figure 3 As shown, the sample contains 48 color patches. First, the color patch image was quantized using a traditional octree quantization algorithm. Then, the digital image of the color patches was quantized using an improved octree quantization algorithm. Finally, the color palettes obtained by the two methods were compared.

[0067] To characterize the difference between the actual and predicted colors, the color difference ΔE* calculated in the CIEL*a*b* color space is used for quantification. In the CIEL*a*b* color space, L* represents brightness from 0 (dark) to 100 (white), a* axis represents the ratio of red (positive) to green (negative), and b* axis represents the ratio of yellow (positive) to blue (negative). The total color difference ΔE* can be used to represent the Cartesian coordinate distance between colors in the L*a*b* color space. ΔE* < 7 indicates that the two colors can be considered approximately the same color, and the smaller the ΔE* value, the smaller the difference between the two colors. Three L*a*b* value tests were performed on each colored sample, and the average of the three results was taken.

[0068] Specifically, the total color difference is expressed using the CIE color difference formula:

[0069]

[0070] Where ΔL* represents the brightness difference, Δa* represents the red-green index difference, and Δb* represents the yellow-blue index difference.

[0071] In addition, during the calculation, the RGB color space needs to be converted to the L*a*b* color space first, and the color difference is calculated in the L*a*b* color space; the conversion method can be found in: Wang Ke, Lu Changde, Le Wande. Research and application of color similarity measurement [J]. Computer Applications Research, 2005, 10: 168-170.

[0072] The experimental results are as follows: For the digital image of the laser-induced color marking block in the case, the primary color ΔE* obtained based on the original octree algorithm is 6.48, while the primary color ΔE* obtained based on the improved octree algorithm is 4.31. The comparison shows that the color error is smaller and the obtained color palette (i.e., all color values ​​of the leaf nodes) is more reasonable.

[0073] Those skilled in the art will readily understand that the above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements 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 extracting the main color of a laser-marked sample color patch, characterized in that, Includes the following steps: S1. Photograph the laser-marked sample to obtain the image to be processed corresponding to the color block; S2. Initialize the octree and insert the RGB values ​​of all pixels in the image to be processed into each node of the octree; S3. Divide the nodes on the octree. When the number of leaf nodes exceeds the threshold, prune the octree. The partitioning of each node includes the following steps: The candidate threshold is determined based on the distribution of RGB values ​​of pixels in the node. Specifically, based on the R, G, and B values ​​of pixels in the node, R, G, and B histograms are constructed respectively. In the three histograms, the R, G, and B values ​​with the largest proportion of pixels are selected as candidate thresholds. Calculate the information gain of node partitioning using each candidate threshold, and select the candidate threshold with the largest information gain as the segmentation threshold. The node is divided into two parts according to the segmentation threshold, thus completing one division of the node; S4. Repeat step S3 until the preset number of iterations is reached to obtain the final octree; S5. Average the RGB values ​​of the pixels in all leaf nodes of the octree to obtain the main color of the laser marking sample color block.

2. The method for extracting the main color of a laser-marked sample color block as described in claim 1, characterized in that, In step S3, the octree is pruned, including the following steps: Select a bottom-level non-leaf node, merge its child nodes, use the average of the pixel RGB values ​​of all child nodes as the RGB value of the pixel in the non-leaf node, and then clear the child nodes.

3. The method for extracting the main color of a laser-marked sample color block as described in claim 1, characterized in that, The quantity threshold is set to 256.

4. The method for extracting the main color of a laser-marked sample color block as described in claim 1, characterized in that, Step S2 specifically includes the following steps: Initialize the octree and divide the RGB color space into eight regions, with each region corresponding to a node in the octree. Traverse all pixels in the image to be processed and insert the RGB value of each pixel into the corresponding octree node.

5. The method for extracting the main color of a laser-marked sample color patch as described in any one of claims 1-4, characterized in that, Step S1 includes the following steps: The laser-marked sample was photographed to obtain a digital image, which was then preprocessed. Based on the arrangement of color blocks on the laser-marked sample, the preprocessed digital image is divided into multiple regions accordingly; Extract the region contour information to obtain the image to be processed corresponding to the color block.

6. The method for extracting the main color of a laser-marked sample color block as described in claim 5, characterized in that, Preprocessing of digital images includes denoising, grayscale conversion, and binarization.

7. The method for extracting the main color of a laser-marked sample color block as described in claim 5, characterized in that, The contour information of the region is extracted by the OpenCV contour extraction function to obtain the ROI region, and thus the image to be processed corresponding to the color block is obtained.

8. A system for extracting the main color of a laser-marked sample color patch, characterized in that, Includes a processor, the processor being used to perform the method for extracting the main color of a laser-marked sample color block as described in any one of claims 1-7.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the method for extracting the main color of a laser-marked sample color block as described in any one of claims 1-7.

Citation Information

Patent Citations

  • Method for compressing types of image colors

    CN102231208A

  • Color reducing method and device of true color image

    CN102592293A