difference image only if the images are different

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Freddie20000
Posts: 4
Joined: 2018-08-05T05:50:09-07:00
Authentication code: 1152

difference image only if the images are different

Post by Freddie20000 »

Hey,

I'm new and found no solution for my problem.
I only want a difference image, when my images are different. The only way currently for me is to start compare two times..
first with null at the end and read out the exit code... and if it is 1, I have to restart with a valid diff image.

Thanks in advance
Freddie
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: difference image only if the images are different

Post by snibgo »

You could run compare once, making the difference image, then delete it if you don't want it.
snibgo's IM pages: im.snibgo.com
Freddie20000
Posts: 4
Joined: 2018-08-05T05:50:09-07:00
Authentication code: 1152

Re: difference image only if the images are different

Post by Freddie20000 »

Yes... that option I thought about as well... but I want to be sure that there's no smarter way ... more parameter wise :-)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: difference image only if the images are different

Post by fmw42 »

You could compare the mean and standard deviation or the image histograms or a perceptual hash as a quick test. If they are not exactly the same, then do your Imagemagick compare. This is not 100% reliable, but should work most of the time to identify identical images.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: difference image only if the images are different

Post by snibgo »

Fredie20000 wrote:but I want to be sure that there's no smarter way...
IM has no options for conditionally writing an image. The command either writes, or it doesn't.

If your concern is performance: comparing two images is quick, needing just one pass through the images. Writing is fairly fast provided there is no compression. Wring PNG is fairly slow.
snibgo's IM pages: im.snibgo.com
Post Reply