Is it possible to use ImageMagick to find duplicate images?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
samiejg
Posts: 2
Joined: 2014-02-11T10:07:19-07:00
Authentication code: 6789

Is it possible to use ImageMagick to find duplicate images?

Post by samiejg »

Like say for example if I had two files name kitten1.jpg and kitten2.jpg, and they were exactly the same image. is there anything with ImageMagick that will allow me to see if they are the same image?

I'm looking to make a PHP script that uses an "If statement" for if the image is a duplicate.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Is it possible to use ImageMagick to find duplicate imag

Post by snibgo »

Code: Select all

compare -metric RMSE kitten1.jpg kitten2.jpg NULL:
snibgo's IM pages: im.snibgo.com
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Is it possible to use ImageMagick to find duplicate imag

Post by magick »

For identical images, you'll get the same signature:
  • identify -verbose kitten.png kitten2.png | grep signature
    signature: 5c701306a9a985a0c93c8d11a1e761d7f863757
    signature: 5c701306a9a985a0c93c8d11a1e761d7f863757
Use -metric PHASH if you want to identify images that are similar or are the same image but resized, cropped, sharpened, etc.
samiejg
Posts: 2
Joined: 2014-02-11T10:07:19-07:00
Authentication code: 6789

Re: Is it possible to use ImageMagick to find duplicate imag

Post by samiejg »

magick wrote:For identical images, you'll get the same signature:
  • identify -verbose kitten.png kitten2.png | grep signature
    signature: 5c701306a9a985a0c93c8d11a1e761d7f863757
    signature: 5c701306a9a985a0c93c8d11a1e761d7f863757
Use -metric PHASH if you want to identify images that are similar or are the same image but resized, cropped, sharpened, etc.
Thanks a lot guys! This helps me a lot. BTW, I'm assuming grep wouldn't work on Windows? I'm using Xampp. Is there anything equivalent on the Xampp/windows version of imagemagick?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Is it possible to use ImageMagick to find duplicate imag

Post by snibgo »

Windows doesn't include a grep, but does have "findstr.exe", which can do this job. Of course, many Unix tools have ben ported to Windows.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Is it possible to use ImageMagick to find duplicate imag

Post by fmw42 »

There is a new compare metric as of IM 6.8.8.3 that does a perceptual hash to look for similar or identical images even if scaled. See http://www.fmwconcepts.com/misc_tests/p ... index.html
Post Reply