简体   繁体   English

在比较API中将PerlMagick与Fuzz参数一起使用

[英]Using fuzz parameter with perlmagick in compare api

I am trying to use perlmagick to compare 2 images. 我正在尝试使用perlmagick比较2张图像。 It works perfectly fine for most of the cases, but if there is slight difference in pixels then it is counted as error. 在大多数情况下,它都可以正常工作,但是如果像素之间存在细微差异,则视为错误。 If I use compare command provided by ImageMagick then I can specify fuzz parameter which will treat pixels in the given distance as same. 如果我使用ImageMagick提供的compare命令,则可以指定fuzz参数,该参数会将给定距离内的像素视为相同。

I tried using fuzz option in compare api as suggested in documentation but it's not working. 我尝试按照文档中的建议在compare api中使用fuzz选项,但是它不起作用。 http://www.imagemagick.org/script/perl-magick.php http://www.imagemagick.org/script/perl-magick.php

$Difference = $orgImage->Compare( image => $secondImage, metric => 'RMSE', fuzz => '100', channel => 'ALL' );

Thanks ! 谢谢 !

This is a known issue in PerlMagick which hasn't been fixed since its discovery in 2009, it would seem that the Compare() function internally uses an equality operation rather than a comparison operation. 这是PerlMagick中的一个已知问题,自2009年被发现以来一直没有得到解决,似乎Compare()函数在内部使用了相等操作而不是比较操作。 Maybe call the CLI utility from in your perl script? 也许从您的perl脚本中调用CLI实用程序?

use strict;
use warnings;

my $difference = `compare -metric RMSE -fuzz 15% first.png second.png null: 2>&1`;
my $diffAmount = $difference =~ m/\([\d.]*\)/;

if ($diffAmount == 0) {
    print "Yay\n";
}

You can work around the issue of fuzz not working by extracting error data from the difference image. 您可以通过从差异图像中提取错误数据来解决绒毛不起作用的问题。 Here is a routine I have used in comparison tests. 这是我在比较测试中使用的例程。

sub cmp_image {
    my ( $result_img, $expect_img, $max_error, $test_name ) = @_;

    my $difference_img = $expect_img->Compare( 
       image => $result_img,
       metric=>'rmse' );

    ok( $difference_img->Get('error') < $max_error, $test_name )
        or diag "Error metric: " . $difference_img->Get('error');
}

Unfortunately, this approach does not help you if you want to view the locations of errors, as even smallest differences between the images will be drawn in $difference_img . 不幸的是,如果您想查看错误的位置,这种方法无济于事,因为即使图像之间的最小差异也将在$difference_img绘制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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