当前位置: 首页>>技术问答>>正文


“diff”是否存在图像?

, ,

问题描述

您可以使用diff轻松比较两个文本文件,甚至可以更好地与meld进行比较:

image-processing,diff,ubuntu

如果您对图像使用diff,则会得到如下示例:

$ diff zivi-besch.tif zivildienst.tif 
Binary files zivi-besch.tif and zivildienst.tif differ

这是一个例子:

原始来自http://commons.wikimedia.org/wiki/File:Tux.svg

image-processing,diff,ubuntu

编辑:

image-processing,diff,ubuntu

我为这两个图像添加了白色背景并应用了GIMP “Difference”过滤器来获取:

image-processing,diff,ubuntu

这是一个非常简单的方法,一个差异可以如何工作,但我可以想象更好(和更复杂)的。

你知道一个程序适用于像meld那样的图像用于文本吗?

(如果一个程序存在可以给出一个百分比(0%相同的图像 – 100%相同的图像)我也会对它感兴趣,但我正在寻找一个给我视觉暗示差异的程序。)

最佳解决办法

是的,这样的程序存在!

ImageMagick具有compare实用程序,它有多种比较图像的方法。

要安装它:

sudo apt-get install imagemagick imagemagick-doc

直观地比较两个图像:

compare -compose src tux_orig.png tux_modified.png tux_difference.png

tux_orig.png& tux_modified.png

image-processing,diff,ubuntu

image-processing,diff,ubuntu

给出这个图像:

image-processing,diff,ubuntu

通过指标比较两个图像:

通过某些指标输出差异的方法也很多,例如:

# compare -verbose -metric PSNR tux_orig.png tux_modified.png tux_difference.png
tux_orig.png PNG 200x232 200x232+0+0 8-bit sRGB 20.6KB 0.000u 0:00.000
tux_modified.png PNG 200x232 200x232+0+0 8-bit sRGB 22.2KB 0.010u 0:00.000
Image: tux_orig.png
  Channel distortion: PSNR
    red: 19.5485
    green: 19.5973
    blue: 19.6507
    alpha: 16.1568
    all: 18.4517
tux_orig.png=>tux_difference.png PNG 200x232 200x232+0+0 8-bit sRGB 12.3KB 0.030u 0:00.020

一些指标选项:

AE     absolute error count, number of different pixels (-fuzz effected)
FUZZ   mean color distance
MAE    mean absolute error (normalized), average channel error distance
MEPP   mean error per pixel (normalized mean error, normalized peak error)
MSE    mean error squared, average of the channel error squared
NCC    normalized cross correlation
PAE    peak absolute (normalize peak absolute)
PSNR   peak signal to noise ratio
RMSE   root mean squared (normalized root mean squared)

有许多方法可以比较图像,有关其他方法,请参阅ImageMagicks section on compare

次佳解决办法

这个问题在2012年被问到,现在是2017年。我们现在有了non-open-source程序Beyond Compare来比较图像,它集成到Nautilus中。我们一直有Geeqie在整个目录结构中寻找相似的图像(递归)。

I.发现超越比较的图像差异

单击此链接到download Beyond Compare .deb软件包。

通过转到你下载软件包的目录安装软件包,输入:sudo dpkg -i YourPackageName.deb,此时名为bcompare-4.2.2.22384_amd64.deb,所以你输入:sudo dpkg -i bcompare- 4.2.2.22384_amd64.deb

要完成安装并使插件在Nautilus中工作,您需要注销,然后重新登录,因为即使您没有打开Nautilus,Nautilus也会在后台运行。

一旦安装并且插件正常工作,您:

  1. 打开Nautilus,然后浏览到第一张图片

  2. Right-click第一个显示上下文菜单的图像,并选择选择左文件进行比较/合并

  3. 浏览到第二张图片

  4. Right-click第二个图像,然后选择Compare to ‘NameOfFirstImageFile’,其中NameOfFirstImageFile是您在步骤2中选择的文件的名称。

  5. 然后图像将在Beyond Compare中打开,它看起来像这样:

image-processing,diff,ubuntu

II。使用Geeqie查找相似/重复的图像

  1. 通过将其绑定到终端来安装Geeqie:sudo apt install geeqie

  2. 打开Geeqie,然后浏览到要扫描的目录。

  3. Right-click您要扫描的目录的名称,然后选择查找重复项…以仅扫描该目录,或选择查找重复项递归…以扫描该目录及其下的所有目录。

image-processing,diff,ubuntu

  1. 使用左下角的比较按drop-down列表,您可以选择按校验和,按文件名或相似级别查找重复项。如果您有裁剪,旋转或调整大小的图像,相似功能非常棒,当我们裁剪/调整图片大小以便在社交媒体等上发布时,您不再需要像我们许多人那样获得这些图像。

第三种解决办法

  1. openimageio-tools中有命令idiff

  2. 有命令perceptualdiff(包perceptualdiff)。

  3. 有命令uprightdiff(包uprightdiff)。

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/1952.html,未经允许,请勿转载。