简体   繁体   中英

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?

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:

在此处输入图片说明

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

And here is a lighter one:

在此处输入图片说明

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM