ImageMagick difference image generation hack

A forum to ask questions, post setups, and generally discuss anything having to do with photomacrography and photomicroscopy.

Moderators: rjlittlefield, ChrisR, Chris S., Pau

blekenbleu
Posts: 146
Joined: Sat May 10, 2008 5:37 pm
Location: U.S.
Contact:

ImageMagick difference image generation hack

Post by blekenbleu »

ImageMagick is IMO powerful and useful, but not always easy for me, despite being moderately comfortable with a terminal command line.
This is a hack to display pixel-by-pixel differences between 2 images, typically registered.
ImageMagick offers an example image differencing invocation:

Code: Select all

magick composite img1.jpg img2.jpg -compose difference diff.jpg
...but
  • small differences are nearly black, displaying poorly
  • differences are also absolute; gray - blue == blue - gray
https://imagemagick.org/Usage/compare/#difference

This invocation results in middle gray for no difference, with gray - blue = yellow:

Code: Select all

magick CZP_Helicon_Comparison_H.jpg.crdownload CZP_Helicon_Comparison_C.jpg.crdownload -compose Mathematics -define compose:args="0,-1,1,.5" -composite ugoo.jpg
.. where those first two images are from https://www.photomacrography.net/forum/ ... 643#p37643
and resulting ugoo.jpg is this:
ugoo.jpg
Documentation for ImageMagick Composition Mathematics:
https://imagemagick.org/Usage/compose/#mathematics

Pretending neither to type reliably nor remember that syntax,
I hacked an dimg shell script that expects 3 filenames
and created an alias for invoking it.
https://blekenbleu.github.io/ImageProcessing/dimg.html

A next step involves hacking a utility to register image pairs,
given images of mismatched magnifications and/or orientations.
Metaphot, Optiphot 1, 66; AO 10, 120, and EPIStar 2571
https://blekenbleu.github.io/microscope

MarkSturtevant
Posts: 1946
Joined: Sat Nov 21, 2015 6:52 pm
Location: Michigan, U.S.A.
Contact:

Re: ImageMagick difference image generation hack

Post by MarkSturtevant »

The image looks a lot like a Nomarski DIC picture. Interesting.
Mark Sturtevant
Dept. of Still Waters

blekenbleu
Posts: 146
Joined: Sat May 10, 2008 5:37 pm
Location: U.S.
Contact:

Re: ImageMagick difference image generation hack

Post by blekenbleu »

MarkSturtevant wrote:
Tue Aug 16, 2022 4:34 pm
like a Nomarski DIC picture
Now that you mention it, comparing images that differ mostly in how sharpened, then mostly edges differ.
Here is a difference image from @RobertOToole's M-Componon 4/28 vs Componon 4/28 corner crop pair:
https://www.photomacrography.net/forum/ ... 25&t=38831
diff.jpg
These were first aligned using Hugin's utility:

Code: Select all

$ align_image_stack.exe -C -a al -m left.jpg right.jpg
$ dimg *.tif diff.jpg
magick al0000.tif al0001.tif -compose Mathematics -define compose:args="0,-1,1,.5" -composite diff.jpg
... where left.jpg and right.jpg had first to be cropped to exactly the same pixel dimensions.
Whatever warping was done by align_image_stack presumably compromised both similarly...
Here is difference for unaligned images:
dun.jpg
Metaphot, Optiphot 1, 66; AO 10, 120, and EPIStar 2571
https://blekenbleu.github.io/microscope

Post Reply Previous topicNext topic