Image defect detection method and device, electronic equipment and storage medium
By converting color images to a color contrast space and processing them using guided filtering technology, the accuracy and stability issues of detecting subtle color differences on the surface of industrial products are resolved, achieving high-precision and high-robust defect detection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SHENZHEN LINGYUN VISION TECH CO LTD
- Filing Date
- 2025-12-26
- Publication Date
- 2026-04-24
AI Technical Summary
Existing technologies are insufficient to effectively identify and detect subtle color difference defects on the surface of industrial products, resulting in unstable test results and low accuracy.
The color image is converted to a color-opposite space (such as the LAB color space) to separate brightness and color information. Guided filtering is then used to process the color channels to suppress noise and background interference, preserve defect edge features, and highlight image defect features through differential operations and adaptive enhancement.
It improves the accuracy and stability of identifying subtle color difference defects, making it suitable for identifying subtle color defects in industrial appearance inspection, and achieving high-precision and robust image defect detection.
Smart Images

Figure CN121921269A_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of image processing technology, and in particular relates to an image defect detection method, device, electronic equipment, and storage medium. Background Technology
[0002] With increasingly stringent requirements for industrial appearance inspection, subtle color differences on product surfaces have become a key challenge affecting the accuracy and stability of inspections. These defects often manifest as slight shifts in hue, tone, or saturation, with extremely minor color differences from the normal background. Directly inspecting the original image of the product surface for defects often leads to unstable results due to the extremely subtle defect characteristics.
[0003] In related technologies, the detection of subtle color difference defects typically relies on overall enhancement preprocessing of the original image, such as saturation boosting, contrast stretching, or frequency domain filtering, to amplify the difference between the defect and the background. However, in practical applications, saturation boosting is largely ineffective for color changes that are already in high-saturation regions; while contrast stretching increases overall contrast, it also proportionally amplifies image noise, making it difficult to achieve stable and reliable color difference defect recognition. Summary of the Invention
[0004] This invention aims to at least solve one of the technical problems existing in the prior art. To this end, this invention proposes an image defect detection method, device, electronic equipment, and storage medium to achieve stable and reliable color difference defect detection.
[0005] In a first aspect, this application provides an image defect detection method, the method comprising: The color image to be detected is converted to a color contrast space to obtain the sub-images corresponding to each color channel of the color image in the color contrast space; The target channel image is determined from the sub-images corresponding to each color channel, and the target channel image is subjected to guided filtering to obtain the guided filtered image corresponding to the color image. Determine the target difference image of the color image based on the target channel image and the guided filter image; Defect detection is performed on the target difference image to obtain the defect detection results of the color image.
[0006] According to one embodiment of this application, guided filtering processing is performed on a target channel image to obtain a guided filtered image corresponding to a color image. Specifically, this includes: defining multiple local windows on the target channel image, establishing a linear model between the pixel values of the target channel image and the output pixel values within each of the multiple local windows; determining the linear parameters of each local window based on the linear model, and obtaining the output pixel values corresponding to each local window based on the linear parameters; and integrating the output pixel values corresponding to each local window to obtain the guided filtered image.
[0007] According to one embodiment of this application, determining a target difference image of a color image based on a target channel image and a guided filter image specifically includes: performing a difference operation on the target channel image and the filtered image to obtain an initial difference image; and performing enhancement processing on the initial difference image to obtain a target difference image.
[0008] According to one embodiment of this application, an initial difference image is enhanced to obtain a target difference image. Specifically, this includes: determining the enhancement coefficient of any pixel in the initial difference image, and adjusting the pixel value of each pixel in the initial difference image according to the enhancement coefficient to obtain a preliminary enhanced image; and superimposing the preliminary enhanced image with the initial difference image to obtain the target difference image.
[0009] According to one embodiment of this application, defect detection is performed on a target difference image to obtain a defect detection result of a color image. Specifically, this includes: inputting the target difference image into a defect detection model to perform defect detection on the target difference image; determining at least one target defect feature in the target difference image; and obtaining a defect detection result of the color image based on the target defect feature.
[0010] According to one embodiment of this application, the color image to be detected is a surface image of an industrial product; determining at least one target channel image from the sub-images corresponding to each color channel specifically includes: obtaining the main color feature corresponding to the industrial product; and selecting, based on the main color feature, the sub-image that matches the main color feature from the sub-images corresponding to each color channel as the target channel image.
[0011] According to one embodiment of this application, before performing color channel separation on a color image, the method further includes: filtering the color image to suppress image noise; and / or adjusting the boundaries of the color image based on the grayscale distribution characteristics of the color image.
[0012] Secondly, this application provides an image defect detection device, the device comprising: The conversion module is used to convert the color image to be detected to a color contrast space to obtain the sub-images corresponding to each color channel of the color image in the color contrast space. The filtering module is used to determine the target channel image from the sub-images corresponding to each color channel, and to perform guided filtering on the target channel image to obtain the guided filtered image corresponding to the color image. The determination module is used to determine the target difference image of the color image based on the target channel image and the guided filter image; The detection module is used to perform defect detection on the target difference image and obtain the defect detection results of the color image.
[0013] Thirdly, this application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the image defect detection method as described in the first aspect above.
[0014] Fourthly, this application provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the image defect detection method as described in the first aspect above.
[0015] Fifthly, this application provides a chip including a processor and a communication interface, the communication interface being coupled to the processor, the processor being used to run programs or instructions to implement the image defect detection method as described in the first aspect.
[0016] In a sixth aspect, this application provides a computer program product, including a computer program that, when executed by a processor, implements the image defect detection method as described in the first aspect above.
[0017] The above-described one or more technical solutions in the embodiments of this application have at least one of the following technical effects: By converting the color image to be detected to a color contrast space, sub-images corresponding to each color channel of the color image are obtained in the color contrast space. This effectively separates brightness and color information, allowing subtle color differences to be highlighted in the color contrast channels, providing a data foundation for subsequent image defect detection. Then, the target channel image is determined from the sub-images corresponding to each color channel, and guided filtering is applied to the target channel image to obtain the guided filtered image corresponding to the color image. Utilizing the edge-preserving smoothing properties of guided filtering, edge details between color defects and the background are preserved while effectively suppressing noise. Furthermore, based on the target channel image and the guided filtered image, the target difference image of the color image is determined. The residual information between the target channel image and the filtered image enhances the difference between the color anomaly area and the background, effectively offsetting background interference such as uneven lighting and material gradients. Finally, defect detection is performed on the target difference image to obtain the defect detection results of the color image. This improves the accuracy, robustness, and detection stability of color difference defects, making it particularly suitable for the identification and detection of subtle color defects in industrial appearance inspection.
[0018] Additional aspects and advantages of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description
[0019] The above and / or additional aspects and advantages of this application will become apparent and readily understood from the description of the embodiments taken in conjunction with the following drawings, in which: Figure 1 This is a flowchart illustrating the image defect detection method provided in some embodiments of this application; Figure 2 This is a schematic diagram of LAB color space image decomposition provided in some embodiments of this application; Figure 3 This is a schematic diagram of the guided filtering principle provided in the embodiments of this application; Figure 4 This is a schematic diagram of the initial difference image provided in an embodiment of this application; Figure 5 This is a schematic diagram of the target difference image provided in an embodiment of this application; Figure 6 This is a schematic diagram of the defect detection results provided in an embodiment of this application; Figure 7 This is a schematic diagram of the image defect detection processing flow provided in the embodiments of this application; Figure 8 This is a schematic diagram of the image defect detection device provided in the embodiments of this application; Figure 9 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0020] The technical solutions of the embodiments of this application will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application are within the scope of protection of this application.
[0021] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.
[0022] As industries such as consumer electronics increasingly demand higher product appearance quality, subtle anomalies in hue, tone, and saturation on product surfaces have become a key focus of appearance inspection. These defects exhibit extremely subtle color differences from the normal substrate, often exceeding the direct discernibility of the human eye. Therefore, image enhancement technology is typically employed to effectively amplify these weak color differences in industrial imaging, enabling automated identification and accurate judgment, ultimately ensuring the consistency of product appearance quality.
[0023] In the field of industrial visual inspection, especially in the appearance quality inspection of consumer electronics products, subtle color difference defects on the product surface (often referred to as "weak color defects") typically manifest as extremely slight deviations in hue, tone, or saturation between localized areas and the normal substrate. For example, an almost invisible micro-green spot may appear on a uniform red-orange surface, or a barely perceptible pale yellow area may exist on a blue material. Because these color differences are extremely subtle, often approaching or even falling below the visual resolution limit of the human eye, traditional defect detection methods struggle to meet the high-precision, high-consistency requirements of industrial quality inspection.
[0024] Therefore, industrial vision inspection systems must rely on high-resolution imaging equipment and image processing algorithms to identify and classify subtle color anomalies by acquiring and analyzing color images of product surfaces. However, in actual production environments, the appearance images of industrial products are often affected by various interference factors: on the one hand, uneven imaging lighting, sensor noise, and the material's own texture can mask subtle color difference signals; on the other hand, the product's own color may be quite vibrant or complex, resulting in an extremely low signal-to-noise ratio between the color difference between defects and the background. Under these complex imaging conditions, effectively separating and enhancing color defect features from color images while suppressing background interference and noise becomes crucial for improving the accuracy, robustness, and applicability of defect detection.
[0025] In related technologies, to enhance subtle color differences, color images are typically processed by saturation enhancement, contrast stretching, and frequency domain filtering. However, these methods have limited effectiveness in handling such problems. For example, saturation enhancement has little effect on areas that are already brightly colored or have minimal color differences, and the enhancement factor is limited; while contrast stretching can improve overall contrast, it is difficult to effectively distinguish defect signals from image noise, and may even amplify noise proportionally.
[0026] Against this backdrop, the inventors gradually learned during their in-depth research on high-precision industrial vision inspection scenarios that image information in color images is decomposable. If a color image is converted to a color space that can separate brightness and color information, and local adaptive processing is performed on the channels that reflect the color opposition, then while suppressing background interference in the color image, subtle color differences can be significantly amplified.
[0027] Furthermore, the inventors discovered that even after separating the brightness and color information of the surface image of an industrial product, the resulting color channel image still contains a large amount of non-defect-related interference, including random noise introduced by the imaging sensor and the complex texture of the industrial product material itself. If traditional global or linear filtering methods are applied directly to such images to suppress interference, all image pixel values will be smoothed indiscriminately while filtering out noise, resulting in blurred, abrupt changes in the subtle grayscale values representing defect edges and loss of key defect features.
[0028] To address this issue, guided filtering can be introduced, using the local structural features of the color channel image to determine the intensity and method of smoothing. Specifically, in background areas with uniform texture and gradual changes, guided filtering can apply a strong smoothing effect to the color channel image, effectively suppressing random noise and gradually changing textures. At the boundary between defects and the background, guided filtering can identify and maintain the original grayscale gradient, thus preserving the outline and details of the defects intact.
[0029] Therefore, the color difference features of the final image are characterized by high significance, clear outline and accurate positioning, which provides good input for subsequent appearance defect detection and classification of industrial products, and realizes high reliability detection of weak color difference defects on the surface of industrial products.
[0030] In view of this, this application provides an image defect detection method to solve the problem of low accuracy in detecting subtle color difference defects caused by color information coupling, noise interference, and edge blurring in industrial visual inspection. By converting the color image to a color contrast space to separate brightness and color information, and using guided filtering to smooth the color channels to suppress background noise and preserve the image defect edges, the method highlights the image defect features through differential operation and adaptive enhancement, thereby improving the visibility and detectability of subtle color differences and achieving high-precision and high-robust image defect detection.
[0031] The image defect detection method, image defect detection device, electronic device, and readable storage medium provided in this application will be described in detail below with reference to the accompanying drawings and through specific embodiments and application scenarios.
[0032] The image defect detection method provided in this application can be executed by an electronic device or a functional module or entity within an electronic device capable of implementing the image defect detection method. The electronic device mentioned in this application includes, but is not limited to, a terminal or a server.
[0033] The terminals include, but are not limited to, one or more of various desktop computers, laptops, smartphones, tablets, in-vehicle terminals, or Internet of Things devices.
[0034] A server can be a standalone physical server, a server cluster or distributed system consisting of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, and big data and artificial intelligence platforms.
[0035] The following uses an electronic device as an example to illustrate the image defect detection method provided in the embodiments of this application.
[0036] In the field of image processing technology, the color opposite space (Lightness-AB, LAB) is a color model based on the characteristics of human visual perception. It consists of three independent channels: the lightness channel (L, Lightness), which represents the brightness of the color; the color opposite channel A (green-red color information), whose value changes from negative to positive, corresponding to the change from green to red; and the color opposite channel B (blue-yellow color information), whose value changes from negative to positive, corresponding to the change from blue to yellow. The values of channels A and B are usually in the real number range.
[0037] The LAB color space is characterized by its separation of luminance (L) and color (A, B) information. Under this representation, a color image can be separated into a luminance component reflecting changes in brightness and two color components. The color attributes of each pixel are determined by the values of its L, A, and B components, enabling a more nuanced depiction of continuous color variations.
[0038] In industrial visual inspection, converting the raw images acquired by industrial vision sensors to the LAB color space separates brightness and color information. In the A and B color channels, the color contrast is presented directly and linearly, which helps to highlight subtle color differences. Therefore, the LAB color space can more accurately enhance color defect features, providing a data foundation for subsequent defect identification.
[0039] The color image to be detected in this embodiment can be acquired by various industrial image acquisition devices, including but not limited to color area scan cameras, color line scan cameras, 8-bit color cameras, or 16-bit true color cameras.
[0040] Figure 1 This is a flowchart illustrating the image defect detection method provided in some embodiments of this application. For example... Figure 1 As shown, the image defect detection method includes steps 110 to 140.
[0041] Step 110: Convert the color image to be detected to a color contrast space to obtain the sub-images corresponding to each color channel of the color image in the color contrast space.
[0042] Among them, the color contrast space refers to the LAB color space, and the color image to be detected is in the RGB (Red-Green-Blue, RGB) color space.
[0043] Specifically, the electronic device acquires a color image to be detected in the RGB color space and converts it from the RGB space to the LAB color space using a color space conversion algorithm. After the conversion, the electronic device performs channel separation on the color image in the LAB color space, obtaining three independent single-channel grayscale sub-images, corresponding to the luminance channel L, the color-opposite channel A (green-red color information), and the color-opposite channel B (blue-yellow color information), respectively. This achieves the separation of luminance and color information in the color image, enabling independent processing of the sub-images in different channels in subsequent processing.
[0044] For example, color space conversion algorithms may be nonlinear transformation methods, lookup table-based pre-computation optimization methods, fast conversion methods based on simplified or piecewise linear approximations, or end-to-end mapping methods based on deep learning networks, etc.
[0045] After a color image is converted from the RGB color space to the LAB color space, the electronic device will decompose the color image in the LAB color space into multiple single-channel images based on the multiple channels in the LAB color space. Each single-channel image is a grayscale image, reflecting the distribution of that component in the image.
[0046] For example, Figure 2 This is a schematic diagram of LAB color space image decomposition provided in some embodiments of this application. For example... Figure 2 As shown, for a LAB color space image, an electronic device can decompose it into sub-images corresponding to the L channel, the A channel, and the B channel. Figure 2 Image number 1 is the sub-image corresponding to channel L, image number 2 is the sub-image corresponding to channel A, and image number 3 is the sub-image corresponding to channel B. Figure 2 It can be seen that the sub-image corresponding to the L channel represents the changes in brightness caused by illumination and shadow, while the sub-image corresponding to the A channel represents the grayscale distribution corresponding to the color difference between green and red, and the sub-image corresponding to the B channel represents the grayscale distribution corresponding to the color difference between blue and yellow.
[0047] By separating the brightness and color opposing channels, electronic devices can differentiate the illumination variation characteristics of the L channel and the chromaticity opposing characteristics of the A and B channels, effectively avoiding image defect detection interference caused by global enhancement of color images.
[0048] Step 120: Determine the target channel image from the sub-images corresponding to each color channel, and perform guided filtering on the target channel image to obtain the guided filtered image corresponding to the color image.
[0049] Guided filtering refers to guided image filtering, which is an edge-preserving filtering technique based on a local linear model. It uses the content of a guide image to constrain the filter output, thereby preserving the defective edge structure in the image while smoothing out image noise and background.
[0050] In some implementations, the electronic device selects one of the sub-images corresponding to channel A and channel B as the target channel image. The electronic device uses the target channel image itself as the guide image and applies a guided filtering algorithm to apply strong smoothing to the background area of the color image with uniform texture to suppress noise, while maintaining the original gray-level gradient at the defect edge by fitting coefficients, thus obtaining the guided filtered image corresponding to the color image.
[0051] For example, an electronic device can select the sub-image corresponding to channel A as the target channel image from the sub-images corresponding to channel A and the sub-images corresponding to channel B, or it can select the sub-image corresponding to channel B as the target channel image from the sub-images corresponding to channel A and the sub-images corresponding to channel B.
[0052] In other implementations, instead of selecting a single channel from channels A and B, the electronic device simultaneously determines the sub-images corresponding to both channels A and B as the target channel image. Subsequently, the electronic device performs independent guided filtering processing on the sub-images corresponding to channels A and B, respectively.
[0053] During this process, the electronic device performs guided filtering operations on the sub-images corresponding to channel A and channel B respectively, resulting in two outputs: the guided filtered image corresponding to channel A and the guided filtered image corresponding to channel B.
[0054] In order to use the guided filter image corresponding to channel A and the guided filter image corresponding to channel B in subsequent steps, the electronic device merges the two guided filter images into a single guided filter image, which serves as the guided filter image corresponding to the color image.
[0055] For example, the fusion methods include, but are not limited to, pixel-level weighted averaging, taking the maximum value of the corresponding pixel, or fusion methods based on neural networks.
[0056] By simultaneously processing two contrasting color channels, A and B, subtle color difference information between channels A and B can be obtained concurrently. For defects with unknown or complex color shift directions, this implementation method avoids missed defects due to single-channel selection bias, thereby further improving the versatility of subsequent defect detection.
[0057] It's important to note that different channels have different meanings and the locations where defects appear. The L channel primarily reflects the brightness and darkness of an image, and is greatly affected by lighting conditions, surface undulations, and shadows. Slight color difference defects typically have a very weak response in the brightness channel, sometimes even completely masked by brightness variations. The A and B channels, on the other hand, encode hue information. In industrial visual inspection, the essence of slight color difference defects is a minor shift in hue in a localized area. This shift directly manifests as an abnormal local grayscale value in the corresponding A or B channel. Therefore, color defects primarily exist in the A or B channels.
[0058] Furthermore, guided filtering needs to suppress background noise and texture in the channel while preserving edges caused by color differences. Applying guided filtering to the L channel can suppress luminance noise to some extent, but it is also highly likely to blur luminance edges caused by material variations, slight bumps, or lighting gradients—edges that are not helpful for color defect detection. Applying guided filtering to the A or B channels can smooth out non-defect backgrounds composed of noise and slow color gradients, while preserving color edges caused by true hue abrupt changes (i.e., defects).
[0059] Therefore, guided filtering does not require guided filtering on the L channel. Instead, guided filtering is performed on either the A or B channel. This allows the edge-preserving smoothing properties of guided filtering to be applied to separate the color background from the color defects, which is crucial for subsequent image defect detection.
[0060] Step 130: Determine the target difference image of the color image based on the target channel image and the guided filter image.
[0061] The target difference image refers to the output image used to characterize defect features, obtained by processing the target channel image and the guided filter image using a preset method.
[0062] In step 120, the electronic device obtains the target channel image and the guided filter image. After that, the electronic device obtains the target difference image through a preset processing method.
[0063] For example, the preset processing method may be one or more of the following: differential operation processing, image fusion processing, or feature extraction and enhancement processing.
[0064] Among them, differential operation processing refers to calculating the pixel-by-pixel algebraic difference between the target channel image and the guided filter image in order to directly extract the residual information after background smoothing.
[0065] Image fusion processing refers to combining the pixel information of the target channel image with that of the guided filter image according to preset weights or fusion rules.
[0066] Feature extraction and enhancement refers to the process of constructing or enhancing a feature map that reflects color defects in a color image by analyzing the differences in local features (such as gradients and textures) between the target channel image and the guided filter image.
[0067] For example, in some implementations, the electronic device can perform differential processing on the target channel image and the guided filter image, and use the resulting image after differential processing as the target difference image.
[0068] In other embodiments, the electronic device can perform image fusion processing on the target channel image and the guided filter image, and use the resulting fusion image as the target difference image.
[0069] In some other implementations, the electronic device can perform feature extraction and enhancement processing on the target channel image and the guided filter image, and use the feature map of the color defect as the target difference image.
[0070] By processing the target channel image and the guided filter image, color defects in the image can be effectively identified from the differences or correlations between the two images, providing a foundation for subsequent defect identification.
[0071] Step 140: Perform defect detection on the target difference image to obtain the defect detection results of the color image.
[0072] Defect detection refers to the process of identifying and locating areas in an image that do not meet preset quality standards using algorithms.
[0073] For example, a defect detection algorithm may be an image segmentation model or an object detection model, etc.
[0074] Among them, the image segmentation model can be, for example, a U-Net, which is suitable for identifying color defects and extracting contours in an image, and outputting classification results with the same size as the input image.
[0075] Object detection models can be, for example, the YOLO (You Only Look Once, a detection model) series or region convolutional neural networks, which are suitable for locating color defects in images and providing their categories and bounding boxes.
[0076] Specifically, the target difference image of the electronic device is input into a pre-trained defect detection model, and the defect detection result is output by analyzing the defect features in the target difference image.
[0077] For example, the defect detection result may be one or more of the following: defect location information (such as bounding box coordinates or pixel-level segmentation mask), defect category label (such as scratch, stain, etc.), and corresponding confidence score.
[0078] Based on the above defect detection results, electronic devices can further generate inspection reports on industrial products or trigger corresponding execution operations, thereby completing the detection of slight color difference defects on the surface of industrial products.
[0079] According to the image defect detection method provided in this application embodiment, by converting the color image to be detected to a color contrast space, sub-images corresponding to each color channel of the color image in the color contrast space are obtained, effectively separating brightness information and color information, so that weak color differences are highlighted in the color contrast channels, providing a data foundation for subsequent image defect detection; then, the target channel image is determined from the sub-images corresponding to each color channel, and guided filtering is performed on the target channel image to obtain the guided filtered image corresponding to the color image. Utilizing the edge-preserving smoothing characteristics of guided filtering, edge details between color defects and the background are preserved while effectively suppressing noise; furthermore, the target difference image of the color image is determined based on the target channel image and the guided filtered image. The residual information between the target channel image and the filtered image enhances the difference between the color abnormal area and the background, effectively offsetting background interference such as uneven lighting and material gradation; finally, defect detection is performed on the target difference image to obtain the defect detection result of the color image, improving the recognition accuracy, robustness and detection stability of color difference defects, and is particularly suitable for the recognition and detection of weak color defects in industrial appearance inspection.
[0080] In some embodiments, the pixel values of each channel of the color image to be detected can be normalized in the RGB color space first, and the normalized pixel values can be centered to convert the color image to be detected into a color contrast space.
[0081] For example, taking the case where each color channel of each pixel in the color image to be detected uses 8 binary bits to store its intensity value, the pixel value of each channel in the color image to be detected is normalized to the range of [0,1], as shown in the following formula: (1) in, , and These represent the normalized pixel values of the R, G, and B color channels in the color image to be detected, respectively. , and These represent the pixel values of the R, G, and B color channels in the color image to be detected, respectively. This is a set offset constant, for example, it can be set to 5, used to compensate for the black level of the imaging system or to make specific numerical adjustments. For an 8-bit image, its pixel value ranges from 0 to 255, that is, 255 is the maximum pixel value of an 8-bit image (for each color channel), and 256 is a parameter related to the offset. This is used to ensure that the mapping result remains stable within the target range.
[0082] After that, the normalized , and To convert to standard values in the LAB color space, this conversion process can be achieved through the following operations: (2) in, The component representing the calculated luminance channel is obtained by simply adding and scaling the values of the three color channels.
[0083] and Representing two opposing color components, by using , and By assigning different weights and combining them, color difference information in an image can be extracted.
[0084] It should be noted that, Composition of components To enhance the blue channel and introduce the mixed color characteristics of the color difference between red and green, It partially captures the trend of the red-green color contrast, while This enhances the influence of blue information.
[0085] Composition of components This can be understood as enhancing the green channel and introducing another mixed color feature by introducing the color difference between red and blue. It enhanced the green color, and This partially weakens the influence of red and blue.
[0086] also, and For normalization coefficients, The channel, due to The sum of these three pixel values in the range [0,1) is close to 3. Dividing the result by the maximum pixel value of the 8-bit image maps the result to the corresponding numerical range.
[0087] for and The channel, with a denominator of 510 (twice 255), is for control. and The output range of the component is such that it is consistent with... Channel component coordination prevents numerical overflow or excessive values.
[0088] In the above embodiments, by converting the image from RGB space to LAB color contrast space and separating the L channel from the A and B channels, the subsequent image processing can focus on subtle color differences.
[0089] In the process of smoothing and filtering single-channel images to suppress noise, traditional methods such as mean filtering and Gaussian filtering, while removing noise, indiscriminately smooth all high-frequency components in the image, resulting in the blurring or loss of edge information representing the boundary between defects and the background. This edge blurring severely weakens the saliency of defect features, directly affecting the effectiveness of subsequent difference operations and the final accuracy of defect detection.
[0090] Based on this, in some embodiments, guided filtering is performed on the target channel image to obtain a guided filtered image corresponding to the color image. Specifically, this includes: defining multiple local windows on the target channel image, establishing a linear model between the pixel values of the target channel image and the output pixel values within each of the multiple local windows; determining the linear parameters of each local window based on the linear model, and obtaining the output pixel values corresponding to each local window based on the linear parameters; and integrating the output pixel values corresponding to each local window to obtain the guided filtered image.
[0091] Figure 3 This is a schematic diagram of the guided filtering principle provided in an embodiment of this application. For example... Figure 3 As shown, the guided filtering process involves two input images and one output image, where the two inputs are the images to be filtered. And using the target channel image as the guide image. , Images used to guide the filtering process and provide structural information.
[0092] Specifically, the image to be filtered And using the target channel image as the guide image The images are the same, i.e., the target channel image. The image obtained after filtering is the output image. .
[0093] A guided filter can be understood as a filter based on a guided image. The process of weighting and averaging the contents. Its overall mathematical expression can be written as: (3) in, Indicates pixel index, The above summation is usually performed on a certain pixel scale. Performed within a local window centered on the user. It is the weight kernel of the filter, which is related to the guiding image. The relevant weighted average weights do not directly depend on the original image. .
[0094] In pixels local window centered Internal output image pixel values With guide map pixel values The linear relationship between them is: (4) in, This indicates the guide image (i.e., the target channel image) in the window. The first grayscale value of each pixel. The output image to be obtained (i.e., the guided filter image) is displayed in the window. The first corresponding position inside grayscale value of each pixel. and To apply only to the window A pair of linear coefficients (i.e., linear parameters) within a window; different windows have different coefficient pairs.
[0095] For example, a window centered on the first pixel. The parameters are , A window centered on the second pixel. The parameters are , .
[0096] The gradient change of the output image is linearly proportional to the gradient change of the guide image. With guide image The gradient relationship within the local window is as follows: (5) in, This represents the gradient.
[0097] Assuming in the guiding image The image contains a smooth region A and an edge region B, with the gradient of region B being four times that of region A. After a linear transformation, the output image... The gradients corresponding to regions A and B will be transformed into the gradients of the guiding graph. Although the absolute gradient value has changed, the gradient in region B is still four times that in region A, and the relative gradient relationships (i.e., structural information) between different regions in the same image have not been distorted. In other words, the guiding image... Its own gradient distribution guides the filtering process to determine which regions should be smoothed and which edge regions should be preserved.
[0098] To determine each window Optimal parameters within and To output the image Try to fit the original input image as closely as possible To simultaneously satisfy the aforementioned linear model, the least squares method is typically used for solving. By minimizing the difference between the linear model output within the window and the original input, the parameters can be derived. and The calculation expression for is given. According to the least squares method, the parameters can be expressed in the following form: (6) (7) in, and It is only composed of the guide image In the window The coefficients are determined by the data within the plot. In the actual standard derivation, these coefficients are specifically expressed as functions of the local mean and variance of the guide plot, as well as the local mean of the original plot.
[0099] Finally, due to each pixel in the image Typically, the pixel is covered by multiple overlapping local windows, so each pixel receives multiple temporary values calculated based on different window linear models. Ultimately, the output value of that pixel... A complete and smooth guided filter image is generated by integrating the output values of all windows containing it (e.g., by averaging). .
[0100] In some implementations, the output image after guided filtering smooths out scattered noise points, slow texture changes, and uneven background grayscale fluctuations. Furthermore, the boundary contours between the defect edges and the surrounding background are not blurred in the processed image, and key morphological features such as the shape and size of the defect area are preserved, making the defect features more prominent relative to background interference. Therefore, guided filtering can distinguish between noise and real defect edges in an image, resulting in a guided-filtered image that suppresses background interference while fully preserving key defect information.
[0101] In the above embodiments, guided filtering can accurately distinguish between defect areas and edge areas in color images, maximize the cancellation of background interference from defects, and highlight the edges of defects without making specific noise distribution assumptions about the color image, so that image defect detection can better adapt to the complex and ever-changing imaging conditions in industrial sites.
[0102] For subtle color differences in images, the corresponding grayscale differences may be very small, resulting in low visual contrast and making them difficult for human eyes to observe or for machines to directly recognize. Therefore, in some embodiments, a target difference image for the color image is determined based on the target channel image and the guided filter image. Specifically, this includes: performing a difference operation on the target channel image and the guided filter image to obtain an initial difference image; and performing enhancement processing on the initial difference image to obtain the target difference image.
[0103] Among them, enhancement processing refers to an image processing method that improves the visual or quantitative contrast between the defect feature region and the background region in an image without significantly amplifying noise, thereby making the defect feature easier to observe or detect by subsequent algorithms.
[0104] For example, enhancement processing may be one or more of the following: contrast stretching, gamma correction, adaptive gain adjustment, or histogram equalization.
[0105] Specifically, the electronic device first performs a pixel-by-pixel algebraic subtraction between the target channel image and the guided filter image. For each pixel in the target channel image and the guided filter image, the grayscale difference is calculated to obtain the initial difference image.
[0106] Since the guided filter image has undergone edge-preserving smoothing and is similar to the background information of the target channel image, the background portion is largely canceled out during the difference operation, and the pixel values of the background portion approach zero or a very small constant. Meanwhile, the defect edge information intentionally preserved in the guided filtering process cannot be canceled out because the edges at the corresponding positions in the guided filter image are smoothed. These remain as non-zero residuals (which can be positive or negative) that are extracted and constitute the main features in the initial difference image.
[0107] Figure 4 This is a schematic diagram of the initial difference image provided in an embodiment of this application. For example... Figure 4As shown, the initial difference image obtained after performing a difference operation between the target channel image and the guided filter image shows a uniform neutral grayscale background because the pixel values of the guided filter image and the target channel image are very close in the background. However, the white rectangular area indicated by the white arrow in the figure shows a local grayscale anomaly. This is because there is a slight color difference defect in the original image. Since the guided filtering process preserves its edge information, there is a significant pixel value difference between the target channel image and the guided filter image at this location.
[0108] Following this, the electronic device enhances the initial difference image to obtain the final target difference image. This is because the initial difference image may lack contrast or contain residual image noise. Therefore, further enhancement processing is required.
[0109] In the above embodiments, by performing differential operations and enhancement processing on the target channel image and the guided filter image respectively, the difference pixel values are initially separated from the complex background. Subsequently, the difference pixel values are optimized through enhancement processing, which effectively improves the identifiability of defect features in the color image and maximizes the enhancement of pixels related to defects. This provides high-quality input for subsequent defect detection models.
[0110] In some embodiments, enhancing the initial difference image to obtain the target difference image specifically includes: determining the enhancement coefficient of any pixel in the initial difference image, and adjusting the pixel value of each pixel in the initial difference image according to the enhancement coefficient to obtain a preliminary enhanced image; and superimposing the preliminary enhanced image with the initial difference image to obtain the target difference image.
[0111] Specifically, the electronic device first iterates through each pixel in the initial difference image and calculates its corresponding adaptive enhancement coefficient using a preset normal distribution model based on the normalized grayscale value of that pixel. Then, the electronic device adjusts the pixel values of each pixel in the initial difference image according to the enhancement coefficient corresponding to each pixel, multiplies the original grayscale value of each pixel by its corresponding enhancement coefficient to obtain a preliminary enhanced image, and finally superimposes the preliminary enhanced image with the initial difference image to obtain the target difference image.
[0112] For example, the electronic device first calculates an enhancement coefficient for the normalized grayscale value of each pixel in the initial difference image. As shown in the following formula: (8) in, Indicates the initial difference image at pixel position The original grayscale value at the given location has been normalized or linearly mapped to the integer range of [0, 255], where 0 represents pure black (no difference), 255 represents pure white (maximum positive difference), and intermediate values represent different degrees of difference intensity. The standard deviation represents the normal distribution. The larger the value, the flatter the normal curve, resulting in a smoother transition in image enhancement effects. The smaller the value, the steeper the normal curve, and the more concentrated the enhancement effect is around the gray value. This represents the center position (mean) of the normal distribution and defines the target gray value with the strongest enhancement effect. For example, It can be 15, meaning that pixels with a grayscale value close to 15 can obtain the maximum enhancement factor. It is a constant offset. Its function is to make hour, The value is exactly 0, which ensures that no additional enhancement is applied to areas that have reached the maximum difference (brightest), and also makes the enhancement coefficient positive in most grayscale ranges, and smoothly decays to zero in extremely high grayscale areas. This represents the gain factor, used to control the maximum scaling factor of the enhancement factor, i.e., the global scaling factor for the entire enhancement intensity. The larger the value, the stronger the maximum enhancement effect.
[0113] After calculating the enhancement coefficient for each pixel Then, the electronic device generates a preliminary enhanced image based on this coefficient, in which the value of each pixel is... .
[0114] The target difference image is generated using the following formula. : (9) in, This is an initial enhancement of the pixel values at the corresponding locations in the image. Indicates the initial difference image at pixel position The original grayscale value at that location.
[0115] Figure 5 This is a schematic diagram of the target difference image provided in an embodiment of this application. For example... Figure 5 As shown in the image, the white rectangular area indicated by the white arrow corresponds to the area of slight color difference defects. Its grayscale value has been specifically enhanced, resulting in a more pronounced contrast with the background. The enhancement process, while strengthening the defect features, suppresses the enhancement amplitude of the nearly neutral, uniform background area remaining in the initial difference image. Therefore... Figure 5 The background is more uniform, effectively suppressing irrelevant background undulations or residual noise, making the defect features more visually prominent.
[0116] In the above embodiments, by dynamically calculating the enhancement coefficient for each pixel, the defect features in the image are significantly enhanced while the excessive enhancement of noise is effectively suppressed. By superimposing the preliminary enhanced image with the initial difference image, the information loss or distortion that may be caused by a single enhancement transformation is avoided, and weak color difference defects can be effectively handled.
[0117] The core value of obtaining high-quality target difference images lies in providing a reliable basis for defect identification and decision-making. Traditional defect detection methods directly process the original image or the image after simple enhancement. When faced with slight color differences, they are often limited by the low contrast between features and the background and the high noise, resulting in low accuracy and high false alarm rate of the detection model.
[0118] In some embodiments, defect detection is performed on the target difference image to obtain the defect detection result of the color image, specifically including: inputting the target difference image into the defect detection model to perform defect detection on the target difference image; determining at least one target defect feature in the target difference image, and obtaining the defect detection result of the color image based on the target defect feature.
[0119] Among them, target defect features refer to the measurable parameters extracted from the target difference image after analysis by the defect detection model to describe and determine the defect.
[0120] When electronic devices perform defect detection, the target difference image is first input into a pre-trained defect detection model.
[0121] For example, the defect detection model can be a deep learning-based image classification model, object detection model (e.g., YOLO, region convolutional neural network series, etc.), or semantic segmentation model (e.g., U-shaped network, etc.).
[0122] In some implementations, when the defect detection model is a target detection model, the defect detection model performs detection processing on the input target difference image. Since the input image has been processed, the background is uniform and the target features are significantly enhanced, the defect detection model can identify image defects more accurately and easily.
[0123] The target defect features output by the defect detection model include, but are not limited to, one or more of the following: defect location and extent information, defect category information, or defect confidence information.
[0124] For example, the location and extent information of the defect can be, for instance, a bounding box defined by its coordinates in the image.
[0125] Defect category information can indicate the category to which the defect belongs. For example, defect category information can be one or more of the following: scratch, stain, discoloration, dent, or protrusion.
[0126] Confidence information is a score used to represent the degree of confidence of a defect detection model in the defect detection result. The value range is usually between 0 and 1. The higher the value, the greater the likelihood that the model believes that the area is a defect and that the category judgment is correct.
[0127] Finally, the electronic device can generate the final defect detection result based on the extracted target defect features. This can be a simple "pass / fail" decision (e.g., any defect feature area larger than a threshold is considered a failure), or a detailed inspection report listing one or more of the following: the type or location of each defect.
[0128] In other implementations, when the defect detection model is an image segmentation model, the image segmentation model performs pixel-level analysis and classification on the input target difference image. The image segmentation model can distinguish between defects and background and identify different categories of defect regions.
[0129] The target defect features output by the defect image segmentation model are mainly based on the defect segmentation mask it generates. This mask is a matrix of the same size as the input image, where the value of each pixel indicates the type of defect the model classifies at that location (e.g., 0 represents the background, 1 represents a type A defect, and 2 represents a type B defect).
[0130] For example, the target defect features include, but are not limited to, one or more of the following: defect location and extent information, defect category information, or defect confidence information.
[0131] The location and extent of the defect are defined by the connected region (i.e., the segmentation mask) formed by the defect pixels, which can depict the outline and extent of the defect.
[0132] Furthermore, the pixel value of each connected region in the mask can indicate the predefined category to which the defect belongs. For example, a region with a pixel value of 1 is classified as a "scratch", and a region with a pixel value of 2 is classified as a "spot", etc.
[0133] Based on the above segmentation mask, electronic devices can further quantify and extract more specific features, such as the pixel area of the defect (i.e., the defect size), the contour shape description (such as roundness, irregularity), and the average intensity of the defect region.
[0134] Figure 6 This is a schematic diagram of the defect detection results provided in an embodiment of this application. For example... Figure 6 As shown, image 1 is the original color image to be detected, and image 2 is the result of defect detection by the defect detection model. The white rectangular area indicated by the white arrow represents the region where the defect is located. Figure 6As can be seen, in the original color image, the color difference between the defect and the background is extremely weak, and the visual representation of the defect area is not obvious due to the interference of lighting and texture. However, in the defect detection result image, the area corresponding to the defect location in the original image is more prominent. This verifies that the defect feature of the target difference image obtained after preprocessing such as LAB spatial separation, guided filtering, and differential normal enhancement has been sufficiently enhanced, and the defect detection model can accurately locate and identify defects with weak color differences.
[0135] In the above embodiments, by inputting the target difference image into the defect detection model, a technical closed loop from image defect enhancement processing to detection is realized, which improves the accuracy and reliability of detecting weak color difference defects, reduces the probability of misjudging noise as defects or missing weak defects, and thus improves the accuracy of image defect detection.
[0136] In complex industrial inspection scenarios, subtle color defects on the surface of industrial products may present as ambiguous or complex hue shifts. For example, the surface of industrial products may contain multiple color component variations at the same time, and relying solely on a fixed color channel may lead to the risk of missing more significant defect features in other color channels.
[0137] In some embodiments, the color image to be detected is a surface image of an industrial product; determining at least one target channel image from the sub-images corresponding to each color channel includes: obtaining the main color feature corresponding to the industrial product; and selecting, based on the main color feature, the sub-image that matches the main color feature from the sub-images corresponding to each color channel as the target channel image.
[0138] Among them, the primary color feature refers to the information that can characterize the main color tendency in the surface image of an industrial product.
[0139] The electronic device first acquires the primary color feature corresponding to the current industrial product. For example, the methods for acquiring the primary color feature of the industrial product include, but are not limited to, prior knowledge input or online statistical analysis.
[0140] Among them, prior knowledge input involves the operator setting the main color category of the industrial product before performing defect detection, for example, the main color of the industrial product is red.
[0141] Online statistical analysis refers to the ability of electronic devices to calculate the average value or main distribution of pixels of industrial products in the LAB space from the current image to be inspected. For example, if the average A channel value is significantly positive, the main color feature is reddish; if the average B channel value is significantly positive, the main color feature is yellowish.
[0142] In some implementations, after obtaining the primary color features corresponding to the industrial product, the electronic device performs channel matching and selection based on these features. The matching logic is based on the principle of color contrast. If the primary color features indicate that the product's main body is predominantly red or green, then the sub-image corresponding to channel A is selected as the target channel image, because hue changes in red and green are more sensitive in channel A. If the primary color features indicate that the product's main body is predominantly yellow or blue, then the sub-image corresponding to channel B is selected as the target channel image, because hue changes in yellow and blue are more sensitive in channel B.
[0143] In other implementations, when performing channel selection, the electronic device uses both the sub-image corresponding to channel A and the sub-image corresponding to channel B obtained after LAB color space conversion as the target channel image. The electronic device can then perform guided filtering, differencing, and enhancement operations on the sub-images corresponding to channel A and channel B respectively to obtain two target difference images.
[0144] Following this, the electronic device fuses the two target difference images. For example, the fusion method may be one or more of the following: pixel-level weighted averaging, taking the maximum or minimum value, or feature fusion based on a neural network.
[0145] In the above embodiments, by performing channel matching and selection based on the main color features corresponding to industrial products, the risk of missing color dimension information that may be caused by pre-selecting a single channel is avoided, the ability to characterize unknown and complex defects is enhanced, and the versatility of the image defect detection model is improved.
[0146] Figure 7 This is a schematic diagram of the image defect detection processing flow provided in an embodiment of this application. For example... Figure 7 As shown, after inputting the color image to be detected, it is converted from the RGB color space to the LAB color space to separate luminance and color information. Then, based on color features, key color channel sub-images are selected from the LAB space as the target image, and guided filtering is applied to this target image to smooth the background and suppress noise while preserving defect edges. After this, the difference between the images before and after guided filtering is calculated to obtain an initial difference image, which is then enhanced to obtain a target difference image with significantly improved contrast. Finally, this target difference image is input into the defect detection model for identification and localization, and the final defect detection result is output.
[0147] During industrial image acquisition, due to the inherent characteristics of image acquisition sensors, ambient light fluctuations, or transmission interference, the acquired color images often contain random noise. This noise may be significantly amplified in subsequent color channel separation and differential processing, thereby interfering with the extraction of color defect features from the real image.
[0148] Based on this, in some embodiments, before performing color channel separation on the color image, the color image is further filtered to suppress image noise; and / or the color image is boundary adjusted according to the grayscale distribution characteristics of the color image.
[0149] In some implementations, the electronic device filters the input raw color image.
[0150] For example, filtering processes include, but are not limited to, one or more of Gaussian filtering, mean filtering, median filtering, etc.
[0151] In other implementations, the electronic device performs boundary adjustment on the color image. Specifically, it can first be converted to a grayscale image, and its grayscale histogram distribution can be analyzed. Based on prior knowledge (e.g., the effective target grayscale should be within a specific range), segmentation is performed by setting a threshold to extract the main target region. Morphological operations (such as closing operations) are then used to smooth the region boundaries and fill small holes, ultimately generating a mask that more accurately focuses on the target. Applying this mask to the original color image can crop or mask out irrelevant background areas, thus achieving boundary adjustment.
[0152] For example, background areas with grayscale values in invalid ranges (such as near pure black or pure white) can be removed by using methods such as threshold segmentation, edge detection, or morphological operations. This concentrates the defect detection area to the true target range, improving the robustness and accuracy of subsequent channel statistics and enhancement.
[0153] In some other implementations, the electronic device performs the two operations described above sequentially: first, it filters the color image to suppress noise, and then it adjusts the boundaries of the filtered image. This approach first improves image quality, and then performs precise region localization based on the improved image. The two work together to provide a high-quality input image with lower noise and a clearer target region for subsequent core processing.
[0154] In the above embodiments, the filtering process improves the signal-to-noise ratio of the input image and effectively suppresses random noise that may be amplified in subsequent differential steps, thereby enhancing the purity and reliability of the final enhancement result. The boundary adjustment, by precisely limiting the processing focus to the target area, eliminates the interference of irrelevant background pixels on statistical features (such as the channel grayscale mean), making the enhancement factor and other parameters determined based on these statistical quantities more realistically reflect the characteristics of the target itself, thereby improving the accuracy and robustness of the entire enhancement process.
[0155] The image defect detection method provided in this application can be executed by an image defect detection device. This application uses an image defect detection device executing the image defect detection method as an example to illustrate the image defect detection device provided in this application.
[0156] Figure 8 This is a schematic diagram of the image defect detection device provided in the embodiments of this application. Figure 8 As shown, the image defect detection device includes: a conversion module 801, a filtering module 802, a determination module 803, and a detection module 804.
[0157] Secondly, this application provides an image defect detection device, the device comprising: The conversion module 801 is used to convert the color image to be detected to a color contrast space to obtain the sub-images corresponding to each color channel of the color image in the color contrast space. The filtering module 802 is used to determine the target channel image from the sub-images corresponding to each color channel, and to perform guided filtering processing on the target channel image to obtain the guided filtered image corresponding to the color image; The determination module 803 is used to determine the target difference image of the color image based on the target channel image and the guided filter image; The detection module 804 is used to perform defect detection on the target difference image and obtain the defect detection result of the color image.
[0158] According to the image defect detection device provided in this application embodiment, by converting the color image to be detected to a color contrast space, sub-images corresponding to each color channel of the color image are obtained in the color contrast space. This effectively separates brightness information from color information, making subtle color differences stand out in the color contrast channels, providing a data foundation for subsequent image defect detection. Then, the target channel image is determined from the sub-images corresponding to each color channel, and guided filtering is performed on the target channel image to obtain the guided filtered image corresponding to the color image. Utilizing the edge-preserving smoothing characteristics of guided filtering, edge details between color defects and the background are preserved while effectively suppressing noise. Furthermore, the target difference image of the color image is determined based on the target channel image and the guided filtered image. The residual information between the target channel image and the filtered image enhances the difference between the color abnormal area and the background, effectively offsetting background interference such as uneven lighting and material gradation. Finally, defect detection is performed on the target difference image to obtain the defect detection result of the color image, improving the recognition accuracy, robustness, and detection stability of color difference defects. It is particularly suitable for the recognition and detection of subtle color defects in industrial appearance inspection.
[0159] In some embodiments, the filtering module is further configured to delineate multiple local windows on the target channel image, establish a linear model between the pixel values of the target channel image and the output pixel values within the multiple local windows respectively; determine the linear parameters of each local window based on the linear model, and obtain the output pixel values corresponding to each local window based on the linear parameters; and integrate the output pixel values corresponding to each local window to obtain the guided filtered image.
[0160] In some embodiments, the determining module is further configured to perform a difference operation on the target channel image and the filtered image to obtain an initial difference image; and to perform enhancement processing on the initial difference image to obtain a target difference image.
[0161] In some embodiments, the determining module is further configured to determine the enhancement coefficient of any pixel in the initial difference image, and adjust the pixel value of each pixel in the initial difference image according to the enhancement coefficient to obtain a preliminary enhanced image; and superimpose the preliminary enhanced image with the initial difference image to obtain a target difference image.
[0162] In some embodiments, the detection module is further configured to input the target difference image into the defect detection model, perform defect detection on the target difference image, determine at least one target defect feature in the target difference image, and obtain the defect detection result of the color image based on the target defect feature.
[0163] In some embodiments, the filtering module is further configured to obtain the main color features corresponding to the industrial product; based on the main color features, select the sub-image that matches the main color features from the sub-images corresponding to each color channel as the target channel image.
[0164] In some embodiments, the conversion module is further configured to filter the color image to suppress image noise; and / or adjust the boundaries of the color image according to the grayscale distribution characteristics of the color image.
[0165] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0166] The image defect detection device in this application embodiment can be an electronic device or a component within an electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal or other devices besides a terminal, such as a server.
[0167] The image defect detection device provided in this application embodiment can realize all the processes implemented in the above-described image defect detection method embodiment. To avoid repetition, it will not be described again here.
[0168] In some embodiments, Figure 9 This is a schematic diagram of the structure of the electronic device provided in an embodiment of this application. For example... Figure 9 As shown, this application embodiment also provides an electronic device 900, including a processor 901, a memory 902, and a computer program stored in the memory 902 and executable on the processor 901. When the program is executed by the processor 901, it implements the various processes of the above-described image defect detection method embodiment and achieves the same technical effect. To avoid repetition, it will not be described again here.
[0169] This application provides a non-transitory computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it implements the various processes of the above-described image defect detection method embodiments and achieves the same technical effect. To avoid repetition, it will not be described again here.
[0170] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable media, such as computer read-only memory (ROM), random-access memory (RAM), magnetic disks, or optical disks.
[0171] The computer-readable storage medium may include: read-only memory (ROM), random-access memory (RAM), magnetic disk or optical disk, etc.
[0172] This application provides a computer program product, including a computer program that, when executed by a processor, implements the above-described image defect detection method.
[0173] This application provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement the various processes of the above-described image defect detection method embodiments and achieve the same technical effect. To avoid repetition, it will not be described again here.
[0174] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.
[0175] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.
[0176] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the related technology, can be embodied in the form of a computer software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0177] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.
[0178] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "illustrative embodiment," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0179] Although embodiments of this application have been shown and described, those skilled in the art will understand that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of this application, the scope of which is defined by the claims and their equivalents.
Claims
1. An image defect detection method, characterized in that, include: The color image to be detected is converted to a color contrast space to obtain sub-images corresponding to each color channel of the color image in the color contrast space; The target channel image is determined from the sub-images corresponding to each color channel, and the target channel image is subjected to guided filtering to obtain the guided filtered image corresponding to the color image. The target difference image of the color image is determined based on the target channel image and the guided filter image; Defect detection is performed on the target difference image to obtain the defect detection result of the color image.
2. The image defect detection method according to claim 1, characterized in that, The step of performing guided filtering on the target channel image to obtain the guided filtered image corresponding to the color image includes: Multiple local windows are defined on the target channel image, and a linear model between the pixel values of the target channel image and the output pixel values is established in each of the multiple local windows. The linear parameters of each local window are determined based on the linear model, and the output pixel values corresponding to each local window are obtained based on the linear parameters. The output pixel values corresponding to each local window are integrated to obtain the guided filter image.
3. The image defect detection method according to claim 1, characterized in that, Determining the target difference image of the color image based on the target channel image and the guided filter image includes: Perform a difference operation on the target channel image and the guided filter image to obtain an initial difference image; The initial difference image is enhanced to obtain the target difference image.
4. The image defect detection method according to claim 3, characterized in that, The enhancement process of the initial difference image to obtain the target difference image includes: Determine the enhancement coefficient of any pixel in the initial difference image, and adjust the pixel value of each pixel in the initial difference image according to the enhancement coefficient to obtain a preliminary enhanced image; The preliminary enhanced image is superimposed on the initial difference image to obtain the target difference image.
5. The image defect detection method according to claim 1, characterized in that, The step of performing defect detection on the target difference image to obtain the defect detection result of the color image includes: The target difference image is input into the defect detection model to perform defect detection on the target difference image; Determine at least one target defect feature in the target difference image, and obtain the defect detection result of the color image based on the target defect feature.
6. The image defect detection method according to claim 1, characterized in that, The color image to be detected is a surface image of an industrial product; determining at least one target channel image from the sub-images corresponding to each color channel includes: Obtain the main color feature corresponding to the industrial product; Based on the primary color feature, the sub-image that matches the primary color feature is selected from the sub-images corresponding to each color channel as the target channel image.
7. The image defect detection method according to claim 1, characterized in that, Before performing color channel separation on the color image, the method further includes: The color image is filtered to suppress image noise; and / or Based on the grayscale distribution characteristics of the color image, the boundary of the color image is adjusted.
8. An image defect detection device, characterized in that, include: The conversion module is used to convert the color image to be detected to a color contrast space to obtain sub-images corresponding to each color channel of the color image in the color contrast space. The filtering module is used to determine the target channel image from the sub-images corresponding to each color channel, and to perform guided filtering processing on the target channel image to obtain the guided filtered image corresponding to the color image; The determination module is used to determine the target difference image of the color image based on the target channel image and the guided filter image; The detection module is used to perform defect detection on the target difference image to obtain the defect detection result of the color image.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the image defect detection method as described in any one of claims 1-7.
10. A non-transitory 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 image defect detection method as described in any one of claims 1-7.