imageperlcolorsdetectionperlmagick

Detect black/almost black JPG images in PERL


I want to detect the black/almost black JPEG images from a folder using PERL. Do you have any suggestions about the method/module that I should use?


Solution

  • Dark images will generally have a low-ish mean pixel value.

    You can get the mean of the image's pixels using ImageMagick's identify at the command line like this:

    identify -format "%[mean]" input.png
    

    or using

    identify -verbose input.png
    

    and looking for the parameter you think will help most.

    Or use Perl like this:

    #!/usr/bin/perl
    use strict;
    use warnings;
    use Image::Magick;
    
    my $image = Image::Magick->new;
    $image->ReadImage("c.png");
    
    print $image->Get("%[mean]");
    

    In the Perl case, the range is 0-65535, so dark ones will have a mean below say 5,000.

    Example:

    Here is a dark image:

    enter image description here

    identify -format "%[mean]" dark.jpg
    16914.6
    

    And here is a lighter one:

    enter image description here

    identify -format "%[mean]" light.jpg
    37265.7