Page 1 of 1

difference image only if the images are different

Posted: 2018-08-05T05:53:50-07:00
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

Re: difference image only if the images are different

Posted: 2018-08-05T07:07:36-07:00
by snibgo
You could run compare once, making the difference image, then delete it if you don't want it.

Re: difference image only if the images are different

Posted: 2018-08-05T10:01:46-07:00
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 :-)

Re: difference image only if the images are different

Posted: 2018-08-05T10:45:59-07:00
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.

Re: difference image only if the images are different

Posted: 2018-08-05T12:02:53-07:00
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.