ImageMagick:如何比较原始 PNG 和有损 JPEG?
我想将原始 PNG 图像与有损 JPEG 图像进行比较,看看丢失了多少。我发现我可以使用 ImageMagic 来比较图像。我更喜欢使用 Java (im4java)。我对他们的文档感到非常困惑(http://www.imagemagick.org/script/compare.php)。它没有描述它适用于哪个平台。如何使用这些命令行?它们在 im4java 中是否可用?如果有人可以写出我如何使用它的步骤,我将不胜感激。
I want to compare original PNG image to lossy JPEG image to see how much I am loosing. I found that I can use ImageMagic to compare images. I prefer using Java (im4java). I am very confused with their documentation (http://www.imagemagick.org/script/compare.php). It doesn't describe which platform it is for. How do I use these command lines and are they even available in im4java? If someone can write steps on how I use it I will appreciate it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
ImageMagick 在许多平台上运行。如果您单击二进制版本,它们会列出可用的软件包。正如其主页所述,im4java 库调用 ImageMagick 命令行工具来完成其工作,因此它可以在支持 ImageMagick 和 Java 的任何平台上运行。浏览其 API 文档,看起来
compare
命令不是im4java 中可用,因此您必须修改 im4java 才能支持它。ImageMagick runs on many platforms. If you click Binary Releases, they have a listing of available packages. The
im4java
library, as its home page describes, calls the ImageMagick command line tools to do its work, so it will run on any platform that supports both ImageMagick and Java. Browsing through its API documentation, it looks like thecompare
command is not available in im4java, so you must modify im4java to support it.那么为什么不能直接使用ImageMagick命令行工具呢?
请注意,只有当两个图像的像素尺寸(宽度 x 高度)相同时,借助“比较”来比较两个不同的图像才会产生有意义的结果。
compare
进行逐像素比较。我的做法如下:
此命令采用 2 个图像作为输入:
orig1.png
和orig2.jpeg
。它生成diff.png
作为输出。它还为您提供了一些关于 stdout 的调试信息。输出图像的所有像素都为红色,这些像素在输入之间有所不同。另一种可能性是这个修改后的命令:
它以另一种方式可视化差异。您也可以不将差异写入文件,而是告诉 Compare 打开一个窗口并在屏幕上显示差异:
So why can't you use the ImageMagick commandline tool directly?
Note, that comparing 2 different images with the help of
compare
only leads to meaningfull results if the two do have the same dimensions (Width x Height) in terms of pixels.compare
does a comparison that is done pixel by pixel.Here's how I would do it:
This command takes 2 images as input:
orig1.png
andorig2.jpeg
. It producesdiff.png
as output. It also gives you some debugging info on stdout. The output image has all pixels colored in red which are different between the inputs.Another possibility is this modified command:
It visualizes the differences in another way. You could also not write the differences to a file, but tell compare to open a window and display the differences on screen:
我的博客文章更多关于 JPEG 质量ImageMagick 和 Lightroom 有什么区别,但您可以找到有用的命令行来进行所需的比较:
确保使用 .png(或 .gif 或其他无损格式)作为输出图像,因为首先您对差异感兴趣,而 .jpg 会将其扭曲为照片。
My blog entry is more about JPEG quality and what is the difference of ImageMagick and Lightroom, but you can find the helpful command line that does the required comparison:
Ensure that you use .png (or .gif or other lossless format) as the output image, because first of all you are interested in the difference, and .jpg would distort it as a photo.