fionbarr has asked for the wisdom of the Perl Monks concerning the following question:

I have an interesting project: I need to look at my company's directory structure for image files (worrying about x-rated). Are there any modules which might analyze for preponderance of flesh-tones in the image?

Replies are listed 'Best First'.
Re: analyze image for color
by BrowserUk (Patriarch) on Feb 18, 2010 at 15:52 UTC

    Hm. I know there are commercial products out there that do this, but the idea has always seemed pretty impossible to me.

    Not so much the technical aspect of detecting a large proportion of skin-tone in a given image--though a close up of the back of someones hand would surely be flagged; but could anyone be offended by it?

    The real problem comes in identifying what is likely to offend the whole gamut of possible offendees.

    Take the recent story of the Aussie Banker seen on live TV with "nude pictures" of a model on his screen. The girl is a model and spends much of her career being photographed scantily clad. Do an image search of her and you'll find it nigh impossible to find a photo of her fully clothed. Religious prohibitions aside, is it really so shocking? Offensive?

    A freind of mine has a large photo of her (then) early 20s daughter hanging on her living room wall. In the photo the daughter is entirely naked, and very heavily pregnant. Strategically placed arm and thigh prevent anything more than might show in a bikini being visible. The oblique lighting and a high contrast black and white print emphasis the motherly curves and make for a very beautiful and completely tastful photo. But I can easily imagine that the same persons offended by the model above would find it offensive.

    She also had the same photo as a screen saver on her laptop. She's a very proud mother and grandmother. But your "skin tones" test would likely completely fail to pick it up.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      This thread is worthless without pics :)
        I take your point...I wish I could help.
Re: analyze image for color
by zentara (Cardinal) on Feb 18, 2010 at 18:30 UTC
    You could do a manuall pixel by pixel count of the color, like in
    #!/usr/bin/perl use warnings; use strict; use Image::Magick; my $file = shift or die "Need a file $!\n"; my $img = Image::Magick->new; $img->ReadImage($file); # if you want a pixel by pixel list of every color # a huge slow output #$img->Set(magick => 'txt'); #$img->Write("$0.txt"); #histogram #returned values are an array of #red, green, blue, opacity, and count values. my $tot = 0; my (@colors) = $img->Histogram(); #print join "\n\n", @colors; while (1){ if (scalar @colors == 0){last} my $r = shift @colors; my $g = shift @colors; my $b = shift @colors; my $o = shift @colors; my $count = shift @colors; $tot++; my $rh = sprintf('%02X',$r); my $gh = sprintf('%02X',$g); my $bh = sprintf('%02X',$b); print "$count ($rh,$gh,$bh) at $o opacity\n"; } print "\n$tot total colors\n";
    You could then setup suspicious range ranges of colors, and do whatever.

    Also google for "ImageMagick flesh color detection" for many other ideas.


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku
      ImageMagick is something else! Thanks
Re: analyze image for color
by derby (Abbot) on Feb 18, 2010 at 15:13 UTC
Re: analyze image for color
by Anonymous Monk on Feb 18, 2010 at 15:13 UTC
    imagemagick
Re: analyze image for color
by Gavin (Archbishop) on Feb 19, 2010 at 11:00 UTC
      interesting...thanks