开发者

ImageMagick: How to compare original PNG to lossy JPEG?

开发者 https://www.devze.com 2023-03-07 02:15 出处:网络
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 开发者_高级

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.


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 the compare command is not available in im4java, so you must modify im4java to support it.


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:

 compare \
       -verbose \
       -debug coder \
       -log "%u %m:%l %e" \
        orig1.png \
        orig2.jpeg \
       -compose src \
        diff.png

This command takes 2 images as input: orig1.png and orig2.jpeg. It produces diff.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:

 compare \
       -verbose \
       -debug coder \
       -log "%u %m:%l %e" \
        orig1.png \
        orig2.jpeg \
       -compose difference \
        diff.png

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:

 compare \
       -verbose \
       -debug coder \
       -log "%u %m:%l %e" \
        orig1.png \
        orig2.jpeg \
       -compose difference \
        x:


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:

composite image1.ext image2.ext -compose difference diff.png

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消