NAME
Imager::SkinDetector - Try to detect skin tones and nudity in images
SYNOPSIS
use Imager::SkinDetector;
# Use whatever format your Imager supports
my $name = 'mypic.png';
# Check a local file
my $image = Imager::SkinDetector->new(file => $name)
or die "Can't load image [$name]\n";
# ... or download a remote picture via HTTP
my $image = Imager::SkinDetector->new(url => 'http://some.server/some.pic')
or die "Can't load image!\n";
my $skinniness = $image->skinniness();
printf "Image is %3.2f%% skinny\n", $skinniness * 100;
my $prob = $image->contains_nudity();
printf "Contains nudity with a %.2f%% probability\n", $prob * 100;
DESCRIPTION
Have you ever needed to know if an image has some amount of skin tone color? Did you find some tool to do it? Free software? Yes? If so, please tell me right now!
If not, welcome to Imager-SkinDetector. It uses Imager as processing engine, so it should have a decent speed. Don't expect miracles, though.
I'm planning to use this as part of a set of tools to automatically classify images as nudity or "containing skin". It's only a plan. I might succeed one day. Most probably I won't. :-)
Feel free to provide feedback and code.
FUNCTIONS
is_skin($color)
Examines an Imager::Color
object and tells you if it seems to be similar to skin color.
The algorithm is as stupid as you can get. No less. And it only detects "white" skin colors for now. Sorry.
Example:
my $color = Imager::Color->new(0, 255, 255);
if (Imager::SkinDetector::is_skin($color)) {
print 'Yes, it seems to be skinny';
} else {
print 'Mmhhh, probably not';
}
rgb2hsv(@rgb)
Converts an RGB triplet into HSV, returned as a list of values. H
is hue, 0 to 360. S
is saturation, 0 to 1. V
is value, 0 to 255.
Example:
my @rgb = (255, 0, 0);
my @hsv = Imager::SkinDetector::rgb2hsv(@rgb);
METHODS
contains_nudity()
Tries to detect if image contains nudity, by using all available methods, like hue_frequencies()
and skinniness()
, and trying to combine their results into something reasonable.
Returns a real value between 0 and 1.
The algorithm is basically crap, so I would be seriously surprised if it works even for a small percentage of the images you throw at it.
Anyway, feel free to send me interesting test cases :-)
hue_frequencies()
Examines the image and returns a list of 36 relative frequencies for color hues in the picture.
Now it outputs 36 values, corresponding to 36 intervals in the entire spectrum, conventionally ranged from 0 to 360, where first interval corresponds to red.
The relation between hue and number is approximately as follows:
Hue value Color
----------------------
0 - 60 red
60 - 120 yellow
120 - 180 green
180 - 240 cyan
240 - 300 blue
300 - 360 magenta
is_fuzzy()
Return a floating point value that tries to represent how "fuzzy" your image is. The higher the number, the "fuzzier" the image.
I don't know how to explain what I mean by "fuzzy", but probably an example can:
http://search.cpan.org/src/COSIMO/Imager-SkinDetector-0.05/examples/fractal.gif
While this other one has a very low "fuzzy" factor:
http://search.cpan.org/src/COSIMO/Imager-SkinDetector-0.05/examples/sand.jpg
skinniness()
Returns a real value from 0 to 1, indicating how much skin tone color is present in the given picture. A return value of zero means no skin tone colors. A return value of one means a picture that contains only skin colors.
Example:
# You might not be able to load '.png' pictures,
# depending on your version of Imager and OS
my $pic = 'coolpic.png';
my $img = Imager::SkinDetector->new(file => $pic);
my $skin = $img->skinniness();
# $skin = 0.21313 -> 21.3% of skin colors
AUTHOR
Cosimo Streppone, <cosimo at cpan.org>
BUGS
Please report any bugs or feature requests to bug-imager-skindetector at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Imager-SkinDetector. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Imager::SkinDetector
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Imager-SkinDetector
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
COPYRIGHT & LICENSE
Copyright 2008 Cosimo Streppone, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.