Skin color extraction and detection method based on YCbCr
Technical Field
The invention relates to a skin color extraction and detection method based on YCbCr, belonging to the technical field of image processing.
Background
Skin color extraction is the basis of skin color detection, while skin color detection refers to the process of selecting a pixel region corresponding to human skin in an image, and with the rapid development of image processing technology, skin color detection technology is widely applied to face detection and recognition, face tracking, facial expression recognition, gesture recognition, man-machine interaction, image retrieval based on image content, video monitoring and the like, but image information acquired by a camera is constantly influenced by complex environments, in the case of a captured image with a large variation in illumination intensity, it is difficult to capture skin color information, therefore, the specific meaning expressed by the human body is difficult to identify, and in order to meet the requirement that people can still effectively identify the skin color of the human body under different illumination intensity environments, skin color information in the image needs to be effectively extracted to highlight the skin color area of the human body, so that the meaning to be expressed is better expressed.
In recent years, segmentation of skin color of images using the YCbCr color space, i.e., YUV, where "Y" represents brightness, i.e., a gray scale value, has been a research focus; and "U" and "V" denote chromaticity, which is used to specify the color of the pixel. The Y component is created through the RGB input signal by superimposing specific parts of the RGB signal together. "chroma" defines the hue and saturation of a color, represented by Cr and Cb, respectively. Because the skin color pixel points are distributed in an approximately elliptical area range on the plane of the YCbCr color space, skin color targets such as human faces, gestures and the like can be effectively segmented.
The color spaces adopted by the images based on skin color segmentation at present mainly comprise YCbCr color spaces and HSV color spaces, but the good effect is not achieved on the processing under the environments of strong light and weak light.
Disclosure of Invention
The invention provides a skin color extraction and detection method based on YCbCr, aiming at solving the problems that skin color targets such as human faces, gestures and the like cannot be effectively segmented under the strong light and weak light environment and the robustness of extracting a skin color area is not high at present.
The invention provides a YCbCr-based skin color extraction method, which adopts different formulas to extract Cr and Cb components according to the range of a brightness component Y after obtaining the brightness component Y of an image so as to realize the extraction of a skin color area of the image, and comprises the following steps:
when Y is less than or equal to 20 or Y is greater than or equal to 180, Cr and Cb components are obtained by adopting an improved conversion formula from RGB color space to YCbCr color space;
when 20< Y <180, Cr and Cb components are obtained by using YCbCr color space conversion formula recommended by international standard ITU-R BT.601.
Optionally, when Y is less than or equal to 20 or Y is greater than or equal to 180, the improved conversion formula from the RGB color space to the YCbCr color space is used to obtain the Cr and Cb components, and the improved conversion formula from the RGB color space to the YCbCr color space is:
wherein, theta0、θ1、λ1、λ0Is a parameter, θ, determined by the variation of different illumination0、θ1、λ1、λ0The solving formula of (2) is as follows:
wherein: y is
(Cr)iIs to determine a certain brightness Y
iThe logarithm of the Cr component of the image under component, obtained by the YCbCr color space conversion formula used in International Standard ITU-R BT.601, is obtained
x
(Cr)iIs the same brightness Y
iThe component being reciprocal, i.e.
y
(Cb)iIs to determine the brightness Y
iYCbCr color space conversion in component down images by using international standard ITU-R BT.601The Cb component being a negative logarithm of the value, i.e. obtained by the formula
x
(Cb)iIs the same brightness Y
iThe component being reciprocal, i.e.
m is obtaining different brightness Y
iNumber of sample skin tone pictures.
Optionally, when 20< Y <180, the YCbCr color space conversion formula used by the international standard ITU-R bt.601 is adopted to obtain the Cr and Cb components, and the YCbCr color space conversion formula used by the international standard ITU-R bt.601 is
Cb=-0.148R-0.291G+0.439B+128
Cr=0.439R-0.368G-0.071B+128
R, G, B are original pixel values in RGB space.
Optionally, the obtaining the luminance component Y of the image includes:
and acquiring an original skin color image, and filtering the original skin color image to ensure that the pixel weight with higher similarity degree in the image is higher, the edge is more obvious, the contrast is higher, and the smooth image is obtained.
Optionally, a bilateral filter is used for filtering the original skin color map, and a transfer function expression of the bilateral filter is as follows:
wherein the weighting factor w (i, j, k, l) depends on the product of the domain kernel d (i, j, k, l) and the value domain kernel r (i, j, k, l), i.e.:
wherein f represents an original skin color map, g (i, j) represents a processed image, (i, j) represents a position of a certain pixel point to be processed in g (i, j), f (k, l) represents a gray value of a neighborhood pixel of the pixel point at the position (i, j) in f, and σ represents the gray value of a neighborhood pixel of the pixel point at the position (i, j) in fdIs a smoothing coefficient, σ, defining a domain kernelrIs the smoothing parameter of the value domain kernel, and e is the euler constant.
The second purpose of the invention is to provide a skin color detection method based on YCbCr, which adopts the skin color extraction method based on YCbCr to extract skin color.
Optionally, the method further includes:
and performing Gaussian filtering on the extracted Cr and Cb components, reducing the spatial change of the Cr and Cb component pixels, weakening random noise, and performing image binarization by adopting a maximum inter-class variance method to obtain a skin-color binarization picture.
Optionally, the kernel function of the gaussian filtering is as follows:
wherein the vector
Representing the mask coordinate (x, y) point,
is the mask center point coordinate, i.e., the mean of the mask coordinates.
Optionally, a high-definition camera is used for acquiring the original skin color image.
The third purpose of the present invention is to provide an application of the YCbCr-based skin color extraction method and/or the YCbCr-based skin color detection method in the technical field of image processing.
The invention has the beneficial effects that:
after the brightness component Y of the image is obtained, Cr and Cb components are extracted by adopting different formulas according to the range of the brightness component Y so as to realize the extraction of the skin color area of the image, thereby effectively improving the robustness of extracting the skin color area under different illumination intensities; specifically, when Y is less than or equal to 20 or Y is greater than or equal to 180, Cr and Cb components are obtained by adopting an improved conversion formula from an RGB color space to a YCbCr color space; when 20< Y <180, obtaining Cr and Cb components by adopting a YCbCr color space conversion formula used in the international standard ITU-R BT.601; aiming at the characteristic that the image is fuzzy under the strong light and weak light environments, the invention realizes the segmentation of the skin color by adopting different modes according to the brightness separation range, improves the robustness of the skin color identification, effectively solves the problem that the extraction of the image skin color area can not be realized under the strong light and weak light environments, and ensures that the subsequent application in face detection and identification, face tracking, facial expression identification, gesture identification, man-machine interaction, image retrieval based on image content and video monitoring can more accurately identify the human body skin color area.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a flowchart of a skin color detection method based on YCbCr according to the present application.
FIG. 2 is a skin color original in the range of 150. ltoreq. Y.ltoreq.190.
Fig. 3 is a skin color map after bilateral filtering of fig. 2 using international standard ITU-R bt.601.
FIG. 4 is a gray scale and skin color combination diagram of Cb and Cr obtained by using skin color detection formula of Y in the range of 150 ≤ Y ≤ 190 of International Standard ITU-R BT.601.
Fig. 5 is a diagram after binarization in step (4).
FIG. 6 is a skin color original in the range of 0. ltoreq. Y.ltoreq.20.
Fig. 7 is a skin tone map for bilateral filtering of fig. 6 using international standard ITU-R bt.601.
Fig. 8 is a gray scale skin color combination plot of Cb, Cr obtained from fig. 7 using the improved skin color detection formula given in this application with Y in the range less than 20.
Fig. 9 is a grey scale skin color combination map of Cb, Cr obtained from fig. 7 using the YCbCr color space conversion formula used by international standard ITU-R bt.601.
Fig. 10 is a diagram of fig. 8 after the binarization at step (4).
Fig. 11 is a diagram of fig. 9 after the binarization at step (4).
FIG. 12 is a skin color original in the range of 180 ≦ Y ≦ 200.
Fig. 13 is a skin tone map for bilateral filtering of fig. 12 using international standard ITU-R bt.601.
FIG. 14 is a combined graph of the gray level skin color of Cb and Cr obtained by using the skin color detection formula given in the international standard ITU-R BT.601 in the range of Y being more than or equal to 180 and less than or equal to 200.
Fig. 15 is a diagram of fig. 14 after the binarization at step (4).
FIG. 16 is a gray scale skin color combination graph of Cb and Cr obtained by using skin color detection formula with the range of Y being more than or equal to 180 and less than or equal to 200 provided by the application
Fig. 17 is a diagram of fig. 16 after the binarization at step (4).
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, embodiments of the present invention will be described in detail with reference to the accompanying drawings.
The first embodiment is as follows:
the embodiment provides a skin color detection method based on YCbCr, which comprises the steps of converting an RGB color space into an YCbCr color space, obtaining a brightness component of an image, and extracting Cr and Cb components by adopting different formulas according to the range of the brightness component Y so as to extract a skin color area of the image;
the following example of the extraction of skin color blocks under different illumination intensities illustrates the specific implementation of the method of the present invention, and the experimental environment includes: the CPU adopts i5-7200U, adopts Python language to write programs, processes images in a Spyder program debugging environment, and adopts a Window10 operating system in a system running environment. The whole improved skin color segmentation method hardware part experimental environment comprises the following steps: the camera adopts Roots (Logitech) C270iIPTV high-definition network camera, adopts an LED annular light source of DHO-RI12030 of great Heng group Limited company in China to adjust the brightness, and the invention is further described with reference to the attached drawings, and please refer to FIG. 1:
step 1: acquiring an original skin color image, and filtering the original skin color image;
in this embodiment, the skin color original image (i.e., fig. 2) with Y being greater than or equal to 150 and less than or equal to 190, the skin color original image (i.e., fig. 6) with Y being greater than or equal to 0 and less than or equal to 20, and the skin color original image (i.e., fig. 12) with Y being greater than or equal to 180 and less than or equal to 200 are selected for extracting skin color.
Filtering the original skin color image to ensure that the pixel weight with higher similarity degree in the image is higher, the edge is more obvious and the contrast is higher:
specifically, a bilateral filter is used for image filtering, a software program calls a bilatelfilter () function of a cv2 module of the OpenCV, and the bilateral filter is used for image filtering, wherein the diameter of a pixel to be filtered is 5 pixels, and the result graphs after filtering in fig. 2, 6, and 12 are respectively shown in fig. 3, 7, and 13, and the transfer function expression of the bilateral filter is as follows:
wherein the weighting factor w (i, j, k, l) depends on the product of the domain kernel d (i, j, k, l) and the value domain kernel r (i, j, k, l), i.e.:
wherein f represents an original skin color map, g (i, j) represents a processed image, (i, j) represents a position of a certain pixel point to be processed in g (i, j), f (k, l) represents a gray value of a neighborhood pixel of the pixel point at the position (i, j) in f, and σ represents the gray value of a neighborhood pixel of the pixel point at the position (i, j) in fdIs a smoothing coefficient, σ, defining the kernel of the domainrIs the smoothing parameter of the value domain kernel, and e is the euler constant.
Step 2: aiming at the images 3, 7 and 13 obtained by the bilateral filtering in the step 1, the conversion of the RGB color space and the YCbCr color space is carried out to obtain the converted brightness component, and the conversion formula is as follows:
Y=0.257R+0.504G+0.098B+16
r, G, B are original pixel values in RGB space, and Y is pixel value of YCbCr space brightness component.
And step 3: judging the approximate range of the luminance Y component of the skin color picture after conversion in step 2, wherein the approximate range of the Y component in fig. 3 is as follows: y is more than or equal to 150 and less than or equal to 190, and for the skin color picture in the brightness component range, a YCbCr color space conversion formula recommended by the international standard ITU-R BT.601 in the prior art is adopted to obtain Cr and Cb components, wherein the conversion formula is as follows:
Cb=-0.148R-0.291G+0.439B+128
Cr=0.439R-0.368G-0.071B+128
obtaining a gray scale image of the combination of the Cr and Cb components after conversion, as shown in FIG. 4;
and the approximate range of the Y component of fig. 7 is: y is more than or equal to 0 and less than or equal to 20, Cr and Cb components are obtained by adopting an improved conversion formula from RGB color space to YCbCr color space, and a gray scale image combining the Cr and Cb components is obtained after conversion, as shown in FIG. 8; wherein the conversion formula is as follows:
wherein, theta0、θ1、λ1、λ0Is a parameter, θ, determined by the variation of different illumination0、θ1、λ1、λ0The solving formula of (2) is as follows:
wherein: y is
(Cr)iIs to determine a certain brightness Y
iThe logarithm of the Cr component in the component-down image obtained by the YCbCr color space conversion formula used in International Standard ITU-R BT.601 in step (3), i.e. the value obtained by taking the logarithm of the Cr component
x
(Cr)iIs the same brightness Y
iThe component being reciprocal, i.e.
y
(Cb)iIs to determine the brightness Y
iThe color space conversion formula of YCbCr used in international standard ITU-R BT.601 in step (3) in the image under componentThe Cb component taking a logarithmic value, i.e.
x
(Cb)iIs the same brightness Y
iThe component being reciprocal, i.e.
m is obtaining different brightness Y
iNumber of sample skin tone pictures.
The approximate range of the Y component of fig. 12 is: y is more than or equal to 180 and less than or equal to 200, Cr and Cb component combined graphs are obtained by respectively adopting a conversion formula from an RGB color space to a YCbCr color space of a YCbCr color space conversion formula used in the international standard ITU-R BT.601, as shown in figure 14, and a binary graph of Cr and Cb component combined is obtained after conversion, as shown in figure 15; and the improved conversion formula from RGB color space to YCbCr color space herein is to obtain the Cr, Cb component combination map as shown in fig. 16, and obtain the binarized map after conversion of Cr and Cb components as shown in fig. 17, while if the conversion formula from YCbCr color space, which is not optimized in international standard ITU-R bt.601, is used in fig. 7 to obtain the gray scale map obtained by combining Cr, Cb components, and the obtained gray scale map is shown in fig. 9, it is known that the improved conversion formula from RGB color space to YCbCr color space provided by the present application has a good effect of extracting the skin color picture with Y components in the range of 0 ≦ Y ≦ 20 compared to the gray scale map obtained by combining Cr, Cb components using the improved conversion formula from RGB color space to YCbCr color space provided by the present application, i.e. fig. 8. As can be seen from comparison of FIG. 15 and FIG. 17, it is also effective in extracting skin color under strong light 180. ltoreq. Y.ltoreq.200.
In this embodiment, m is 600, and one group of parameters obtained and adopted from the skin color sample picture under the condition of 600 different brightnesses is: theta0=2.92;θ1=-52.07,λ0=2.42,λ1=-28.27。
And (4) performing Gaussian filtering on the gray level image 4, the gray level image 8 and the gray level image 9 combined by the Cr and Cb components in the step (3), and performing binarization on the image to obtain a picture after skin color binarization, wherein the obtained result is shown as a binarization image 5, a binarization image 10 and a binarization image 11. Wherein the gaussian filter kernel function is as follows:
wherein the vector
Representing the mask coordinate (x, y) point,
is the mask center point coordinate, i.e., the mean of the mask coordinates.
Fig. 10 is a result diagram after binarization in fig. 8, fig. 11 is a result diagram after binarization in fig. 9, and comparing fig. 10 and fig. 11 with comparing fig. 15 and fig. 17, it can be known that in the skin color detection method based on YCbCr provided in the present application, the Cr and Cb components are obtained by an improved conversion formula from an RGB color space to an YCbCr color space, and then a gray scale image in which the Cr and Cb components are combined is obtained, so that robustness of extracting skin color regions under different illumination intensities is effectively improved, and a segmentation effect is significantly improved.
Some steps in the embodiments of the present invention may be implemented by software, and the corresponding software program may be stored in a readable storage medium, such as an optical disc or a hard disk.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents, improvements and the like that fall within the spirit and principle of the present invention are intended to be included therein.