PHP .png 线稿比较

发布于 2024-11-24 03:18:46 字数 618 浏览 2 评论 0原文

几天来,我一直在执行一项涉及使用 PHP 进行图像比较的任务。我开始认为 PHP 不适合完成此类任务。

目标

使用一个基础,将新的线条艺术与其进行比较,并返回它们之间的百分比差异。 我尝试了几种方法来解决这个问题:比较像素数的差异(这并不能真正解决线条艺术差异的目标),使所有重叠的像素变白,并找到没有透明度/颜色的像素白色并除以底部的非透明像素(似乎没有得到正确的数字)

这是一个示例:

Base在此处输入图像描述

-- -- -- -- -- -- -- --基础 -- -- -- -- -- -- -- -- -- -- -- -- 艺术线条 -- -- -- -- -- -- --

百分比差异应在 54% 左右。然而,我尝试过的所有方法都无法接​​近这一点。(~5%)

我的问题是:可以/如何在 PHP 中完成此操作? 谢谢!

图片© Aywas.com

For a couple days now, I've been stuck on a task involving image comparison using PHP. I'm beginning to think that PHP isn't the language to do this sort of task.

The Objective:

Use a base, compare a new line-art to it, and return the percentage difference between them.
I've tried a couple ways of going about this: Compare the differences in pixel count (which doesn't really solve the goal of line-art difference), make all pixels that overlap, white, and find pixels without transparency/the color white and divide by non-transparent pixels in the base (which doesn't seem to get the correct number)

Here's an example:

Baseenter image description here

-- -- -- -- -- -- -- -- Base -- -- -- -- -- -- -- -- -- -- -- Line-Art -- -- -- -- -- -- --

The percentage difference should be around 54%. However, none of the ways I've tried get close (~5%) to this.

My question is: Can/How can this be done in PHP?
Thanks!

Images © Aywas.com

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

睡美人的小仙女 2024-12-01 03:18:46

您可以尝试使用 ImageMagick 函数 compareimagechannels(),仅使用黑色通道?

编辑:这是一个基本尝试及其输出。您也许能够操纵输出数字来计算出阈值。图片 1 和 2 是线条艺术,图片 3 是调整为 200x200 的 Google 标题徽标。

$img1 = new Imagick('image1.png');
$img2 = new Imagick('image2.png');
$img3 = new Imagick('image3.png');

$diff12 = $img1->compareImageChannels($img2,
             Imagick::CHANNEL_ALL, Imagick::METRIC_MEANABSOLUTEERROR);
$diff13 = $img1->compareImageChannels($img3,
             Imagick::CHANNEL_ALL, Imagick::METRIC_MEANABSOLUTEERROR);

print_r($diff12);
print_r($diff13);

输出:

Array
(
    [0] => Imagick Object
        (
        )

    [1] => 1512.25385625
)
Array
(
    [0] => Imagick Object
        (
        )

    [1] => 24353.6380375
)

You might try using the ImageMagick function compareimagechannels(), using only the black channel?

Edit: Here's a basic attempt, and its output. You might be able to manipulate the output numbers to figure out your thresholds. Images 1 and 2 are the line art and image 3 is the Google header logo resized to 200x200.

$img1 = new Imagick('image1.png');
$img2 = new Imagick('image2.png');
$img3 = new Imagick('image3.png');

$diff12 = $img1->compareImageChannels($img2,
             Imagick::CHANNEL_ALL, Imagick::METRIC_MEANABSOLUTEERROR);
$diff13 = $img1->compareImageChannels($img3,
             Imagick::CHANNEL_ALL, Imagick::METRIC_MEANABSOLUTEERROR);

print_r($diff12);
print_r($diff13);

Output:

Array
(
    [0] => Imagick Object
        (
        )

    [1] => 1512.25385625
)
Array
(
    [0] => Imagick Object
        (
        )

    [1] => 24353.6380375
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文