A method for detecting the color compliance of a certificate photo clothes
By combining portrait analysis and refined color feature analysis with illumination normalization and anti-aliasing, an extended candidate region is adaptively generated to accurately extract the clothing mask image in ID photos. This solves the problem of misjudgment in clothing color detection in complex environments and achieves high accuracy and robustness in detection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- GUANGZHOU PIXEL SOLUTIONS CO LTD
- Filing Date
- 2025-09-03
- Publication Date
- 2026-05-05
AI Technical Summary
Existing technologies struggle to accurately detect whether the color of a user's clothing meets the light-colored requirement in ID photo selfie environments. The false judgment rate is high, especially in complex lighting and areas with similar skin tones, affecting the reliability of ID photo compliance detection.
By analyzing human portraits and refining color features, combined with illumination normalization, automatic white balance, and optical anti-aliasing, an extended candidate region is adaptively generated to accurately extract clothing mask images. Color features are then calculated in the CIE-Lab space and fused to determine the compliance of clothing colors in ID photos.
It improves the accuracy and robustness of clothing color detection in ID photos under complex environments, reduces lighting and background interference, and ensures the reliability and accuracy of detection.
Smart Images

Figure CN121170844B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, and specifically to a method for detecting the compliance of clothing color in ID photos. Background Technology
[0002] As an important carrier of personal legal identity, the quality of ID photos directly affects the anti-counterfeiting performance and verification efficiency of the documents. ID photos must meet strict imaging specifications, some of which explicitly stipulate requirements for clothing color: light-colored clothing (such as white, light pink, light blue, etc.) is not allowed.
[0003] With the rapid development of technology, mobile phone apps for taking ID photos have emerged. Users take photos of their faces and upload them to a server, which automatically determines whether the ID photo meets the standards. Existing technology attempts to solve this problem using HSV color space threshold analysis. This method uses facial key points and color threshold information to extract the percentage of pixels in the global clothing area that exceed a specific threshold to determine whether the clothing is light-colored. However, for some users, the neck and collar areas have similar skin tones, leading to edge segmentation failure and statistical errors. Furthermore, changes in the lighting environment can cause shifts in clothing color information values. This traditional threshold method has a high false positive rate under complex lighting and skin tone interference, resulting in reduced reliability of ID photo compliance detection results. Summary of the Invention
[0004] The purpose of this invention is to provide a method for detecting the compliance of clothing color in ID photos. By combining the results of portrait analysis with detailed color feature analysis, the accuracy and robustness of light-colored clothing detection are improved.
[0005] To achieve the above objectives, the present invention provides the following technical solution:
[0006] In a first aspect, the present invention provides a method for detecting the compliance of clothing color in ID photos, comprising the following steps:
[0007] A portrait parsing operation is performed on the input user image to obtain a portrait parsing mask; a face detection operation is performed on the user image to obtain a face detection bounding box; an extended candidate region is generated based on the face detection bounding box; the user image and the portrait parsing mask are cropped based on the extended candidate region to obtain a local image and a local portrait parsing mask;
[0008] Based on the local portrait parsing mask image, the clothing area is located to obtain an initial clothing mask image; an erosion operation is performed on the initial clothing mask image to obtain a precise clothing mask image; a partitioning operation is performed on the precise clothing mask image to obtain the clothing interior mask and the clothing edge mask; a specific region exclusion operation is performed on the precise clothing mask image.
[0009] The local image is sequentially subjected to illumination normalization, automatic white balance, and optical anti-aliasing to obtain a local image with normalized illumination and chromaticity.
[0010] If the proportion of non-zero pixels in the precise clothing mask image does not meet the preset conditions, then based on the local image with normalized illumination and chromaticity, the clothing interior mask, and the clothing edge mask, the color features of the clothing edge region and the interior region are calculated; the color features are processed according to the fusion strategy to obtain the final color feature vector, which is used to determine whether the clothing color in the ID photo is compliant.
[0011] In one possible implementation, the step of generating the extended candidate region includes:
[0012] Calculate the width and height of the face based on the face detection bounding box;
[0013] In the horizontal direction, the maximum expandable range of the user image in the face detection box is calculated, and the smaller value between half the face width and the boundary distance is taken as the actual expandable width.
[0014] In the vertical direction, the face detection box is expanded upward by a preset proportion of the face height and downward by another preset proportion of the face height, ensuring that the expansion does not exceed the image boundary, thus obtaining the expanded candidate region.
[0015] In one possible implementation, the step of partitioning the precise clothing mask image includes:
[0016] The precise clothing mask image is subjected to erosion and Gaussian blur operations to obtain a temporary mask image;
[0017] Define the area with a preset pixel value in the temporary mask image as the inner area to obtain the inner mask of the clothing;
[0018] The inner mask of the clothing is subtracted from the precise clothing mask image to obtain the outer mask of the clothing.
[0019] In one possible implementation, the steps of performing the exclusion of a specific region operation include:
[0020] An exclusion operation is performed on the clothing portion extending below the face detection frame to reduce the interference of the inner layer color on the overall clothing color analysis.
[0021] In one possible implementation, the steps of performing the illumination normalization operation include:
[0022] Perform Retinex-CLAHE joint enhancement operation to convert the local image from BGR to CIE-Lab space and separate the luminance channel; perform contrast-limited adaptive histogram equalization operation on the luminance channel; merge the processed luminance channel with the original other channels and convert it back to BGR space;
[0023] Perform a global Gamma correction operation on the result of the Retinex-CLAHE joint enhancement operation;
[0024] The result of the global Gamma correction operation is subjected to a local exponential mapping operation. The luminance channel is extracted as a guide map. The adaptive radius is determined according to the preset ratio of the maximum side length of the image. A fast guided filtering operation is performed to obtain a luminance mask. A local gain factor is constructed using an exponential function. High gain is applied to the shadow area and low gain is applied to the highlight area. The new luminance is backmapped to the three channels according to a preset ratio while keeping the chromaticity unchanged.
[0025] In one possible implementation, the steps for performing the automatic white balance operation include:
[0026] Calculate the global mean of each channel in the BGR color space for the local image after illumination normalization, and calculate the average gray value.
[0027] A scaling factor is applied to each channel, which is the ratio of the average gray value to the global mean of the corresponding channel;
[0028] Perform a truncation operation on the three-channel floating-point pixel values after channel gain correction, forcing values less than the preset lower limit to the preset lower limit and values greater than the preset upper limit to the preset upper limit; convert the result into an unsigned integer of a preset number of bits.
[0029] In one possible implementation, the steps for performing the optical anti-aliasing operation include:
[0030] The image is blurred using a Gaussian kernel of a preset size to suppress potential ringing artifacts and quantization noise.
[0031] In one possible implementation, the step of calculating the color feature includes:
[0032] The local image with normalized illumination and chromaticity is converted from BGR space to CIE-Lab space;
[0033] Based on the internal mask and the edge mask of the clothing, calculate the average brightness, green-red value, and blue-yellow value of the edge region and the internal region of the clothing in the CIE-Lab space;
[0034] The color feature is obtained by combining the HSV primary color of the edge area of the clothing.
[0035] In one possible implementation, the fusion strategy includes:
[0036] If the average brightness of the edge area of the clothing is less than a preset brightness threshold and the brightness value in the HSV space is less than a preset brightness threshold, then the average brightness of the edge area of the clothing will be used as the final average brightness.
[0037] In other cases, the average brightness of the edge area of the clothing is linearly fused with equal weights to the average brightness of the inner area to obtain the final average brightness.
[0038] For the green-red and blue-yellow values, the corresponding values of the edge area and the inner area of the clothing are linearly fused with equal weights to obtain the final green-red and blue-yellow values.
[0039] One possible implementation also includes:
[0040] If the initial clothing mask image does not contain any non-zero pixels, it is determined that there is no clothing area or that it is completely occluded by other foreground elements, and an empty color feature vector is returned.
[0041] If the proportion of non-zero pixels in the precise clothing mask image meets the preset conditions, it is determined that the clothing area is completely occluded by the edge of the document, the arm, or other foreground, and an empty color feature vector is returned. The empty color feature vector is used to indicate that the conditions for clothing color compliance detection are not met.
[0042] In one possible implementation, the global Gamma correction operation includes:
[0043] Global average brightness data is obtained by calculating the global average brightness of the image data obtained from the Retinex-CLAHE joint enhancement operation.
[0044] The Gamma correction coefficient is determined based on the global average brightness data.
[0045] The pixel values in the image data obtained by the Retinex-CLAHE joint enhancement operation are subjected to exponentiation, and the Gamma correction coefficient is used in the operation process to obtain Gamma-corrected image data.
[0046] In one possible implementation, calculating the HSV primary color includes:
[0047] The local image data with normalized illumination and chromaticity is subjected to color space conversion processing to convert it from BGR space to HSV space to obtain HSV space image data;
[0048] The HSV spatial image data and the clothing edge mask are processed for region extraction. Based on the region located by the clothing edge mask, the HSV value data of the corresponding region is extracted from the HSV spatial image data.
[0049] The extracted HSV value data is quantized, and the number of pixels in each quantization interval is counted to obtain an HSV distribution histogram.
[0050] The histogram is subjected to main peak detection to select the quantization interval with the highest number of pixels, and the center value of the interval is determined as the HSV main color.
[0051] In a second aspect, the present invention also provides an electronic device, including a processor and a memory;
[0052] The memory is used to store programs;
[0053] The processor executes the program to implement the method described above.
[0054] Thirdly, the present invention also provides a computer-readable storage medium storing a program that is executed by a processor to implement the methods described above.
[0055] Fourthly, the present invention also provides a computer program product or computer program comprising computer instructions stored in a computer-readable storage medium. A processor of a computer device can read the computer instructions from the computer-readable storage medium and execute the computer instructions, causing the computer device to perform the aforementioned method.
[0056] Compared with the prior art, the advantages of this invention are as follows:
[0057] This invention aims to improve the ability to detect compliance of clothing colors in ID photos. It comprehensively utilizes portrait analysis and color feature analysis technologies and optimizes the detection process through multiple steps.
[0058] In the region processing stage, face detection is first performed on the input user image to obtain face detection bounding boxes. Then, based on the width and height of the face detection bounding boxes, expanded candidate regions are adaptively generated. In the horizontal direction, the maximum expandable range of the image within the horizontal direction of the face detection bounding box is calculated, and the smaller value between half the face width and the boundary distance is selected as the actual expanded width. In the vertical direction, the face detection bounding box is expanded upward by a preset proportion of the face height and downward by another preset proportion of the face height, while strictly ensuring that the expanded range does not exceed the image boundary. Through this adaptive cropping, the interference of non-clothing areas such as background and arms on subsequent detection is effectively reduced.
[0059] After cropping, a robust lighting preprocessing operation is performed on the resulting local area. This operation includes lighting normalization, automatic white balance, and optical anti-aliasing. Lighting normalization compensates for lighting distortions of different scales and physical causes through a multi-level cascaded architecture. Automatic white balance eliminates color shifts caused by light source color temperature deviations. Optical anti-aliasing suppresses artifacts and noise that may occur during the operation, ensuring that subsequent color analysis is not affected by ambient light, shadows, or other factors.
[0060] Subsequently, image analysis technology is used to extract the clothing region. First, the clothing region is initially located based on a local image analysis mask, resulting in an initial clothing mask. Then, an erosion operation is performed on the initial clothing mask to remove background pixels, yielding a precise clothing mask. Based on this, the clothing region is divided into edge and interior regions with different weights: an erosion and Gaussian blur operation is performed on the precise clothing mask to obtain a temporary mask. Regions in the temporary mask whose pixel values meet preset conditions are defined as interior regions. The interior region mask is obtained by subtracting the interior region mask from the precise clothing mask. Subsequent color feature analysis adjusts the weights based on region characteristics; for example, if the edge region exhibits a darker tone, edge region features are prioritized as the judgment criterion.
[0061] Finally, based on the preprocessed local image and the predefined clothing edge and internal region masks, the brightness, chromaticity, and other features of the two regions in a specific color space are calculated. These features are then analyzed comprehensively using a fusion strategy to ultimately evaluate the depth of the clothing color in the ID photo.
[0062] This invention can solve the problem of misjudgment that may occur when traditional methods for detecting the compliance of clothing color in ID photos are affected by the natural environment or other interfering objects during shooting, and ensure that the depth of clothing color can still be accurately detected under any ambient light, shadow and complex background. Attached Figure Description
[0063] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0064] Figure 1 This is a flowchart illustrating the method for detecting the compliance of clothing color in ID photos according to an embodiment of the present invention.
[0065] Figure 2 This is another flowchart illustrating the method for detecting the compliance of clothing color in ID photos according to an embodiment of the present invention.
[0066] Figure 3This is a visualization of the local portrait parsing mask generated in an embodiment of the present invention;
[0067] Figure 4 This is a visualization of the clothing mask image after performing a partitioning operation and excluding specific areas in an embodiment of the present invention;
[0068] Figure 5 This is a flowchart illustrating the joint normalization preprocessing operation of illumination and chromaticity in an embodiment of the present invention. Detailed Implementation
[0069] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0070] Example:
[0071] It should be noted that the terms "comprising" and "having" and any variations thereof in the embodiments of the present invention are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not necessarily limited to those steps or units that are explicitly listed, but may include other steps or units that are not explicitly listed or that are inherent to such processes, methods, products, or devices.
[0072] Figure 1 This is a flowchart illustrating the method for detecting the compliance of clothing color in ID photos according to an embodiment of the present invention; see also Figure 1 This invention provides a method for detecting the compliance of clothing color in ID photos, including the following steps:
[0073] Step 1: Perform portrait parsing on the input user image to obtain a portrait parsing mask; perform face detection on the user image to obtain a face detection bounding box; generate an extended candidate region based on the face detection bounding box; crop the user image and the portrait parsing mask based on the extended candidate region to obtain a local image and a local portrait parsing mask.
[0074] In specific execution, the steps for generating the extended candidate region include: calculating the face width and height based on the face detection box; in the horizontal direction, calculating the maximum expandable range of the user image in the horizontal direction of the face detection box, and taking the smaller value between half the face width and the boundary distance as the actual expanded width; in the vertical direction, expanding the face detection box upward by a preset proportion of face height and downward by another preset proportion of face height, while ensuring that the expansion does not exceed the image boundary, to obtain the extended candidate region.
[0075] Step 2: Locate the clothing area based on the local portrait parsing mask to obtain an initial clothing mask; perform an erosion operation on the initial clothing mask to obtain a precise clothing mask; perform a partitioning operation on the precise clothing mask to obtain the clothing interior mask and the clothing edge mask; perform a specific region exclusion operation on the precise clothing mask.
[0076] In specific execution, the steps of partitioning the precise clothing mask image include: performing erosion and Gaussian blur operations on the precise clothing mask image to obtain a temporary mask image; defining the region with a preset pixel value in the temporary mask image as an internal region to obtain the clothing internal mask; and subtracting the clothing internal mask from the precise clothing mask image to obtain the clothing edge mask.
[0077] Furthermore, the step of performing the exclusion operation for specific areas includes: performing an exclusion operation on the clothing portion extending below the face detection frame to reduce the interference of the inner layer color on the overall clothing color analysis.
[0078] Step 3: Perform illumination normalization, automatic white balance, and optical anti-aliasing operations sequentially on the local image to obtain a local image with normalized illumination and color.
[0079] In specific execution, the steps of performing the illumination normalization operation include: performing a Retinex-CLAHE joint enhancement operation to convert the local image from BGR to CIE-Lab space and separate the luminance channel; performing a contrast-limited adaptive histogram equalization operation on the luminance channel; merging the processed luminance channel with the original other channels and converting it back to BGR space; and performing a global Gamma correction operation on the result of the Retinex-CLAHE joint enhancement operation. A local exponential mapping operation is then performed on the result of the global Gamma correction operation, extracting the luminance channel as a guide map, determining the adaptive radius according to a preset ratio of the image's maximum side length, and performing a fast guided filtering operation to obtain a luminance mask; a local gain factor is constructed using an exponential function, applying high gain to shadow areas and low gain to highlight areas; and the new luminance is backmapped to the three channels according to a preset ratio, maintaining chromaticity.
[0080] Further, the steps of performing the automatic white balance operation include: calculating the global mean of each channel in the BGR color space for the local image after illumination normalization, and calculating the average gray value; applying a scaling factor to each channel, wherein the scaling factor is the ratio of the average gray value to the global mean of the corresponding channel; performing a truncation operation on the floating-point pixel values of the three channels after channel gain correction, forcing values less than a preset lower limit to the preset lower limit, and forcing values greater than a preset upper limit to the preset upper limit; and converting the result into an unsigned integer with a preset number of bits.
[0081] Furthermore, the steps of performing the optical anti-aliasing operation include: blurring the image using a Gaussian kernel of a preset size to suppress potential ringing artifacts and quantization noise.
[0082] Furthermore, the global Gamma correction operation includes: calculating the global average brightness of the image data obtained by the Retinex-CLAHE joint enhancement operation to obtain global average brightness data; determining the Gamma correction coefficient based on the global average brightness data; performing exponentiation on the pixel values in the image data obtained by the Retinex-CLAHE joint enhancement operation, and using the Gamma correction coefficient in the calculation process to obtain Gamma-corrected image data.
[0083] Step 4: If the proportion of non-zero pixels in the precise clothing mask image does not meet the preset conditions, then based on the local image with normalized illumination and chromaticity, the clothing interior mask, and the clothing edge mask, calculate the color features of the clothing edge region and the interior region; process the color features according to the fusion strategy to obtain the final color feature vector, which is used to determine whether the clothing color in the ID photo is compliant.
[0084] In specific execution, the steps for calculating the color features include: converting the local image with normalized illumination and chromaticity from BGR space to CIE-Lab space; calculating the average brightness, green-red value, and blue-yellow value of the clothing edge region and the inner region in CIE-Lab space based on the clothing inner mask and the clothing edge mask; and obtaining the color features by combining the HSV primary color of the clothing edge region.
[0085] Furthermore, the fusion strategy includes: if the average brightness of the clothing edge area is less than a preset brightness threshold and the brightness value in the HSV space is less than a preset brightness threshold, then the average brightness of the clothing edge area is taken as the final average brightness; otherwise, the average brightness of the clothing edge area is linearly fused with the average brightness of the inner area with equal weight to obtain the final average brightness; for green-red and blue-yellow values, the corresponding values of the clothing edge area and the inner area are linearly fused with equal weight to obtain the final green-red and blue-yellow values.
[0086] Furthermore, it also includes: if the initial clothing mask image does not contain any non-zero pixels, it is determined that there is no clothing area or that it is completely occluded by other foreground elements, and an empty color feature vector is returned; if the proportion of non-zero pixels in the precise clothing mask image meets a preset condition, it is determined that the clothing area is completely occluded by the edge of the document, the arm, or other foreground elements, and an empty color feature vector is returned, wherein the empty color feature vector is used to indicate that the conditions for clothing color compliance detection are not met.
[0087] Further, calculating the HSV primary color includes: performing color space conversion processing on the local image data with normalized illumination and chromaticity, converting it from BGR space to HSV space to obtain HSV space image data; performing region extraction processing on the HSV space image data and the clothing edge mask, extracting HSV value data of the corresponding region from the HSV space image data based on the region located by the clothing edge mask; quantizing the extracted HSV value data and counting the number of pixels in each quantization interval to obtain an HSV distribution histogram; performing main peak detection on the histogram, filtering out the quantization interval with the highest number of pixels, and determining the center value of this interval as the HSV primary color.
[0088] As a preferred example, further explanation is provided below with reference to the accompanying drawings:
[0089] This embodiment provides a method for detecting the compliance of clothing color in ID photos. Figure 2 This is another flowchart illustrating the method for detecting the compliance of clothing color in ID photos according to an embodiment of the present invention, which includes the following steps:
[0090] Step 10 (Region Adaptive Generation): Perform face detection and portrait parsing operations to obtain face detection bounding boxes and portrait parsing mask images, and generate extended candidate regions based on the face detection bounding boxes.
[0091] Step 20 (Refine and partition the clothing area): Locate the clothing area, perform morphological operations for fine extraction, and divide the clothing area into the clothing edge area and the clothing interior area.
[0092] Step 30 (Joint Illumination and Chromaticity Normalization): Perform illumination normalization, automatic white balance, and optical anti-aliasing to obtain an image with normalized illumination and chromaticity.
[0093] Step 40 (Color Feature Extraction and Lightness Evaluation): The image with normalized illumination and chromaticity is transformed from the BGR space to the perceptually uniform CIE-Lab space, and the final color feature vector is calculated according to the fusion strategy.
[0094] Figure 3 This is a visualization of the local portrait parsing mask generated in this embodiment. In step 10, the region adaptive generation operation in this embodiment further includes:
[0095] Step 11: Obtain the input user image Image0 and perform portrait parsing to generate a portrait parsing mask image M0.
[0096] For example, the portrait analysis model used in this solution can perform in-depth analysis of the input image and accurately and quickly identify and distinguish the four main semantic categories: background, clothing, hair, and skin.
[0097] Step 12: Perform face detection on the user image Image0 to obtain the face detection bounding box Face_ROI, and generate an extended candidate region ROI based on the face detection bounding box Face_ROI to reduce interference from environmental factors such as background and arms.
[0098] Furthermore, the method for generating the extended candidate region ROI specifically calculates the face width and height based on the face detection box Face_ROI; in the horizontal direction, the maximum expandable range of the user image Image0 in the horizontal direction of the face detection box Face_ROI is calculated, and the smaller value of half the face width and the boundary distance is taken as the actual expanded width; in the vertical direction, the face detection box Face_ROI is expanded upward by half the face height and downward by 0.75 times the face height, and it is ensured that the expansion operation does not exceed the image boundary, finally obtaining the extended candidate region ROI.
[0099] Step 13: Based on the candidate region ROI, crop the user image Image0 and the portrait analysis mask M0 to obtain the local image Image1 and the local portrait analysis mask M1.
[0100] Figure 4 This is a visualization of the clothing mask image after performing a partitioning operation and excluding specific areas in this embodiment. In step 20, the detailed clothing area partitioning operation further includes the following specific operations in this embodiment:
[0101] Step 21: Based on the local portrait parsing mask M1, the clothing region is initially located to obtain an initial clothing mask M2, which marks the pixels in the image that are identified as clothing. If the clothing mask M2 does not contain any non-zero pixels, it is determined that there is no clothing region or that it is completely occluded by other foreground elements, and an empty color feature vector (0, 0, 0) is directly returned.
[0102] Step 22: Perform an erosion operation on the initial clothing mask image M2 to obtain an accurate clothing mask image M3, removing background pixels from the clothing mask and improving the accuracy of the mask.
[0103] Step 23: Perform a partitioning operation on the precise clothing mask image M3 to divide its clothing area into clothing edge area and clothing interior area, and obtain clothing interior mask M4 and clothing edge mask M5. By performing color analysis on different areas, the color features of the clothing can be extracted more accurately.
[0104] Furthermore, the partitioning operation specifically involves performing an erosion operation and a Gaussian blur operation on the precise clothing mask image M3 to obtain a temporary mask image M6. The area in the temporary mask image M6 where the pixel value is still 255 is defined as the inner region to obtain the inner clothing mask M4. The inner clothing mask M4 is subtracted from the intermediate clothing mask image M3 to obtain the clothing edge mask M5.
[0105] Step 24: After the above partitioning operation, perform an active exclusion operation for specific regions, especially the clothing portion extending below the Face_ROI detection bounding box. This aims to reduce the interference of the inner layer color on the overall clothing color analysis in specific clothing combinations (such as a suit with a light-colored inner shirt). By removing these potentially interfering areas, the main color features of the clothing can be evaluated more accurately, thereby improving the reliability and accuracy of color analysis.
[0106] Furthermore, by adaptively selecting the parameters of the aforementioned morphological operations based on the image height, and by adaptively adjusting the kernel size of the sparse blur and the kernel size of the erosion operation, the algorithm can better adapt to images of different resolutions.
[0107] Figure 5 This is a flowchart illustrating the joint normalization preprocessing operation of illumination and chromaticity in this embodiment. In step 30, the joint normalization operation of illumination and chromaticity in this embodiment further includes:
[0108] Step 31: Perform illumination normalization on the local image Image1;
[0109] Furthermore, the illumination normalization operation specifically includes Retinex-CLAHE joint enhancement operation, global Gamma correction operation, and local exponential mapping operation. The three-level cascaded architecture compensates for illumination distortions of different scales and physical causes at different levels.
[0110] Specifically, the Retinex-CLAHE joint enhancement operation transforms the local image Image1 from BGR to the perceptually uniform CIE-Lab space, separating the luminance channel L. Constrained Contrast Adaptive Histogram Equalization (CLAHE) is then performed on the L channel. This operation approximates single-scale Retinex, suppressing local luminance differences caused by light source direction or occlusion, while avoiding chromatic aberration caused by global histogram equalization. The processed L is then merged back with the original a and b channels and transformed back into the BGR space, achieving non-linear stretching of luminance only.
[0111] Specifically, the global Gamma correction operation is a power-law transformation of the result of the Retinex-CLAHE joint enhancement operation with γ=1.2, so that the color information in the shadow of the clothing is restored to an approximately linear light space.
[0112] Specifically, the local exponential mapping operation involves first extracting the luminance channel Y from the result of the global Gamma correction operation as a guide map, then performing a fast guided filtering operation to obtain a luminance mask based on an adaptive radius of 1% of the maximum side length of the image, constructing a local gain factor using an exponential function, applying high gain to the shadow area and low gain to the highlight area, and backmapping the new luminance Y′ to the three channels according to the ratio Y′ / Y, keeping the chromaticity unchanged, and finally eliminating the residual shadow in the clothing area.
[0113] Step 32: Perform an automatic white balance operation on the result of step 31;
[0114] Furthermore, the automatic white balance operation specifically involves calculating the global mean μ in the BGR color space of the local image after the illumination normalization operation. B μ G μ R The average gray value Gray is calculated, and a scale factor α is applied to each channel. c =Gray / μ c (c∈{B,G,R}), to achieve channel gain correction and further eliminate light source color temperature shift;
[0115] Specifically, the three-channel floating-point pixel values after channel gain correction are truncated point by point, forcing values less than 0 to 0 and values greater than 255 to 255. The results are then converted into 8-bit unsigned integers to ensure that all pixel values fall within the standard image representation range [0, 255], thus avoiding overflow artifacts.
[0116] Step 33: Perform optical anti-aliasing on the result of step 32 to obtain a local image Image2 with normalized illumination and chromaticity;
[0117] Furthermore, the optical anti-aliasing operation specifically involves using a 5×5 Gaussian kernel to slightly blur the image, suppressing potential ringing artifacts and quantization noise caused by the above operation.
[0118] In step 40, the color feature extraction and light color evaluation operations in this embodiment further include:
[0119] Step 41: If the proportion of non-zero pixels in the accurate clothing mask image M3 is ≤0.1% (≈one-thousandth of the whole image), it is determined that the clothing area is completely occluded by the edge of the document, the arm or other foreground, and an empty color feature vector (0,0,0) is returned directly.
[0120] Step 42: If the return condition of Step 41 is not met, perform luminance and chromaticity statistics and adaptive fusion operations. Convert the local image Image2, whose illumination and chromaticity have been normalized, from BGR space to the perceptually uniform CIE-Lab space. Calculate the average luminance (L), green-red (A), and blue-yellow (B) values of the edges and interior of the clothing area in the LAB color space based on the clothing interior mask M4 and the clothing edge mask M5. Combine this with the HSV primary color of the edge area, and finally calculate the final color feature vector (Mean) according to the fusion strategy. L Mean A Mean B ).
[0121] Furthermore, the fusion strategy specifically includes:
[0122] When L edge <Threshold L And V edge <Threshold V (Dark edges), (i.e., edge areas exhibiting darker tones and lower brightness), the system will completely trust the brightness statistics of the edge areas, that is:
[0123]
[0124] In this case, it can be reasonably inferred that the edge of the garment is made of dark material. Therefore, regardless of the brightness characteristics of the inner area (i.e., the non-edge area), the garment can be determined to be of the dark color category.
[0125] In other cases, the system no longer places absolute trust in edge statistics. To more accurately reflect the overall brightness characteristics of clothing, edge brightness L is used.edge With internal brightness L internal Perform equal-weight linear fusion, that is:
[0126]
[0127] For color channels A and B, regardless of brightness conditions, a 1:1 linear blending of the edge and inner areas is always used. The calculation method is as follows:
[0128]
[0129]
[0130] The proposed fusion strategy takes into account the brightness information of both the edge and center regions, and can more effectively handle situations where there are brightness differences between the edges and the interior, thereby improving the accuracy and stability of brightness judgment. Especially when clothing has high reflectivity, gradient materials, or partial occlusion, this method can significantly alleviate judgment bias caused by local anomalies.
[0131] Based on the same inventive concept, embodiments of the present invention also provide an electronic device, the electronic device including a processor and a memory, the memory storing at least one instruction, at least one program, code set or instruction set, the at least one instruction, the at least one program, the code set or instruction set being loaded and executed by the processor to realize the above-described method for detecting the compliance of clothing color in ID photos.
[0132] It is understood that the memory may include random access memory (RAM) or read-only memory. Optionally, the memory may include non-transitory computer-readable storage medium. The memory can be used to store instructions, programs, code, code sets, or instruction sets. The memory may include a stored program area and a stored data area, wherein the stored program area may store instructions for implementing an operating system, instructions for at least one function, instructions for implementing the various method embodiments described above, etc.; the stored data area may store data created according to the use of the server, etc.
[0133] A processor may include one or more processing cores. The processor connects to various parts of the server via various interfaces and lines, performing various server functions and processing data by running or executing instructions, programs, code sets, or instruction sets stored in memory, and by accessing data stored in memory. Optionally, the processor may be implemented using at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). The processor may integrate one or more of a Central Processing Unit (CPU) and a modem. The CPU primarily handles the operating system and applications; the modem handles wireless communication. It is understood that the modem may also be implemented as a separate chip without being integrated into the processor.
[0134] Since this electronic device is the electronic device corresponding to the method for detecting the compliance of clothing color in ID photos in this embodiment of the invention, and the principle of solving the problem by this electronic device is similar to that of this method, the implementation of this electronic device can refer to the implementation process of the above method embodiment, and the repeated parts will not be described again.
[0135] Based on the same inventive concept, embodiments of the present invention also provide a computer-readable storage medium storing at least one instruction, at least one program, code set, or instruction set, wherein the at least one instruction, the at least one program, the code set, or the instruction set is loaded and executed by a processor to implement the above-described method for detecting the compliance of clothing color in ID photos.
[0136] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable storage medium, including read-only memory (ROM), random access memory (RAM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), one-time programmable read-only memory (OTPROM), electrically-Erasable Programmable Read-Only Memory (EEPROM), compactdisc read-only memory (CD-ROM) or other optical disc storage, disk storage, magnetic tape storage, or any other computer-readable medium capable of carrying or storing data.
[0137] Since this storage medium is the storage medium corresponding to the method for detecting the compliance of clothing color in ID photos in this embodiment of the invention, and the principle of this storage medium in solving the problem is similar to that of this method, the implementation of this storage medium can refer to the implementation process of the above method embodiment, and the repeated parts will not be described again.
[0138] In some possible implementations, various aspects of the methods of the embodiments of the present invention can also be implemented as a program product comprising program code that, when run on a computer device, causes the computer device to perform the steps of the ID photo clothing color compliance detection method according to various exemplary embodiments of the present application described above. The executable computer program code or "code" used to perform the various embodiments can be written in high-level programming languages such as C, C++, C#, Smalltalk, Java, JavaScript, Visual Basic, Structured Query Language (e.g., Transact-SQL), Perl, or in various other programming languages.
[0139] It should be understood that various parts of the present invention can be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.
[0140] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "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 the present invention. 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. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.
[0141] The above embodiments are merely illustrative of the technical concept and features of the present invention, and are intended to enable those skilled in the art to understand the content of the present invention and implement it accordingly. They should not be construed as limiting the scope of protection of the present invention. All equivalent changes or modifications made based on the essence of the content of the present invention should be covered within the scope of protection of the present invention.
Claims
1. A method for detecting the compliance of clothing color in ID photos, characterized in that, Including the following steps: A portrait parsing operation is performed on the input user image to obtain a portrait parsing mask; a face detection operation is performed on the user image to obtain a face detection bounding box; an extended candidate region is generated based on the face detection bounding box; the user image and the portrait parsing mask are cropped based on the extended candidate region to obtain a local image and a local portrait parsing mask; Based on the local portrait parsing mask image, the clothing area is located to obtain an initial clothing mask image; an erosion operation is performed on the initial clothing mask image to obtain a precise clothing mask image; a partitioning operation is performed on the precise clothing mask image to obtain the clothing interior mask and the clothing edge mask; a specific region exclusion operation is performed on the precise clothing mask image. The local image is sequentially subjected to illumination normalization, automatic white balance, and optical anti-aliasing to obtain a local image with normalized illumination and chromaticity. If the proportion of non-zero pixels in the precise clothing mask image does not meet the preset conditions, then based on the local image with normalized illumination and chromaticity, the clothing interior mask, and the clothing edge mask, the color features of the clothing edge region and the interior region are calculated; the color features are processed according to the fusion strategy to obtain the final color feature vector, which is used to determine whether the clothing color in the ID photo is compliant.
2. The method for detecting the compliance of clothing color in ID photos according to claim 1, characterized in that, The steps for generating the expanded candidate region include: Calculate the width and height of the face based on the face detection bounding box; In the horizontal direction, the maximum expandable range of the user image in the face detection box is calculated, and the smaller value between half the face width and the boundary distance is taken as the actual expandable width. In the vertical direction, the face detection box is expanded upward by a preset proportion of the face height and downward by another preset proportion of the face height, ensuring that the expansion does not exceed the image boundary, thus obtaining the expanded candidate region.
3. The method for detecting the compliance of clothing color in ID photos according to claim 1, characterized in that, The steps for partitioning the precise clothing mask image include: The precise clothing mask image is subjected to erosion and Gaussian blur operations to obtain a temporary mask image; Define the area with a preset pixel value in the temporary mask image as the inner area to obtain the inner mask of the clothing; The inner mask of the clothing is subtracted from the precise clothing mask image to obtain the outer mask of the clothing.
4. The method for detecting the compliance of clothing color in ID photos according to claim 1, characterized in that, The steps for performing the exclusion of a specific region include: An exclusion operation is performed on the clothing portion extending below the face detection frame to reduce the interference of the inner layer color on the overall clothing color analysis.
5. The method for detecting the compliance of clothing color in ID photos according to claim 1, characterized in that, The steps for performing the illumination normalization operation include: Perform Retinex-CLAHE joint enhancement operation to convert the local image from BGR to CIE-Lab space and separate the luminance channel; perform contrast-limited adaptive histogram equalization operation on the luminance channel; merge the processed luminance channel with the original other channels and convert it back to BGR space; Perform a global Gamma correction operation on the result of the Retinex-CLAHE joint enhancement operation; The result of the global Gamma correction operation is subjected to a local exponential mapping operation. The luminance channel is extracted as a guide map. The adaptive radius is determined according to the preset ratio of the maximum side length of the image. A fast guided filtering operation is performed to obtain a luminance mask. A local gain factor is constructed using an exponential function. High gain is applied to the shadow area and low gain is applied to the highlight area. The new luminance is backmapped to the three channels according to a preset ratio while keeping the chromaticity unchanged.
6. The method for detecting the compliance of clothing color in ID photos according to claim 1, characterized in that, The steps for performing the automatic white balance operation include: Calculate the global mean of each channel in the BGR color space for the local image after illumination normalization, and calculate the average gray value. A scaling factor is applied to each channel, which is the ratio of the average gray value to the global mean of the corresponding channel; Perform a truncation operation on the three-channel floating-point pixel values after channel gain correction, forcing values less than the preset lower limit to the preset lower limit and values greater than the preset upper limit to the preset upper limit; convert the result into an unsigned integer of a preset number of bits.
7. The method for detecting the compliance of clothing color in ID photos according to claim 1, characterized in that, The steps for performing the optical anti-aliasing operation include: The image is blurred using a Gaussian kernel of a preset size to suppress potential ringing artifacts and quantization noise.
8. The method for detecting the compliance of clothing color in ID photos according to claim 1, characterized in that, The steps for calculating the color features include: The local image with normalized illumination and chromaticity is converted from BGR space to CIE-Lab space; Based on the internal mask and the edge mask of the clothing, calculate the average brightness, green-red value, and blue-yellow value of the edge region and the internal region of the clothing in the CIE-Lab space; The color feature is obtained by combining the HSV primary color of the edge area of the clothing.
9. The method for detecting the compliance of clothing color in ID photos according to claim 1, characterized in that, The fusion strategy includes: If the average brightness of the edge area of the clothing is less than a preset brightness threshold and the brightness value in the HSV space is less than a preset brightness threshold, then the average brightness of the edge area of the clothing will be used as the final average brightness. In other cases, the average brightness of the edge area of the clothing is linearly fused with equal weights to the average brightness of the inner area to obtain the final average brightness. For the green-red and blue-yellow values, the corresponding values of the edge area and the inner area of the clothing are linearly fused with equal weights to obtain the final green-red and blue-yellow values.
10. The method for detecting the compliance of clothing color in ID photos according to claim 1, characterized in that, Also includes: If the initial clothing mask image does not contain any non-zero pixels, it is determined that there is no clothing area or that it is completely occluded by other foreground elements, and an empty color feature vector is returned. If the proportion of non-zero pixels in the precise clothing mask image meets the preset conditions, it is determined that the clothing area is completely occluded by the edge of the document, the arm, or other foreground, and an empty color feature vector is returned. The empty color feature vector is used to indicate that the conditions for clothing color compliance detection are not met.
Citation Information
Patent Citations
Wearing specification judgment method based on image recognition and related equipment
CN112395999A
Identification photo intelligent reloading processing method and device
CN119624792A