Java 一种简单的方法(工具?)来比较不同格式的图像像素?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/691799/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 18:24:43  来源:igfitidea点击:

An easy way (tool?) to compare images pixel for pixel in different formats?

javaimageimage-processingcomparisonjpeg

提问by joinJpegs

Well I've written a basic lossless jpeg joiner thing in java now but I'd like to compare the files it produces with the original files.

好吧,我现在已经用 Java 编写了一个基本的无损 jpeg 连接器,但我想将它生成的文件与原始文件进行比较。

I can only compare so much in a hex editor, does anyone know of an easy way, software or java based (preferably software as I dont feel like any more coding for now!) that I can compare two images and produce a "difference map" of where the pixels aren't the same?

我只能在十六进制编辑器中进行这么多比较,有没有人知道一种简单的方法,软件或基于 Java 的(最好是软件,因为我现在不想再编码了!)我可以比较两个图像并生成“差异图” “哪里像素不一样?

Thanks.

谢谢。

采纳答案by joinJpegs

Thanks for the suggestions.

感谢您的建议。

I tried the Gimp approach first which works well except when the difference between the images are very small. I couldn't find an "enhance differences" option to make the differences obvious and the histogram also only gives a rough representation of the differences.

我首先尝试了 Gimp 方法,该方法效果很好,除非图像之间的差异非常小。我找不到“增强差异”选项来使差异变得明显,直方图也只能粗略地表示差异。

In the end I used ImageMagicksomething I'd installed a while ago and forgot all about. Creating a difference/comparison image is as easy as typing:

最后,我使用了ImageMagick之前安装的东西,但忘记了。创建差异/比较图像就像输入一样简单:

 compare first.jpg second.png difference.gif

in the command line.

在命令行中。

It's all nicely explained here.

这一切都很好地解释here。

回答by Doug

Use an image editor like Photoshop or the Gimp or whatever, which has multiple layers. Create an image where each source image in a separate layer.

使用像 Photoshop 或 Gimp 之类的具有多层的图像编辑器。创建一个图像,其中每个源图像都位于单独的图层中。

At this point, you can visually compare the images by toggling the top layer's visibility off and on.

此时,您可以通过关闭和打开顶层的可见性来直观地比较图像。

In most decent editors, you can also set the top layer to "difference" mode. Now each image pixel's value is the absolute difference of the pixel values in the underlying images. You can use e.g. a histogram tool to see if the images are identical. If they're identical, then all the pixel values will be exactly 0.

在大多数不错的编辑器中,您还可以将顶层设置为“差异”模式。现在每个图像像素的值是底层图像中像素值的绝对差。您可以使用例如直方图工具来查看图像是否相同。如果它们相同,则所有像素值都将恰好为 0。

回答by Norman Ramsey

For stuff like this, I love the netpbm/pbmplustoolkit. You can use djpegand pnmtoplainpnmto convert each image into a simple ASCII format. You then just read both files and emit a new image which shows where pixels differ. You could, for example, compute the Euclidean distance in RGB space between old and new pixels and emit a white pixel for zero difference, light gray for a small difference, darker for larger differences, and so on. The ASCII format is simple and is well documented on the man pages, and all the standard viewer programs can view it directly.

对于这样的东西,我喜欢netpbm/pbmplus工具包。您可以使用djpegpnmtoplainpnm将每个图像转换为简单的 ASCII 格式。然后您只需读取这两个文件并发出一个新图像,该图像显示像素不同的位置。例如,您可以计算旧像素和新像素之间 RGB 空间中的欧几里得距离,对于零差异发出白色像素,对于小差异发出浅灰色,对于较大差异发出较暗像素,等等。ASCII 格式很简单,并且在手册页中有详细说明,所有标准查看器程序都可以直接查看它。

回答by Mark Simpson

You could do a lot worse than Perceptual Diff.

你可以做得比Perceptual Diff差很多。

回答by Narcissus

The latest version of Araxis Merge will do image diffs ( http://www.araxis.com/merge/topic_comparing_image_files.html).

最新版本的 Araxis Merge 将进行图像差异 ( http://www.araxis.com/merge/topic_comparing_image_files.html)。

Unfortunately it's not a free app so whether or not you're willing to pay for it is another thing...

不幸的是,它不是一个免费的应用程序,所以你是否愿意为它付费是另一回事......

回答by mjn

TortoiseIDiff is a free image diff viewer:

TortoiseIDiff 是一个免费的图像差异查看器:

http://tortoisesvn.tigris.org/TortoiseIDiff.html

http://tortoisesvn.tigris.org/TortoiseIDiff.html

It is part of TortoiseSVN, but can be used without Subversion.

它是 TortoiseSVN 的一部分,但可以在没有 Subversion 的情况下使用。

Depending on your project, not all files which are under version control are text files. Most likely you will have images too, for example screenshots and diagrams for the documentation/helpfile.

For those files it's not possible to use a common file diff tool, because they only work with text files and diff line-by-line. Here is where the Tortoise Image Diff tool (TortoiseIDiff) comes to the rescue. It can show two images side-by-side, or even show the images over each other alpha blended.

根据您的项目,并非所有受版本控制的文件都是文本文件。您很可能也会有图像,例如文档/帮助文件的屏幕截图和图表。

对于这些文件,不可能使用通用的文件差异工具,因为它们仅适用于文本文件和逐行差异。这就是 Tortoise Image Diff 工具 (TortoiseIDiff) 派上用场的地方。它可以并排显示两个图像,甚至可以显示彼此 alpha 混合的图像。

回答by Bryan Mackenzie

The best approach would be to use Pix for windows (comes with the DirectX SDK). Supports Bitmap, PNG and Jpeg...Enjoy!

最好的方法是使用 Pix for windows(随 DirectX SDK 一起提供)。支持位图、PNG 和 Jpeg...享受吧!

回答by Pavel Vladov

There's also a convenient web app called Resemble.js, which analyzes and compares images pixel by pixel. The different pixels in the images (if any) are highlighted with pink or yellow color depending on your preference.

还有一个名为 Resemble.js的便捷网络应用程序,它可以逐个像素地分析和比较图像。根据您的喜好,图像中的不同像素(如果有)以粉红色或黄色突出显示。