detect_skin_pixels.py 1.05 KB
Newer Older
1
2
3
4
5
6
7
import sys
import numpy

import bob.io.base
import bob.io.base.test_utils
import bob.io.image
import bob.ip.facedetect
8
from bob.ip.skincolorfilter import SkinColorFilter
9

10
face_image = bob.io.base.load(bob.io.base.test_utils.datafile('test-face.jpg', 'bob.ip.skincolorfilter'))
11
12
13
14
detection = bob.ip.facedetect.detect_single_face(face_image)
bounding_box, quality = bob.ip.facedetect.detect_single_face(face_image)
face = face_image[:, bounding_box.top:bounding_box.bottom, bounding_box.left:bounding_box.right]
skin_filter = SkinColorFilter()
15
16
skin_filter.estimate_gaussian_parameters(face)
skin_mask = skin_filter.get_skin_mask(face_image, 0.5)
17
18
19
20
skin_image = numpy.copy(face_image)
skin_image[:, numpy.logical_not(skin_mask)] = 0

from matplotlib import pyplot
21
22
23
24
25
26
27
28
29
30
31
f, ax = pyplot.subplots(1, 1) 
ax.set_title('Original Image')
ax.set_xticks([])
ax.set_yticks([])
ax.imshow(numpy.rollaxis(numpy.rollaxis(face_image, 2),2))
f, ax = pyplot.subplots(1, 1) 
ax.set_title('Detected skin pixels')
ax.set_xticks([])
ax.set_yticks([])
ax.imshow(numpy.rollaxis(numpy.rollaxis(skin_image, 2),2))