Yesterday I read a few comments saying that Opus can’t compare images beyond their properties or available metadata. While that’s partially true, I have to say Opus is extremely extendable through scripting.
So I set out to learn a bit about image comparison. So I browsed a lot of websites on the topic and got especially interested in the discussions around the algorithms mentioned in here—including the comments.
In the end, I went with pHash. Even though dHash is often said to be the better option, in my implementation it just didn’t give the results I was hoping for.
The challenge was to develop or port some of those algorithms using pure JScript, with minimal use of third-party tools (except Opus), and ideally sticking to tools that come with Windows. Also, no temporary files allowed.
That led me to dig deeper and discover that Windows does have some (outdated) scripting capabilities for image processing. It can't convert an image to grayscale, though, so I had to come up with a manual workaround!
To keep this short, here’s a test version of a script that compares two images and shows their similarity percentage. The closer the value is to 0, the more alike the images are.
To use it, first install the script.
PhotoComparer.opusscriptinstall (5.2 KB)
Then, just select a couple of images (at least two) and run PhotoComparer
.
You can also drag and drop images onto the dialog—whichever side you drop it on will be used to compare against the image on the opposite side.
Note 1: Shoutout to everyone who’s shared their image comparison algorithms—especially the one from here, which was the main barebones inspiration for my pHash implementation.
Note 2: Because of the way resizing and grayscale conversion is handled, results will definitely differ from more advanced tools. Just keep in mind this is a proof of concept made by an Opus enthusiast.
Note 3: The script can’t recognize rotated images as similar. From what I read, it looks like none of the three main algorithms can handle that either. Also, it only works with image formats supported by Windows' WIA implementation—as far as I know, that includes PNG, BMP, JPG, and GIF.
Note 4: This script is a test project. I’m sharing it here to exchange ideas, get suggestions, and hear your feedback. If it turns out to be useful, it could definitely be expanded to compare batches of images and, for example, export the results to an Opus duplicate collection. And hey, maybe we can even save a few bucks by not buying yet another piece of software—and just add one more handy tool to the Opus toolbox!