Package pyvision :: Package face :: Module skintone
[hide private]
[frames] | no frames]

Source Code for Module pyvision.face.skintone

 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 #pv.Image(I).show() 22 #pv.Image(Ip).show() 23 24 e = I - Ip 25 #pv.Image(e).show() 26 mask = (e > low_thresh) & (e < high_thresh) & (g > 0.05) & (g < 0.98) 27 #mask = (e > low_thresh) 28 #print low_thresh,high_thresh,mask.sum(),e.min(),e.max() 29 #mask = (e < high_thresh) 30 31 #mask = g > 0.5 32 33 return mask
34 35 if __name__ == '__main__': 36 video = pv.VideoFromDirectory("/data/retrieval/test_images/people/") 37 for im in video: 38 #for lt in [0.0,0.02,0.04,0.08,0.10,0.12]: 39 mask = skintone(im,low_thresh=.03,high_thresh=.10) 40 tmp = im.copy() 41 tmp.annotateMask(mask) 42 tmp.show() 43