Created
January 31, 2013 13:18
-
-
Save jcupitt/4682797 to your computer and use it in GitHub Desktop.
Find skin tones with ruby-vips.
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/ruby | |
require 'rubygems' | |
require 'vips' | |
im = VIPS::Image.new(ARGV[0]) | |
begin | |
# import to CIELAB with lcms | |
# if there's no profile there, we'll fall back to the thing below | |
cielab = im.icc_import_embedded(:relative) | |
rescue | |
# nope .. use the built-in converter instead | |
cielab = im.srgb_to_xyz().xyz_to_lab() | |
end | |
# convert to LCh | |
lch = cielab.lab_to_lch() | |
# 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).and(h.less(90)) | |
mask.write(ARGV[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment