Created
January 31, 2013 13:05
-
-
Save jcupitt/4682718 to your computer and use it in GitHub Desktop.
detect skin tones in an image with libvips and python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys | |
from vipsCC import * | |
im = VImage.VImage(sys.argv[1]) | |
try: | |
# import to CIELAB with lcms | |
# 1 means relative colorimetry | |
# this assumes there is a profile there, of course | |
cielab = im.icc_import_embedded(1) | |
except: | |
# nope .. use the built-in converter instead | |
cielab = im.sRGB2XYZ().XYZ2Lab() | |
# convert to LCh | |
lch = cielab.Lab2LCh() | |
# get the h band | |
h = lch.extract_band(2) | |
# find all pixels with a hue in the range 60 - 90 (approximately skin tones) | |
mask = h.more(60).andimage(h.less(90)) | |
mask.write(sys.argv[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment