fastest way to create a `diff` image from two source images?
fastest way to create a `diff` image from two source images?
hey, i have two source images that are the same dimensions and mostly the same content and i want to produce an output image that contains only the pixels that are different between the two images, the rest whited out or changed to a constant color. what is the fastest (in terms of time to process the images and create the output image) way to do this? I think I could write a pixel by pixel comparison script but there must be a faster way...
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: fastest way to create a `diff` image from two source ima
I don't know the fastest, but a highly convenient method is:
convert A.gif B.gif -compose Change-mask -composite d.png
convert A.gif B.gif -compose Change-mask -composite d.png
snibgo's IM pages: im.snibgo.com
Re: fastest way to create a `diff` image from two source ima
i'm not sure exactly what that does but it doesn't do what i'm talking about. the output image contains some sort of merging of the two input files. the pixels that are the same in both are still there but at a different gradient, as are the pixels that differ.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: fastest way to create a `diff` image from two source ima
Perhaps you can post a sample pair of input files, and the command you use, and tell us which IM version you are using.
My command creates output pixels where:
- if the input pixels are the same, creates a transparent pixel;
- if the input pixels are different, uses the pixel from A.
If different pixels should use the pixel from B, just swap the input file names.
If identical pixels should produce a particular colour, use "-background {colour} -flatten".
Your requirement "an output image that contains only the pixels that are different between the two images" is a bit vague. Can you be more precise?
My command creates output pixels where:
- if the input pixels are the same, creates a transparent pixel;
- if the input pixels are different, uses the pixel from A.
If different pixels should use the pixel from B, just swap the input file names.
If identical pixels should produce a particular colour, use "-background {colour} -flatten".
Your requirement "an output image that contains only the pixels that are different between the two images" is a bit vague. Can you be more precise?
snibgo's IM pages: im.snibgo.com
Re: fastest way to create a `diff` image from two source ima
ah, i had the input files reversed
. thanks.

Re: fastest way to create a `diff` image from two source ima
oh, one other quick question: is there a way to make the output image a tiff? the input images are gifs.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: fastest way to create a `diff` image from two source ima
perhaps this will work?
convert image1 image2 -compose difference -composite result
The pixels that are exactly the same will be black and the others the difference in colors. You could recolor the exact values to some color if you want using
-fill somecolor -opaque black.
cyclops:

cyclops with red dot in middle:

diff image

If you want to binarize the result so that black=same and white=difference, then
convert image1 image2 -compose difference -composite -threshold 0 result
binarized diff image

http://www.imagemagick.org/Usage/compose/#difference
and
http://www.imagemagick.org/Usage/compare/#difference
Perhaps you can provide a link to a pair of images and your expected result.
convert image1 image2 -compose difference -composite result
The pixels that are exactly the same will be black and the others the difference in colors. You could recolor the exact values to some color if you want using
-fill somecolor -opaque black.
cyclops:

cyclops with red dot in middle:

diff image

If you want to binarize the result so that black=same and white=difference, then
convert image1 image2 -compose difference -composite -threshold 0 result
binarized diff image

http://www.imagemagick.org/Usage/compose/#difference
and
http://www.imagemagick.org/Usage/compare/#difference
Perhaps you can provide a link to a pair of images and your expected result.
Last edited by fmw42 on 2010-05-27T22:21:51-07:00, edited 3 times in total.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: fastest way to create a `diff` image from two source ima
Just give the output filename an extension of ".tiff" or ".tif".is there a way to make the output image a tiff?
snibgo's IM pages: im.snibgo.com
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: fastest way to create a `diff` image from two source ima
That can still loose information due to the greyscalign operation!fmw42 wrote:If you want to binarize the result so that black=same and white=difference, thenCode: Select all
convert image1 image2 -compose difference -composite -threshold 0 result
The way to get a binary image of changed pixels is to add the channels togather before thresholding.
Code: Select all
convert image1.png image2.png -compose difference -composite
-channel RGBA -separate +channel \
-compose plus -background black -flatten \
-threshold 0 bgnd_mask.png
http://www.imagemagick.org/Usage/compare/#difference
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/