在PERL中检测黑色/近乎黑色的JPG图像

Nic*_*ick 2 perl image colors detection perlmagick

我想使用PERL从文件夹中检测黑/近黑的JPEG图像.您对我应该使用的方法/模块有什么建议吗?

Mar*_*ell 7

暗图像通常具有低平均像素值.

您可以identify在命令行使用ImageMagick获取图像像素的平均值,如下所示:

identify -format "%[mean]" input.png
Run Code Online (Sandbox Code Playgroud)

或使用

identify -verbose input.png
Run Code Online (Sandbox Code Playgroud)

并寻找你认为最有帮助的参数.

或者Perl像这样使用:

#!/usr/bin/perl
use strict;
use warnings;
use Image::Magick;

my $image = Image::Magick->new;
$image->ReadImage("c.png");

print $image->Get("%[mean]");
Run Code Online (Sandbox Code Playgroud)

在Perl的情况下,范围是0-65535,所以黑暗的范围低于5000.

例:

这是一个黑暗的图像:

在此输入图像描述

identify -format "%[mean]" dark.jpg
16914.6
Run Code Online (Sandbox Code Playgroud)

这是一个较轻的一个:

在此输入图像描述

identify -format "%[mean]" light.jpg
37265.7
Run Code Online (Sandbox Code Playgroud)