6

Follow up on “Diff” an image using ImageMagick

When you are working with forms (as opposed to images), the changes are very hard to see with this technique. I wanted to show some type of yellow highlight maybe 10-20 pixels "bigger" (padding) around the actual pixels that changed.

So instead of just this

enter image description here

Something more like this

enter image description here

It seems like I am just missing something here in the stack that can make this work.

convert '(' file1.png -flatten -grayscale Rec709Luminance ')' \ '(' file2.png -flatten -grayscale Rec709Luminance ')' \ ... here ? ... '(' -clone 0-1 -compose darken -composite ')' \ ... or here ? ... -channel RGB -combine diff.png

I can also run this as separate commands and does not need to be fast, most of this is going to be run offline.

I also tried studying the technique here (specifically how the thumbnail scaling gives you the effect I want as the pixels get expanded) but this code is using the library instead of the ImageMagick command line tools. Line 248 => "make the red as visible as possible"

https://github.com/vslavik/diff-pdf/blob/master/diff-pdf.cpp#L218

An example form is the standard W-9. I made 2 subtle changes

  • PART II .. moved the 2. left about 2 pixels
  • PART II .. on 4., moved word is to the right 2 pixels

enter image description here

enter image description here

and the compare pumps out this (changes in red that you can barely see)

enter image description here

Thank you for any help

1 Answer 1

7

You can use -morphology dilate in Imagemagick to increase the size of the red areas. For example, using your two forms:

convert JW0wZ.png 1nHWT.png -compose difference -composite -morphology dilate disk:10 +level-colors black,red result.gif

enter image description here

UPDATE:

If you want the background transparent, then try

convert JW0wZ.png 1nHWT.png -compose difference -composite -morphology dilate disk:10 +level-colors "black,red" -fuzz 20% -transparent black result.png

enter image description here

Or better

convert JW0wZ.png 1nHWT.png -compose difference -composite -morphology dilate disk:10 -alpha copy -background red -alpha shape result2.png

enter image description here

Update 2: Here is how to overlay a 50% yellow marking onto you two originals. Change the value as desired. I create a difference image and dilate the white. Then I create a 50% yellow image. Then I composite each of the originals with the yellow using the difference image as a mask. See https://www.imagemagick.org/Usage/compose/#compose

convert JW0wZ.png 1nHWT.png \
\( -clone 0,1 -compose difference -composite -morphology dilate disk:10 \) \
\( -clone 0 -fill yellow -colorize 100 -channel a -evaluate set 50% +channel \) \
\( -clone 0,3,2 -compose over -composite +write 1.png \) \
\( -clone 1,3,2 -compose over -composite +write 2.png \) \
null:

enter image description here

enter image description here

To view this, if on Unix and have X11 installed, you can do

animate -delay 20 -resize 50% 1.png 2.png
Sign up to request clarification or add additional context in comments.

9 Comments

cool, then I can probably use something along the lines of -transparent black -fill "rgba(255, 215, 0, 0.1)" -opaque red to use this as an overlay on one of the original images for the yellow highlight ... the yellow-ish rgba(...) is showing as opaque and not doing the 10% :(
See my appended answer.
thank you @fmw42 ... getting closer. I have to get some time to figure out the overlaying this red with transparent background into the actual image of the form itself and making the red into 30% alpha-channel yellow so you can still see the text below. Thank you for your help! I just realized you are Fred's Imagemagick scripts (nice avatar too) fmwconcepts.com/imagemagick/morphology/index.php
See my second UPDATE to show you how to do the yellow overlay. Please consider an up-vote if this has been helpful.
I need to find a way to buy you a beer or something (I'm serious) ... I really appreciate you taking the time to help me out. I am pretty sure it would've taken me at least 10+ hours to figure this out. I know you are retired and all and not need money but maybe I can send you a check for a couple hundred dollars?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.