Page 1 of 1
fastest way to create a `diff` image from two source images?
Posted: 2010-05-27T20:14:24-07:00
by rdil
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...
Re: fastest way to create a `diff` image from two source ima
Posted: 2010-05-27T20:29:22-07:00
by snibgo
I don't know the fastest, but a highly convenient method is:
convert A.gif B.gif -compose Change-mask -composite d.png
Re: fastest way to create a `diff` image from two source ima
Posted: 2010-05-27T21:06:41-07:00
by rdil
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.
Re: fastest way to create a `diff` image from two source ima
Posted: 2010-05-27T21:19:13-07:00
by snibgo
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?
Re: fastest way to create a `diff` image from two source ima
Posted: 2010-05-27T21:24:45-07:00
by rdil
ah, i had the input files reversed

. thanks.
Re: fastest way to create a `diff` image from two source ima
Posted: 2010-05-27T21:29:47-07:00
by rdil
oh, one other quick question: is there a way to make the output image a tiff? the input images are gifs.
Re: fastest way to create a `diff` image from two source ima
Posted: 2010-05-27T21:30:50-07:00
by fmw42
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.
Re: fastest way to create a `diff` image from two source ima
Posted: 2010-05-27T21:44:00-07:00
by snibgo
is there a way to make the output image a tiff?
Just give the output filename an extension of ".tiff" or ".tif".
Re: fastest way to create a `diff` image from two source ima
Posted: 2010-05-31T20:17:24-07:00
by anthony
fmw42 wrote:If you want to binarize the result so that black=same and white=difference, then
Code: Select all
convert image1 image2 -compose difference -composite -threshold 0 result
That can still loose information due to the greyscalign operation!
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
See Using difference to Compare images...
http://www.imagemagick.org/Usage/compare/#difference