Page 1 of 1

difference between two files

Posted: 2015-05-14T06:08:37-07:00
by geoland
Hi.

I am attempting to show the difference between two files, image1 and image2, where image1 contains image2.

Image1 is "the image" and image2 is fixed pattern noise. I want to remove the fixed pattern noise with a template, which is image2

I'm new to imagemagick and this has me stumped.

If I apply the code below, I finish up with what looks very much like image2, when in fact what I want is what is left of image1 - image1 contains image2 - sounds like subtraction, but this too has me stumped.

Code: Select all

composite  image1 image2 -compose difference diff
Subtraction should work, but is not ideal because I have a series of images that are almost identical but not exactly. If I apply the following code the images combine with blurring because the images are not exactly aligned - and I don't want them to be. I want to return separate images for further processing, to be combined some time later.

Code: Select all

files=(*.tiff); for f in "${files[@]}"; do composite *.tiff MBIAS.tiff -compose Minus_Dst "$f"; done 
Is there a better way of doing this? I have attempted numerous commands without success - difference seems the logical approach. If I understand difference correctly.

This is a pixel math problem, but I would like to find a similar solution in imagemagick.

Re: difference between two files

Posted: 2015-05-14T09:47:42-07:00
by fmw42
compose difference is absolute value subtraction. See http://www.imagemagick.org/Usage/compose/#difference.

I would suggest you use convert ... -composite rather than composite. composite is old and may be deprecated in IM 7.

You might find that using compare is better. See
http://www.imagemagick.org/script/compare.php
http://www.imagemagick.org/Usage/compare/

Re: difference between two files

Posted: 2015-05-22T19:22:55-07:00
by geoland
Thanks fwm42.

I must admit to getting a little bit lost in the jargon.

Using a real world example, I came up with the following using convert. I think this is correct; that is, the bias is subtracted from the frame (light, flat whichever) leaving the frame minus its bias.

Code: Select all

convert frame.tiff bias.tiff -compose Minus_Dst -composite frame-bias.tiff
EDIT: should be

Code: Select all

convert frame.tiff bias.tiff -compose Minus_Src -composite frame-bias.tiff
Similarly a frame divided by a flat. But I am not getting what I expect to see; that is, removal of vignetting, dust motes etc.

Code: Select all

convert frame.tiff flat.tiff -compose Divide_Src -composite frame-divided-by-flat.tiff
I have tried swapping the image order and using _Dst instead of _Src. Not sure where I am going wrong? Now resolved...

Using convert instead of composite to overcome merging of the images out of alignment. But I can't seem to properly flat-field the frames.

EDIT: The problem I have discovered is batch processing. If I apply the lines above to single images the results are very good, excellent.

Code: Select all

files=(light*.tiff); for f in "${files[@]}"; do convert light*.tiff MDARK_$NAME.tiff -compose Minus_Src -composite "$f"; done
Returns weird results - I need to process each image separately and preferably return the result to the original image as with mogrify, but it doesn't like the options I am using.

Re: difference between two files

Posted: 2015-05-25T11:45:03-07:00
by fmw42
The order of the images with compose minusXXX is like swapped when using composite -compose and when using convert -compose ... -composite. See the syntax change at http://www.imagemagick.org/Usage/compose/#compose.

Not sure what you want. If you want pixels that are different between the two images, then -compose difference is better and you can then -threshold the result to get a mask image. If you want only pixels that are brighter in one image than the other, then -compose minus (with the correct ordering of the two images) should do that and thresholded for the mask.

Using compare -metric XX does what you may want automatically. See http://www.imagemagick.org/Usage/compare/#methods for examples of some of the above.

Re: difference between two files

Posted: 2015-05-25T12:07:30-07:00
by snibgo

Code: Select all

files=(light*.tiff); for f in "${files[@]}"; do convert light*.tiff MDARK_$NAME.tiff -compose Minus_Src -composite "$f"; done
I don't do much bash, but that looks wrong to me. Insert "-verbose" or "-debug all" after "convert" to see what arguments are being passed to convert.