How to Create a Diff of Two Images

When I was a child, I loved looking for Waldo in the “Where’s Waldo?” book series. These days I’m a sucker for TMZ’s “What’s the Big Frigin Difference” images, where TMZ slightly changes an image and you have to spot the differences between the two. That got me to thinking — how easily could I […]

The post How to Create a Diff of Two Images appeared first on David Walsh Blog.


This content originally appeared on David Walsh Blog and was authored by David Walsh

When I was a child, I loved looking for Waldo in the “Where’s Waldo?” book series. These days I’m a sucker for TMZ’s “What’s the Big Frigin Difference” images, where TMZ slightly changes an image and you have to spot the differences between the two. That got me to thinking — how easily could I automate diff’ing two images? This StackOverflow post was gold.

To create a diff of two similar images, we’ll use ImageMagick’s convert command line utility with a large host of configurations:

convert '(' image1.png -flatten -grayscale Rec709Luminance ')' \
        '(' image2.png -flatten -grayscale Rec709Luminance ')' \
        '(' -clone 0-1 -compose darken -composite ')' \
        -channel RGB -combine diff.png

How effective is this command with its configuration arguments? Let’s have a look:

Original Image

Modified Image

Diff’ed Image

The diff image result is pretty informative! The size of the sunglasses is clearly presented, and if you look closely, you can see one skull at the top-right of the shirt has been flipped.

Whatever your reason for wanting to identify the difference two images, ImageMagick’s convert tool is impressive. You can do a million things with ImageMagick; check out my Media tutorials to learn more awesome ways to modify images, videos, and audio!

The post How to Create a Diff of Two Images appeared first on David Walsh Blog.


This content originally appeared on David Walsh Blog and was authored by David Walsh


Print Share Comment Cite Upload Translate Updates
APA

David Walsh | Sciencx (2023-01-30T11:32:51+00:00) How to Create a Diff of Two Images. Retrieved from https://www.scien.cx/2023/01/30/how-to-create-a-diff-of-two-images/

MLA
" » How to Create a Diff of Two Images." David Walsh | Sciencx - Monday January 30, 2023, https://www.scien.cx/2023/01/30/how-to-create-a-diff-of-two-images/
HARVARD
David Walsh | Sciencx Monday January 30, 2023 » How to Create a Diff of Two Images., viewed ,<https://www.scien.cx/2023/01/30/how-to-create-a-diff-of-two-images/>
VANCOUVER
David Walsh | Sciencx - » How to Create a Diff of Two Images. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/01/30/how-to-create-a-diff-of-two-images/
CHICAGO
" » How to Create a Diff of Two Images." David Walsh | Sciencx - Accessed . https://www.scien.cx/2023/01/30/how-to-create-a-diff-of-two-images/
IEEE
" » How to Create a Diff of Two Images." David Walsh | Sciencx [Online]. Available: https://www.scien.cx/2023/01/30/how-to-create-a-diff-of-two-images/. [Accessed: ]
rf:citation
» How to Create a Diff of Two Images | David Walsh | Sciencx | https://www.scien.cx/2023/01/30/how-to-create-a-diff-of-two-images/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.