Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Comparing two images

  • Please log in to reply
7 replies to this topic
  • Members
  • 16 posts
  • Last active:
  • Joined: 22 Mar 2013



I want to know how is it possible to compare two images in order to know if there the same or not

For example I want to compare Img1 (in X directory ) with Img2 (in Y directory).


Thank you



  • Members
  • 997 posts
  • Last active:
  • Joined: 10 Apr 2012
Did you search the forum? http://www.autohotke...mparing-images/

  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Try this:
MsgBox % Memory_Compare(img1,img2)
  return VarSetCapacity(mem2)=DllCall("ntdll\RtlCompareMemory","PTR",&mem1,"PTR",&mem2,"PTR",len?len:VarSetCapacity(mem2))

  • Members
  • 935 posts
  • Last active: Jun 07 2014 07:40 AM
  • Joined: 18 Jan 2013
for an exact match both would have to be the same size and shape and every pixel would have to be an identical match to the corresponding pixel in the other one. once you have the images you could for example load one into mspaint and do an image compare with the other one. or you could do a byte-by-byte comparison of the two with a binary file read on both files then try comparing the two in-memory areas.
Before you do though you might want to take a look at this article.

Never assume evil intent when simple ignorance will suffice. Ignorance is an eventually curable condition with the right education. Evil intent, however, is another matter entirely. Scripts are much like children. Simple to conceive. Difficult, expensive, and time-consuming to raise. Often do the opposite of what you expect them to. Require frequent  "correction". And once they leave home you can't control them anymore. But you love them anyway.

  • Members
  • 304 posts
  • Last active: Jan 12 2017 09:11 PM
  • Joined: 28 Mar 2011

You can also try 3rd program, BeyondComapre.

  • Members
  • 1704 posts
  • Last active: Nov 19 2015 11:58 AM
  • Joined: 10 Mar 2011

  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009

This whole thing also reminds me of an interesting script: http://www.autohotke...-in-two-images/


Antonio Fran├ža -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.

  • Members
  • 27 posts
  • Last active: Jul 31 2017 06:50 AM
  • Joined: 19 Nov 2012
(Replying to old thread sorry)
For all you googlers like me with the same problem, I have come up with a somewhat simple workaround to finding duplicate images.
At first I was using the file size to determine if 2 images were the same. But 1 out of every 1000 or so you'll come across an image that isn't duplicate but share the same file size, flagging a false result. I tried the MD5 hash technique but I was still getting the same hash result somehow.
So then I tried to read the contents of the file to a variable and compare. But even after using a FileRead *c or *t or every other combination of this command, I could only get the first few binary characters of the file which is identical to every other image.
To circumvent this, I did a "Loop Read" of the image and FileAppended every line back to a text file. Then compared the filesizes again. This however takes a long time when reading every line of an image when you have thousands to go through. So first I short listed the results into groups of %filesize%.txt files... Which is hard to explain in writing so here is the code: (Ughhhh i get a dark screen in 3 different browsers when press the code format button. If a mod can please convert this into code I appreciate it thanks).
; Part 1 of Duplicate image checking - File Sizes
Loop, pages\images\*.*
FileAppend, %A_LoopFileName%`n, pages\images\sizes\%A_LoopFileSize%.txt ; contents of sizes txt file contains the name of the image file
Loop, pages\images\sizes\*.txt ; cycle through sizes files
file = %A_LoopFileName%
Loop Read, pages\images\sizes\%file% ; read lines of file
If A_Index > 1
FileCopy, pages\images\sizes\%file%, Duplicate-%file%
; Part 2 of Duplicate image checking - Contents Check
Loop, Duplicate*
file = %A_LoopFileName%
Loop Read, %file%
imagefile = %A_LoopReadLine%
Loop Read, pages\images\%imagefile%
FileAppend, %A_LoopReadLine%, %imagefile% ; reading and then writing binary data from the image to a text file
Loop, *.jpg
FileAppend, %A_LoopFileName%`n, Checked-%file%-%A_LoopFileSize%.txt ; if the binary data is different then the file sizes are different
FileDelete *.jpg
; Part 3 - Final Check - everything that is in FinalCheck* are the actual duplicate images
Loop, Checked*
file = %A_LoopFileName%
Loop Read, %file% ; read lines of file
If A_Index > 1
FileCopy, %file%, FinalCheck-%file%