Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the methods of skin region detection in Python traditional image processing

Shulou Source: shulou.com Published: 2022-06-02 08:03:18 10月02日 Update

This article mainly introduces "Python traditional image processing skin area detection methods have what", in daily operation, I believe many people in Python traditional image processing skin area detection methods have what problems, small editor consulted all kinds of data, sorted out simple and easy to use operation methods, hope to answer "Python traditional image processing skin area detection methods have what" doubts help! Next, please follow the small series to learn together!

1. RGB space

The range of skin tones in the RGB model basically satisfies the following constraints:

Under uniform illumination, the following discriminant shall be satisfied:

R>95 AND G>40 B>20 AND MAX(R,G,B)-MIN(R,G,B)>15 AND ABS(R-G)>15 AND R>G AND R>B

In edge-lit environments:

R>220 AND G>210 AND B>170 AND ABS(R-G)B AND G>B

Code:

def skinMask_rgb(image): b, g, r = cv2.split(image) mask_uniformity = (r>95)*(g>40)*(b>20)* (np.max(image, axis=2) -np.min(image,axis=2)>15)* (abs(r-g)>15)*(r>g)*(r>b) mask_side = (r>220)*(g>210)*(b>170)*(abs(r-g)b)*(g>b) mask = mask_uniformity|mask_side skin = np.array(mask, np.uint8)*255 ratio = np.sum(skin/255)/(image.shape[0]*image.shape[1]) return skin, ratio

Effect:

2. Ycrcb space

In RGB space, the skin color of human face is greatly affected by brightness, so it is difficult to separate skin color points from non-skin color points, that is to say, after processing in this space, skin color points are discrete points with many non-skin colors embedded in the middle. If RGB is converted to YCrCb space, the effect of Y(luminance) can be ignored, because this space is less affected by luminance, and skin color will produce good clustering. This reduces the three-dimensional space to two-dimensional CrCb, and the skin color points will form a certain shape.

133≤Cr≤173

77≤Cb≤127

Code:

def skinMask_YCrCb(image): YCrCb = cv2.cvtColor(image, cv2.COLOR_BGR2YCR_CB) #Convert to YCrCb space (y,cr,cb) = cv2.split(YCrCb) #Split Y,Cr,Cb values skin = np.zeros(cr.shape, dtype = np.uint8) (x,y) = cr.shape cr_mask1 = cr >= 133 cr_mask2 = cr = 77 cb_mask2 = cb

Tags: Space image skin color detection picture skin pixel effect processing brightness code method ellipse histogram traditional region image processing signal target learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology MariaDB vpn Shulou Information NVidia