Methods, systems, storage media and devices for detecting color components in industrial products

CN122574115APending Publication Date: 2026-08-14HANGZHOU HUICUI INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-05-20
Publication Date
2026-08-14

AI Technical Summary

Technical Problem

[0004]本发明的目的是提供一种工业产品的颜色成分检测方法、系统、存储介质和装置,用于解决现有颜色检测技术光照适应性差、缺乏空间上下文感知、对微小目标不敏感以及模型泛化能力弱、维护成本高的核心问题

Benefits of technology

[0062]1.卓越的光照鲁棒性:通过采用CIE Lab色彩空间和对光照相对不敏感的颜色通道作为光谱流输入,并结合色彩恒常性激励模块进行特征增强,对光照强度和色温变化的容忍度远高于基于RGB/HSV阈值或统计的方法,其中,模型学习的是颜色的本质属性,而非表观值。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122574115A_ABST
    Figure CN122574115A_ABST
Patent Text Reader

Abstract

This invention discloses a method, system, storage medium, and apparatus for detecting the color components of industrial products. The method includes: acquiring and preprocessing a raw image to obtain a target image, the target image comprising three independent image channel matrices; extracting dual-stream features from the target image to obtain a color feature map and a spatial feature map; concatenating and fusing the color feature map and the spatial feature map to obtain a fused feature map and a spatial attention map; spatially weighting the fused feature map and the spatial attention map to obtain a weighted feature map; performing global average pooling on all spatial locations of the weighted feature map to obtain a feature vector, and inputting the feature vector into a classifier to obtain the confidence score of the target color component for output. This invention achieves highly robust and high-precision detection of the presence or absence of color components in industrial products through spectral-spatial dual-stream feature extraction and semantically guided attention fusion.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image processing technology, and more specifically, to a method, system, storage medium, and apparatus for detecting the color components of industrial products. Background Technology

[0002] In many industrial sectors, such as food sorting, pharmaceutical packaging, printed material quality inspection, electronic component polarity identification, and cosmetic packaging assembly, accurately determining the presence or absence of specific color components on a product or its label is a crucial quality control step.

[0003] This type of detection not only requires identifying the presence of color, but also often needs to maintain extremely high accuracy under complex backgrounds, changing lighting conditions, or when the area of ​​color components is small and their position is not fixed. Traditional manual visual inspection is inefficient, inconsistent in standards, and prone to fatigue. Therefore, the use of machine vision for automated color detection has become an inevitable trend. Summary of the Invention

[0004] The purpose of this invention is to provide a method, system, storage medium, and device for detecting the color components of industrial products, in order to solve the core problems of existing color detection technologies, such as poor light adaptability, lack of spatial context awareness, insensitivity to small targets, weak model generalization ability, and high maintenance costs.

[0005] The first aspect of this invention provides a method for detecting the color components of industrial products, comprising the following steps:

[0006] The acquired raw image is preprocessed to obtain the target image, which includes three independent image channel matrices;

[0007] Based on the target image, dual-stream features are extracted to obtain a color feature map and a spatial feature map;

[0008] Based on the color feature map and the spatial feature map, a fused feature map and a spatial attention map are obtained by splicing and fusing them.

[0009] A weighted feature map is obtained by spatial weighting based on the fused feature map and the spatial attention map;

[0010] Global average pooling is performed on all spatial locations of the weighted feature map to obtain feature vectors, and the feature vectors are input into a classifier to obtain the confidence scores of the target color components and output them.

[0011] In this scheme, the acquired raw image is preprocessed to obtain the target image, which includes three independent image channel matrices, specifically including:

[0012] Acquire the original image The original image is converted from the RGB color space to the CIE Lab color space to obtain the target image. ;

[0013] Based on the target image, channel separation is performed to obtain three channels: brightness, red-green axis, and yellow-blue axis. Based on these three channels, three independent image channel matrices are obtained, wherein the independent image channel matrix includes a brightness channel matrix. and color channel matrix , ; and contrast-limited adaptive histogram equalization of the brightness channel to obtain the target enhancement image. .

[0014] In this scheme, the step of extracting dual-stream features from the target image to obtain a color feature map and a spatial feature map specifically includes:

[0015] Based on color channel matrix , Feature extraction is performed to obtain the color feature map, wherein the color information is input into a preset first convolutional neural network using a color constancy activation module, as shown in the following formula:

[0016] ;

[0017] in, It is a color feature map. This is the feature map of the intermediate layer of the spectral flow; GAP is global average pooling. Learnable weight matrix It is the ReLU activation function. It is the Sigmoid function; and based on the brightness channel matrix Feature extraction is performed to obtain the spatial feature map, wherein the structural information of the brightness channel is input into a second convolutional neural network, and the convolutional kernel is used to capture edges, textures, and shapes to obtain the spatial feature map. .

[0018] In this solution, the step of stitching and fusing the color feature map and the spatial feature map to obtain a fused feature map and a spatial attention map specifically includes:

[0019] Color feature map and spatial feature map The concatenation is performed along the channel dimension, and then fused through convolution to obtain the fused feature map. ;

[0020] Obtain the trained semantic query vector, and calculate the spatial dot product similarity between the semantic query vector and the fused feature map to obtain the initial response map;

[0021] The initial response map is integrated and refined, and then normalized using the Sigmoid function to obtain the spatial attention map. , These are dimensional parameters.

[0022] In this scheme, the step of obtaining a weighted feature map by spatial weighting based on the fused feature map and the spatial attention map specifically includes:

[0023] The fused feature map is spatially weighted using the spatial attention map, calculated as follows:

[0024] ;

[0025] in, For the weighted feature map, The spatial attention map, For the fused feature map, This indicates element-wise multiplication.

[0026] In this scheme, the step of performing global average pooling on all spatial locations of the weighted feature map to obtain a feature vector, and then inputting the feature vector into a classifier to obtain the confidence score of the target color component for output, specifically includes:

[0027] The weighted feature map is subjected to global average pooling to convert it into a fixed-length feature vector;

[0028] The feature vector is input into a fully connected layer classifier to obtain a binary decision probability, where the decision probability represents the confidence level of the target color component;

[0029] The decision result is output based on the comparison between the decision probability and a preset threshold to determine whether there is a color component.

[0030] A second aspect of the present invention also provides a color component detection system for industrial products, including a memory and a processor. The memory includes a method program for detecting the color component of industrial products. When the color component detection method program for industrial products is executed by the processor, it performs the following steps:

[0031] The acquired raw image is preprocessed to obtain the target image, which includes three independent image channel matrices;

[0032] Based on the target image, dual-stream features are extracted to obtain a color feature map and a spatial feature map;

[0033] Based on the color feature map and the spatial feature map, a fused feature map and a spatial attention map are obtained by splicing and fusing them.

[0034] A weighted feature map is obtained by spatial weighting based on the fused feature map and the spatial attention map;

[0035] Global average pooling is performed on all spatial locations of the weighted feature map to obtain feature vectors, and the feature vectors are input into a classifier to obtain the confidence scores of the target color components and output them.

[0036] In this scheme, the acquired raw image is preprocessed to obtain the target image, which includes three independent image channel matrices, specifically including:

[0037] Acquire the original image The original image is converted from the RGB color space to the CIE Lab color space to obtain the target image. ;

[0038] Based on the target image, channel separation is performed to obtain three channels: brightness, red-green axis, and yellow-blue axis. Based on these three channels, three independent image channel matrices are obtained, wherein the independent image channel matrix includes a brightness channel matrix. and color channel matrix , ; and contrast-limited adaptive histogram equalization of the brightness channel to obtain the target enhancement image. .

[0039] In this scheme, the step of extracting dual-stream features from the target image to obtain a color feature map and a spatial feature map specifically includes:

[0040] Based on color channel matrix , Feature extraction is performed to obtain the color feature map, wherein the color information is input into a preset first convolutional neural network using a color constancy activation module, as shown in the following formula:

[0041] ;

[0042] in, It is a color feature map. This is the feature map of the intermediate layer of the spectral flow; GAP is global average pooling. Learnable weight matrix It is the ReLU activation function. It is the Sigmoid function; and based on the brightness channel matrix Feature extraction is performed to obtain the spatial feature map, wherein the structural information of the brightness channel is input into a second convolutional neural network, and the convolutional kernel is used to capture edges, textures, and shapes to obtain the spatial feature map. .

[0043] In this solution, the step of stitching and fusing the color feature map and the spatial feature map to obtain a fused feature map and a spatial attention map specifically includes:

[0044] Color feature map and spatial feature map The concatenation is performed along the channel dimension, and then fused through convolution to obtain the fused feature map. ;

[0045] Obtain the trained semantic query vector, and calculate the spatial dot product similarity between the semantic query vector and the fused feature map to obtain the initial response map;

[0046] The initial response map is integrated and refined, and then normalized using the Sigmoid function to obtain the spatial attention map. , These are dimensional parameters.

[0047] In this scheme, the step of obtaining a weighted feature map by spatial weighting based on the fused feature map and the spatial attention map specifically includes:

[0048] The fused feature map is spatially weighted using the spatial attention map, calculated as follows:

[0049] ;

[0050] in, For the weighted feature map, The spatial attention map, For the fused feature map, This indicates element-wise multiplication.

[0051] In this scheme, the step of performing global average pooling on all spatial locations of the weighted feature map to obtain a feature vector, and then inputting the feature vector into a classifier to obtain the confidence score of the target color component for output, specifically includes:

[0052] The weighted feature map is subjected to global average pooling to convert it into a fixed-length feature vector;

[0053] The feature vector is input into a fully connected layer classifier to obtain a binary decision probability, where the decision probability represents the confidence level of the target color component;

[0054] The decision result is output based on the comparison between the decision probability and a preset threshold to determine whether there is a color component.

[0055] A third aspect of the present invention provides a computer-readable storage medium comprising a program for a method of detecting the color composition of an industrial product, wherein when executed by a processor, the program implements the steps of a method for detecting the color composition of an industrial product as described in any of the preceding claims.

[0056] A fourth aspect of the present invention provides a color component detection device for industrial products, comprising:

[0057] Optical imaging module and detection module, wherein,

[0058] The optical imaging module includes an industrial camera and a light source, wherein the industrial camera is used to acquire images and the light source is used to provide illumination;

[0059] The detection module includes an industrial computer with a high-performance GPU, used to implement the steps of the color component detection method for an industrial product as described above.

[0060] In this solution, the light source is a ring light source or a dome light source, used to provide diffuse lighting.

[0061] The present invention discloses a method, system, storage medium, and apparatus for detecting the color components of industrial products, which have the following beneficial effects:

[0062] 1. Excellent light robustness: By adopting the CIE Lab color space and color channels that are relatively insensitive to light as spectral stream inputs, and combining it with a color constancy excitation module for feature enhancement, the tolerance to changes in light intensity and color temperature is much higher than that of methods based on RGB / HSV thresholds or statistics. Here, the model learns the essential properties of color, rather than the apparent values.

[0063] 2. Powerful background suppression and contextual understanding capabilities: The semantically guided attention fusion module enables the network to no longer treat all color pixels "equally". Instead, it can combine spatial structure and semantic priors to intelligently focus attention on the area where the target is most likely to appear, greatly reducing the risk of misjudging similar colors in the background as the target.

[0064] 3. High sensitivity to small targets and local defects: Due to the adoption of a fully convolutional network structure and spatial attention mechanism, the model can perceive any subtle color anomalies in the image. Even if the target color region is small, as long as its features match the learned semantic query, it can be captured by the attention map and affect the final global decision, effectively avoiding the defect of histogram statistical methods being insensitive to local information.

[0065] 4. End-to-end learning and low maintenance cost: Training is conducted in a data-driven manner, eliminating the need for manually designing complex thresholds or features. When the application scenario changes (such as product redesign), only fine-tuning with new data is required, which greatly reduces the difficulty and cost of maintenance and deployment.

[0066] 5. Strong interpretability of the decision-making process: The generated spatial attention map and auxiliary segmentation map intuitively show the basis for the model's decision-making, namely "where the model thinks the target color is", which enhances the user's trust in the system and facilitates troubleshooting and model optimization. Attached Figure Description

[0067] Figure 1 This invention illustrates the steps of a method for detecting the color components of an industrial product.

[0068] Figure 2 A schematic flowchart of a method for detecting the color components of an industrial product according to the present invention is shown;

[0069] Figure 3 A schematic diagram illustrating the generation process of a spatial attention map for a color component detection method for industrial products according to the present invention is shown.

[0070] Figure 4 A schematic diagram showing the detection results of a color component detection method for industrial products according to the present invention is illustrated.

[0071] Figure 5 A block diagram of a color composition detection system for industrial products according to the present invention is shown;

[0072] Figure 6 A schematic diagram of the composition of a color component detection device for industrial products according to the present invention is shown.

[0073] Component designation: 611 Industrial camera; 612 Light source; 621 Industrial computer; 63 Support platform. Detailed Implementation

[0074] To better understand the above-mentioned objectives, features, and advantages of the present invention, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. It should be noted that, unless otherwise specified, the embodiments of the present invention and the features thereof can be combined with each other.

[0075] Many specific details are set forth in the following description in order to provide a full understanding of the invention. However, the invention may also be practiced in other ways different from those described herein, and therefore the scope of protection of the invention is not limited to the specific embodiments disclosed below.

[0076] Existing machine vision-based color detection schemes primarily rely on the distribution characteristics of colors within a specific color space for differentiation. The most similar implementations include color space segmentation based on fixed thresholds, comparison based on color histogram statistics, and pixel classification based on traditional machine learning classifiers.

[0077] Specifically, the background technology and existing technology solution one: RGB / HSV color space segmentation based on fixed thresholds. This is the most intuitive and widely used solution. First, a standard image is acquired under specific lighting conditions. Engineers observe the color area to be inspected (such as the red warning strip on a medicine bottle label) and manually set a set of threshold ranges in the RGB or HSV color space. For example, in the RGB space, for a specific red color, a rule might be set: if the R, G, and B components of a pixel satisfy... , ,and If the color is not specified, then the pixel is determined to be the target color. In the HSV color space, because it separates hue, saturation, and value, it is slightly more robust to changes in lighting. The rules are set as follows: , , During detection, the image to be tested is scanned pixel by pixel. Pixels that meet the criteria are marked as "1" (target color), and others are marked as "0", forming a binary image. Then, morphological operations and connected component analysis are used to calculate the area or number of target color pixels. If the area exceeds a threshold, the image is considered "present"; otherwise, it is considered "absent". The advantage of this method is its simplicity and fast calculation speed. However, its disadvantage is extremely critical: it is extremely sensitive to changes in lighting. Slight changes in the color temperature and intensity of ambient light can cause RGB or HSV values ​​to drift, rendering the fixed threshold ineffective, resulting in either missed detections or misclassification of the background color as the target color. In addition, threshold setting relies on human experience, which is highly subjective. Furthermore, for scenes with similar colors or complex backgrounds, it is difficult to find a threshold that can both guarantee the detection rate and reduce the false alarm rate.

[0078] And background technology and existing technology solution two: a method based on color histogram comparison or statistical features. In order to improve robustness, this solution no longer focuses on a single pixel, but starts from the statistical features of the region. First, a region containing only the target color is defined on the standard sample, and its color histogram is calculated, such as the H component histogram in the HSV space. During detection, the H-component histogram is calculated in the corresponding region or globally of the image to be inspected. By calculating the similarity between two histograms (such as Bhattacharyya distance), The color composition can be determined by the distance the Earth has moved (or Earth's distance). The formula for calculating the Bach distance is:

[0079] ;

[0080] like If the color is below a certain threshold, the target color is considered to be present. This method is more tolerant of minor pixel fluctuations and noise than pixel-level thresholding. However, its limitation lies in its heavy reliance on precise region delineation. If the position, size, or shape of the target color region changes, or if the background color is included in the statistical region, the histogram features will change drastically, leading to misjudgments. It is essentially a global statistical method and cannot handle localized missing values ​​or minor contamination. For example, most of the red area on a label may be present, but a small area may be worn; its histogram might still be highly similar to the standard histogram, resulting in a missed "missing" defect.

[0081] And background technology and existing technology solution three: color pixel classification based on traditional machine learning classifiers (such as SVM). This solution attempts to learn the color decision boundary through machine learning. First, a large number of samples need to be collected, including target color pixels and non-target color pixels (background), and the color features of each pixel are extracted, such as a three-dimensional feature vector. or Then, classifiers such as Support Vector Machines (SVM) are used to train the samples in these feature spaces to find an optimal hyperplane that separates the two classes of pixels. During detection, features are extracted from each pixel in the image and input into the trained SVM model to determine whether it belongs to the target color or the background. This method is more adaptive than a fixed threshold and can theoretically handle more complex color distributions. However, it still has significant problems: limited feature representation ability; relying only on three color channel information, classification performance drops sharply when colors are similar and lighting changes are large. It also faces the problem of lighting sensitivity; the model's performance is difficult to guarantee when trained under one lighting condition and tested under another. Moreover, the collection and labeling of training data (pixel-by-pixel labeling) is costly, and the model has poor adaptability to product changes (changes in target color), requiring data collection and retraining.

[0082] Through in-depth analysis of the above-mentioned existing technical solutions, it can be clearly summarized that they have the following shortcomings when dealing with the detection of color components in complex industrial scenarios:

[0083] 1. Fragile light adaptability: The core features of existing methods (RGB / HSV values) directly depend on the incident light. Slight changes in illumination can cause significant drift in feature values, resulting in poor stability of the detection system and requiring frequent recalibration or parameter adjustment.

[0084] 2. Lack of spatial context awareness: Whether it's the thresholding method, histogram method, or pixel-level classification method, they all mainly focus on the color information itself, ignoring the spatial distribution of color and the contextual information of the surrounding environment. For example, existing methods cannot use prior knowledge such as "the red warning bar should be at the top of the label" to assist in the judgment, nor can they distinguish whether a red pixel belongs to the warning bar or a red pattern in the background;

[0085] 3. Insensitive to small targets and local defects: Histogram statistics can overwhelm local information; although pixel-level methods can locate targets, they are susceptible to noise interference, and when the target color area is very small (such as a small color dot), it is easily filtered out by morphological operations or ignored in global decision-making.

[0086] 4. High model generalization and maintenance costs: Thresholds and traditional machine learning models are strongly bound to specific colors, backgrounds and lighting conditions. When product models are changed, material colors are changed or the production environment is adjusted on the production line, the system requires a lot of manual intervention and re-adjustment, resulting in low automation and intelligence levels.

[0087] To address these shortcomings, the present invention aims to provide a robust color component presence / absence detection method based on spectral-spatial dual-stream analysis and semantically guided attention. This method transcends the traditional paradigm relying on raw RGB / HSV values, simulating the mechanism by which the human visual system combines color and spatial structure for comprehensive judgment. It achieves an intelligent color detection scheme that is insensitive to illumination changes, understands scene context, and exhibits high sensitivity to small targets. Specifically, it weakens the direct impact of illumination changes on color judgment through innovative feature extraction methods; by introducing spatial context and semantic information, it "knows" where to find the target color, thus eliminating background interference; and it constructs an end-to-end deep learning model that can automatically learn the essential characteristics of color components from data, reducing reliance on manual parameter tuning and improving generalization ability across different products and environments. The core innovations and key protection points are:

[0088] 1. Dual-stream encoder architecture for color component detection: specially protected network design that uses spectral and spatial streams for feature extraction in parallel.

[0089] 2. Color constancy excitation module: A specific structure and method for protecting color features robust to illumination changes in the spectral stream through a channel attention mechanism.

[0090] 3. Semantically Guided Attention Fusion Module: Protects the complete mechanism for generating a spatial attention map for focusing on target regions by interacting with learnable semantic query vectors and dual-stream fusion features.

[0091] 4. Attention-weighted feature extraction and decision-making process: This is a systematic method that uses the output attention map to spatially weight the fused features, and then uses global pooling and a classifier to achieve the final "presence" judgment.

[0092] 5. Hybrid supervised training strategy combining classification and segmentation: a method that protects the joint training of the network using both image-level labels and (optionally) pixel-level segmentation labels to improve model performance and interpretability.

[0093] 6. A complete color component detection system covering everything from Lab* space preprocessing to CA-Net inference: a full-process implementation plan from image acquisition, color space conversion, enhancement, to network inference and result visualization.

[0094] Specifically, Figure 1 The diagram illustrates the steps of a method for detecting the color components of an industrial product according to the present invention.

[0095] like Figure 1 As shown, this invention discloses a method for detecting the color components of industrial products, comprising the following steps:

[0096] S102, acquire the raw image and preprocess it to obtain the target image, the target image including three independent image channel matrices;

[0097] S104, extract dual-stream features based on the target image to obtain a color feature map and a spatial feature map;

[0098] S106, Based on the color feature map and the spatial feature map, a fused feature map and a spatial attention map are obtained by splicing and fusing them.

[0099] S108, A weighted feature map is obtained by spatial weighting based on the fused feature map and the spatial attention map;

[0100] S110, perform global average pooling on all spatial locations of the weighted feature map to obtain a feature vector, and input the feature vector into the classifier to obtain the confidence score of the target color component and output it.

[0101] It should be noted that, in this embodiment, when detecting the presence or absence of color components in industrial products, such as in food sorting, pharmaceutical packaging, printing quality inspection, electronic component polarity identification, and cosmetic packaging assembly, to accurately determine the "presence or absence" of specific color components on the product or its label, the original image of the product must first be obtained by taking a picture using a preset industrial camera. The camera is selected with good color reproduction capabilities, its white balance function is ensured to be accurate or a fixed white balance mode is used, and the camera is color calibrated.

[0102] Furthermore, in this embodiment, the core algorithm flow of the present invention is as follows: Figure 2 As shown, a deep learning network, Color-Attention Net (CA-Net, Color-Space Dual-Stream Attention Network), is used to process images. The network receives a color image as input and outputs a decision indicating whether the target color component is present or absent, visually indicating the target location. Specifically, after acquiring the raw image, preprocessing is performed to obtain the target image. The obtained target image includes three independent image channel matrices, including a brightness channel matrix. and color channel matrix , Then, based on the target image, dual-stream features are extracted to obtain a color feature map and a spatial feature map. The color feature map and the spatial feature map are then spliced ​​and fused to obtain a fused feature map and a spatial attention map. The spatial attention map can highlight the region in the image that is most likely to be the target color component.

[0103] Furthermore, in this embodiment, a weighted feature map is obtained by spatial weighting based on the fused feature map and the spatial attention map, thereby refining the features, strengthening the features of the target region, and weakening the features of the background region. Then, global average pooling is performed on all spatial locations of the weighted feature map to obtain a feature vector, and the feature vector is input into a classifier to obtain the confidence of the target color component for output. The output can not only output the judgment result of the presence or absence of the current color component, but also output a pixel-level segmentation map, an attention heatmap, and an overlay display image.

[0104] According to an embodiment of the present invention, the acquired raw image is preprocessed to obtain a target image, the target image comprising three independent image channel matrices, specifically including:

[0105] Acquire the original image The original image is converted from the RGB color space to the CIE Lab color space to obtain the target image. ;

[0106] Based on the target image, channel separation is performed to obtain three channels: brightness, red-green axis, and yellow-blue axis. Based on these three channels, three independent image channel matrices are obtained, wherein the independent image channel matrix includes a brightness channel matrix. and color channel matrix , ; and contrast-limited adaptive histogram equalization of the brightness channel to obtain the target enhancement image. .

[0107] It should be noted that, in this embodiment, the original image First, convert the RGB color space to the CIE Lab color space to obtain the target image. The CIE Lab color space is designed to better align with human visual perception. The L* channel represents lightness, while the a* and b* channels represent contrasting color dimensions. Channel separation based on the target image yields three channels: lightness, red-green axis, and yellow-blue axis. These three channels result in three independent image channel matrices, including a lightness channel matrix. and color channel matrix , The process involves contrast-limited adaptive histogram equalization of the L* channel to enhance local image contrast while suppressing noise. This step improves the visibility of details in dark or overly bright areas without significantly altering color information (a*, b*), laying the foundation for subsequent processing. The processed image is denoted as the target enhanced image. .

[0108] According to an embodiment of the present invention, the step of extracting two-stream features from the target image to obtain a color feature map and a spatial feature map specifically includes:

[0109] Based on color channel matrix , Feature extraction is performed to obtain the color feature map, wherein the color information is input into a preset first convolutional neural network using a color constancy activation module, as shown in the following formula:

[0110] ;

[0111] in, It is a color feature map. This is the feature map of the intermediate layer of the spectral flow; GAP is global average pooling. Learnable weight matrix It is the ReLU activation function. It is the Sigmoid function; and based on the brightness channel matrix Feature extraction is performed to obtain the spatial feature map, wherein the structural information of the brightness channel is input into a second convolutional neural network, and the convolutional kernel is used to capture edges, textures, and shapes to obtain the spatial feature map. .

[0112] It should be noted that, in this embodiment, the encoder part of CA-Net consists of two parallel branches, each responsible for extracting different types of information. The Spectral Stream branch focuses on extracting color features robust to changes in illumination, with the input being enhanced a* and b* channels. Because these two channels primarily carry color information and are decoupled to some extent from lightness (L*), the main body of the spectral flow is a lightweight first-order convolutional neural network (e.g., composed of several convolutional and pooling layers). Its key innovation lies in the introduction of a Color Constancy Excitation (CCE) module. This module adaptively recalibrates the channel feature responses by analyzing the inter-channel relationships of the feature maps. Its calculation formula is as follows:

[0113] ;

[0114] in, It is a color feature map. This is the feature map of the intermediate layer of the spectral flow; GAP is global average pooling. Learnable weight matrix It is the ReLU activation function. It is the Sigmoid function, where the CCE module enables the network to learn which color features are stable and critical under various lighting conditions, thereby suppressing interference caused by lighting changes and enhancing the representation of the essence of color. The output of the spectral stream is a high-level color feature map. .

[0115] Furthermore, the Spatial Stream branch focuses on extracting texture, shape, and spatial structure information from the image. Its input is the L* channel of the CIE Lab color space. The Spatial Stream uses a second convolutional neural network (which can share the structure with the spectral stream but has independent weights) to capture the edges, contours, and regional features of the target through convolution and pooling operations. Its output corresponds to a spatial feature map. .

[0116] According to an embodiment of the present invention, the step of splicing and fusing the color feature map and the spatial feature map to obtain a fused feature map and a spatial attention map specifically includes:

[0117] Color feature map and spatial feature map The concatenation is performed along the channel dimension, and then fused through convolution to obtain the fused feature map. ;

[0118] Obtain the trained semantic query vector, and calculate the spatial dot product similarity between the semantic query vector and the fused feature map to obtain the initial response map;

[0119] The initial response map is integrated and refined, and then normalized using the Sigmoid function to obtain the spatial attention map. , These are dimensional parameters.

[0120] It should be noted that, in this embodiment, the use of a semantic-guided attention fusion (SGAF) module to generate the spatial attention map is one of the core innovations of this invention. This module receives color feature maps from a two-stream encoder. and spatial feature map The goal is to generate a spatial attention graph. This image highlights the areas in the image most likely to contain the target color components.

[0121] Specifically, in this embodiment, as Figure 3 The diagram shown illustrates the process of generating a spatial attention map. The first step involves feature stitching and fusion: combining the color feature map... and spatial feature map The data is concatenated along the channel dimension and then fused using a 1x1 convolution to obtain a fused feature map. Then obtain the trained semantic query vector. Among them, semantic query vector Defined as a set of learnable semantic query vectors, where each vector can be understood as an abstract concept of the target color component in different typical contexts (e.g., "the red bar at the top", "scattered blue dots") formed by the network during the learning process. By calculating the spatial dot product similarity between the semantic query vectors and the fused feature map, an initial attention response map can be obtained. Then, the initial response map is integrated and refined through convolutional layers and the sigmoid function to finally generate a spatial attention map. , Here are the dimensional parameters, where, The closer the value is to "1", the more it indicates the position. The higher the probability of it belonging to the corresponding target color component.

[0122] According to an embodiment of the present invention, the step of obtaining a weighted feature map by spatial weighting based on the fused feature map and the spatial attention map specifically includes:

[0123] The fused feature map is spatially weighted using the spatial attention map, calculated as follows:

[0124] ;

[0125] in, For the weighted feature map, The spatial attention map, For the fused feature map, This indicates element-wise multiplication.

[0126] It should be noted that, in this embodiment, the generated spatial attention map is used. For fused feature maps The weighted feature map is obtained by spatial weighting, and the calculation formula is: ,in, For the weighted feature map, The spatial attention map, For the fused feature map, This indicates element-wise multiplication. This step is equivalent to "purifying" the features, strengthening the features of the target region and weakening the features of the background region.

[0127] According to an embodiment of the present invention, the step of performing global average pooling on all spatial locations of the weighted feature map to obtain a feature vector, and inputting the feature vector into a classifier to obtain the confidence score of the target color component for output, specifically includes:

[0128] The weighted feature map is subjected to global average pooling to convert it into a fixed-length feature vector;

[0129] The feature vector is input into a fully connected layer classifier to obtain a binary decision probability, where the decision probability represents the confidence level of the target color component;

[0130] The decision result is output based on the comparison between the decision probability and a preset threshold to determine whether there is a color component.

[0131] It should be noted that, in this embodiment, the weighted feature map is subjected to global average pooling to convert it into a fixed-length feature vector. This feature vector is then input into a fully connected layer classifier, which ultimately outputs a binary decision probability, where the decision probability represents the confidence level of the target color component, corresponding to: and , By setting a preset threshold (such as 0.5), a final judgment can be made, and the result of whether there is a color component can be output. Figure 4 As shown, this is a visualization of the detection results. Furthermore, to enhance the model's interpretability and provide more refined localization information, an auxiliary segmentation decoder can be added. This decoder takes the aforementioned fused or weighted features as input, upsamples them, and outputs a binary segmentation map with the same resolution as the input image. It visually displays all pixel areas that have been identified as the target color.

[0132] Furthermore, it should be noted that the method of this invention is based on the application of a deep learning network model, Color-Attention Net (CA-Net, Color-Space Dual-Stream Attention Network). The model uses a large number of labeled images for end-to-end training. The labeling information includes image-level labels ("present / absent") and / or pixel-level segmentation masks (used to assist training). The loss function typically consists of two parts: the main loss is the binary cross-entropy loss for image classification. The auxiliary loss is the Dice loss for the segmentation task. (If splitting branches is used), the total loss is ,in It is the weighting coefficient.

[0133] During the inference phase, the input image to be detected is processed through the CA-Net forward propagation, and the result is determined based on the output. Decision-making can be done while simultaneously visualizing attention maps. and auxiliary segmentation map (If present) to provide decision-making support for operators.

[0134] Figure 5 A block diagram of a color composition detection system for industrial products according to the present invention is shown.

[0135] like Figure 5 As shown, this invention discloses a color component detection system for industrial products, including a memory and a processor. The memory includes a color component detection method program for industrial products. When the processor executes the color component detection method program for industrial products, it performs the following steps:

[0136] The acquired raw image is preprocessed to obtain the target image, which includes three independent image channel matrices;

[0137] Based on the target image, dual-stream features are extracted to obtain a color feature map and a spatial feature map;

[0138] Based on the color feature map and the spatial feature map, a fused feature map and a spatial attention map are obtained by splicing and fusing them.

[0139] A weighted feature map is obtained by spatial weighting based on the fused feature map and the spatial attention map;

[0140] Global average pooling is performed on all spatial locations of the weighted feature map to obtain feature vectors, and the feature vectors are input into a classifier to obtain the confidence scores of the target color components and output them.

[0141] It should be noted that when the color component detection system for industrial products disclosed in this application is applied, the specific process corresponds to the color component detection method for industrial products described in the above embodiments. Since the specific implementation details of the system application are consistent with the content of the color component detection method for industrial products described above, no further details will be provided in this embodiment.

[0142] A third aspect of the present invention provides a computer-readable storage medium comprising a method program for detecting the color composition of an industrial product, wherein when executed by a processor, the method program implements the steps of a method for detecting the color composition of an industrial product as described in any of the preceding claims.

[0143] A fourth aspect of the present invention provides a color component detection device for industrial products, comprising:

[0144] Optical imaging module and detection module, wherein,

[0145] The optical imaging module includes an industrial camera 611 and a light source 612. The industrial camera 611 is used to acquire images, and the light source 612 is used to provide illumination.

[0146] The detection module includes an industrial computer 621 with a high-performance GPU, used to implement the steps of the color component detection method for an industrial product as described above.

[0147] It should be noted that, in this embodiment, the light source is a ring light source or a dome light source, used to provide diffuse illumination, such as... Figure 6 As shown, in this embodiment, a ring light source is used as an example. When the color component of the test object is detected, the test object is placed on the support platform 63, the light source 612 provides illumination, the industrial camera 611 acquires images of the test object, and then the industrial computer 621 processes the images to output a decision result on whether there is a color component.

[0148] This invention discloses a method, system, storage medium, and device for detecting the color components of industrial products. By extracting spectral and spatial dual-stream features and semantically guided attention fusion, it achieves highly robust and high-precision detection of the presence or absence of color components in industrial scenarios. The system performs stably under complex lighting conditions, can intelligently distinguish target colors from background interference, is sensitive to small targets and local defects, and significantly reduces manual debugging and maintenance costs through end-to-end learning. At the same time, it provides visualized attention heatmaps and segmentation results, and the decision-making process is transparent and interpretable, significantly improving the automation level and reliability of industrial quality inspection.

[0149] In the several embodiments provided by this invention, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods, such as: multiple units or components can be combined, or integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the various components shown or discussed can be through some interfaces, and the indirect coupling or communication connection between devices or units can be electrical, mechanical, or other forms.

[0150] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units. They may be located in one place or distributed across multiple network units. Some or all of the units may be selected to achieve the purpose of this embodiment according to actual needs.

[0151] In addition, in the various embodiments of the present invention, each functional unit can be integrated into one processing unit, or each unit can be a separate unit, or two or more units can be integrated into one unit; the integrated unit can be implemented in hardware or in the form of hardware plus software functional units.

[0152] Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0153] Alternatively, if the integrated units of this invention are implemented as software functional modules and sold or used as independent products, they can also be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the embodiments of this invention, or the parts that contribute to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, ROM, RAM, magnetic disks, or optical disks.

Claims

1. A method for detecting the color components of an industrial product, characterized in that, Includes the following steps: The acquired raw image is preprocessed to obtain the target image, which includes three independent image channel matrices; Based on the target image, dual-stream features are extracted to obtain a color feature map and a spatial feature map; Based on the color feature map and the spatial feature map, a fused feature map and a spatial attention map are obtained by splicing and fusing them. A weighted feature map is obtained by spatial weighting based on the fused feature map and the spatial attention map; Global average pooling is performed on all spatial locations of the weighted feature map to obtain feature vectors, and the feature vectors are input into a classifier to obtain the confidence scores of the target color components and output them.

2. The method for detecting the color components of an industrial product according to claim 1, characterized in that, The acquired raw image is preprocessed to obtain the target image, which includes three independent image channel matrices, specifically: Acquire the original image The original image is converted from the RGB color space to the CIE Lab color space to obtain the target image. ; Based on the target image, channel separation is performed to obtain three channels: brightness, red-green axis, and yellow-blue axis. Based on these three channels, three independent image channel matrices are obtained, wherein the independent image channel matrix includes a brightness channel matrix. and color channel matrix , ; and contrast-limited adaptive histogram equalization of the brightness channel to obtain the target enhancement image. .

3. The method for detecting the color components of an industrial product according to claim 2, characterized in that, The step of extracting dual-stream features from the target image to obtain a color feature map and a spatial feature map specifically includes: Based on color channel matrix , Feature extraction is performed to obtain the color feature map, wherein the color information is input into a preset first convolutional neural network using a color constancy activation module, as shown in the following formula: ; in, It is a color feature map. This is the feature map of the intermediate layer of the spectral flow; GAP is global average pooling. Learnable weight matrix It is the ReLU activation function. It is the Sigmoid function; and based on the brightness channel matrix Feature extraction is performed to obtain the spatial feature map, wherein the structural information of the brightness channel is input into a second convolutional neural network, and the convolutional kernel is used to capture edges, textures, and shapes to obtain the spatial feature map. .

4. The method for detecting the color components of an industrial product according to claim 3, characterized in that, The process of concatenating and fusing the color feature map and the spatial feature map to obtain a fused feature map and a spatial attention map specifically includes: Color feature map and spatial feature map The concatenation is performed along the channel dimension, and then fused through convolution to obtain the fused feature map. ; Obtain the trained semantic query vector, and calculate the spatial dot product similarity between the semantic query vector and the fused feature map to obtain the initial response map; The initial response map is integrated and refined, and then normalized using the Sigmoid function to obtain the spatial attention map. , These are dimensional parameters.

5. The method for detecting the color components of an industrial product according to claim 4, characterized in that, The step of spatially weighting the fused feature map and the spatial attention map to obtain a weighted feature map specifically includes: The fused feature map is spatially weighted using the spatial attention map, calculated as follows: ; in, For the weighted feature map, The spatial attention map, For the fused feature map, This indicates element-wise multiplication.

6. The method for detecting the color components of an industrial product according to claim 5, characterized in that, The process of performing global average pooling on all spatial locations of the weighted feature map to obtain a feature vector, and then inputting the feature vector into a classifier to obtain the confidence score of the target color component for output, specifically includes: The weighted feature map is subjected to global average pooling to convert it into a fixed-length feature vector; The feature vector is input into a fully connected layer classifier to obtain a binary decision probability, where the decision probability represents the confidence level of the target color component; The decision result is output based on the comparison between the decision probability and a preset threshold to determine whether there is a color component.

7. A color component detection system for industrial products, characterized in that, The system includes a memory and a processor. The memory contains a program for detecting the color composition of industrial products. When the processor executes the program for detecting the color composition of industrial products, it performs the following steps: The acquired raw image is preprocessed to obtain the target image, which includes three independent image channel matrices; Based on the target image, dual-stream features are extracted to obtain a color feature map and a spatial feature map; Based on the color feature map and the spatial feature map, a fused feature map and a spatial attention map are obtained by splicing and fusing them. A weighted feature map is obtained by spatial weighting based on the fused feature map and the spatial attention map; Global average pooling is performed on all spatial locations of the weighted feature map to obtain feature vectors, and the feature vectors are input into a classifier to obtain the confidence scores of the target color components and output them.

8. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a method program for detecting the color composition of an industrial product. When the method program is executed by a processor, it implements the steps of a method for detecting the color composition of an industrial product as described in any one of claims 1 to 6.

9. A color component detection device for industrial products, characterized in that, include: Optical imaging module and detection module, wherein, The optical imaging module includes an industrial camera and a light source, wherein the industrial camera is used to acquire images and the light source is used to provide illumination; The detection module includes an industrial computer with a high-performance GPU, used to implement the steps of the color component detection method for an industrial product as described in any one of claims 1 to 6.

10. The color component detection device for industrial products according to claim 9, characterized in that, The light source is either a ring light source or a dome light source, used to provide diffuse illumination.