[PYTHON] Is it possible to detect similar images only with ImageHash?

Introduction

ImageHash has a Hamming distance of ** 0 ** for the same image, and ** 1-10 ** for potentially similar images. Reconfirm whether similar images can be detected only with ImageHash.

Source code

Hash uses dhush.

reference: https://tech.unifa-e.com/entry/2017/11/27/111546

sample.py


import imagehash
from PIL import Image

hash1 = imagehash.dhash(Image.open('./images/001.png'))
hash2 = imagehash.dhash(Image.open('./images/002.png'))
hash3 = imagehash.dhash(Image.open('./images/003.png'))

print(hash1, hash2, hash3)

print('001.png:002.png - {}'.format(hash1 - hash2))
print('001.png:003.png - {}'.format(hash1 - hash3))
print('002.png:003.png - {}'.format(hash2 - hash3))

Image used

The following images are used in this program. 002.png and 003.png choose similar images, 001.png has a different pose, but the composition with the character in the center is the same.

1 2 3
001.png 002.png 003.png
001.png 002.png 003.png

Execution result

The Hamming distances of 001.png and other images are 16 and 12, respectively, which are very different. The Hamming distance of 002.png and 003.png is 8. Normally, "1 to 10" are potentially similar images, but since they are completely different images, it can be said to be a false positive. As mentioned in Posted the other day, it can be said that it is difficult to judge similar images only with Image hash.

3868e0f870706979 a269e8e8f0f4f070 b860e0e8f1f0f070
001.png:002.png - 16
001.png:003.png - 12
002.png:003.png - 8

Recommended Posts

Is it possible to detect similar images only with ImageHash?
Is it possible to create an infinite length "non-repeating character string" with only three types of characters? [BFS] [DFS]
After all it is wrong to cat with python subprocess.
Made it possible to convert PNG to JPG with Pillow of Python
Make it possible to output a log to a file with go echo
When it is troublesome to copy what you built with vue
I tried to find out if ReDoS is possible with Python
Is it possible to enter a venture before listing and make a lot of money with stock options?
Is it possible to build a loop structure with a person whose city name and mayor's name are confusing?
I tried to implement deep learning that is not deep with only NumPy
When you want to use it as it is when using it with lambda memo
It is better to use Weight Initializer when initializing with HeNormal with Chainer
Is it possible to eat by forecasting stock prices by machine learning [Machine learning part 1]
Read CSV file with Python and convert it to DataFrame as it is
Is it possible to extract the person's profile information from the chat log?
I want to detect objects with OpenCV
Is it deprecated to use pip directly?
Learn to colorize monochrome images with Chainer
Python to remember only with hello, worlds
Add images to iOS photos with Pythonista
Add Gaussian noise to images with python2.7
Upload images to Google Drive with Python
It is more convenient to use csv-table when writing a table with python-sphinx
[OpenCV] When you want to check if it is read properly with imread
Is it possible to eat stock price forecasts by machine learning [Implementation plan]