1 '''
2 Copyright 2013 Oak Ridge National Laboratory
3 Created on Jun 3, 2013
4
5 @author: David S. Bolme
6 '''
7
8 import pyvision as pv
9
10 -def skintone(im,low_thresh=0.02511,high_thresh=0.1177):
11 '''
12 Returns a mask showing pixels classified as skin tone.
13
14 Based on:
15 Cheddad et.al. "A new colour space for skin tone detection" ICIP. 2009.
16 '''
17 mat = im.asMatrix3D()
18 r,g,b = mat/255.0
19 I = 0.298936021*r + 0.5870430*g + 0.14020904255*b
20 Ip = (g>b)*g + (b>=g)*b
21
22
23
24 e = I - Ip
25
26 mask = (e > low_thresh) & (e < high_thresh) & (g > 0.05) & (g < 0.98)
27
28
29
30
31
32
33 return mask
34
35 if __name__ == '__main__':
36 video = pv.VideoFromDirectory("/data/retrieval/test_images/people/")
37 for im in video:
38
39 mask = skintone(im,low_thresh=.03,high_thresh=.10)
40 tmp = im.copy()
41 tmp.annotateMask(mask)
42 tmp.show()
43