[PYTHON] I compared the identity of the images by Hu moment

Overview

"I compared the images of Kantai Collection with the index of Hu Moment."

About Hu Moment

The Hu moment invariant was used as the index to compare the images. Image moment - Wikipedia(en)

The Hu moment takes an invariant value with respect to image rotation and scaling. The implementation is included in OpenCV, so you can use it as is.

Also, the Python implementation is based on the following. Image reading is cv2.IMREAD_GRAYSCALE. Reference: Search for similar images by Hu moment invariant

Example

The image set was borrowed from @kiguchiyura's KanColle Icon Summary [Free Icon].

matome.png

Snowstorm Kumano Thunder Den Shigure Shigure改二 Oi Kai Oi Kai二 Z1 Z3
Snowstorm 0.00 12.45 5.78 5.02 12.63 12.94 9.07 9.02 3.94 4.04
Kumano 12.45 0.00 8.08 9.76 0.73 0.94 3.71 3.72 9.02 9.29
Thunder 5.78 8.08 0.00 9.32 8.14 8.08 4.82 4.76 9.67 9.66
Den 5.02 9.76 9.32 0.00 10.03 10.07 6.40 6.33 1.73 8.47
Shigure 12.63 0.73 8.14 10.03 0.00 0.46 4.15 4.16 9.13 9.13
Shigure Kaiji 12.94 0.94 8.08 10.07 0.46 0.00 4.54 4.55 9.53 9.53
Oi Kai 9.07 3.71 4.82 6.40 4.15 4.54 0.00 0.08 5.53 12.41
Kaiji Oi 9.02 3.72 4.76 6.33 4.16 4.55 0.08 0.00 5.46 12.40
Z1 3.94 9.02 9.67 1.73 9.13 9.53 5.53 5.46 0.00 7.23
Z3 4.04 9.29 9.66 8.47 9.13 9.53 12.41 12.40 7.23 0.00

The two reformers such as Shigure and Oi look exactly the same before and after the remodeling, so it makes sense. On the other hand, the reason why thunder and electricity look very similar but there is a big difference is probably because of the difference in hair color. The reason why the biggest difference between Shigure Kaiji and Snowstorm may be the same. Since I am reading the image in grayscale this time, it may be a little closer if RGB etc. are taken into consideration.

Compare different images

ikaduti.pngikaduti_r.pngikaduti_s.pngikaduti_sc.pngikaduti_sc2.png

Thunder(original) Thunder(rotation) Thunder(Dialogue change) Thunder(Reduction / transparency of margins) Thunder(Reduction / margin filling)
Thunder(original) 0.00 0.16 0.29 0.03 5.88
Thunder(rotation) 0.16 0.00 0.39 0.13 5.96
Thunder(Dialogue change) 0.29 0.39 0.00 0.31 5.71
Thunder(Reduction / transparency of margins) 0.03 0.13 0.31 0.00 5.90
Thunder(Reduction / margin filling) 5.88 5.96 5.71 5.90 0.00

Only the sample with the reduced margins filled with white is judged as a different image. I wonder why.

AHDu0cq.pngWJqqUHV.png Image Source: Using Waifu2x to Upscale Japanese Prints

img1.png img2.png
img1.png 0.00 0.05
img2.png 0.05 0.00

A comparison of images converted by waifu2x. Since the original image is the same, it is almost the same value. As an aside, it is John Resig (the developer of jQuery) who reports this ukiyo-e transformation. ([Wikipedia](http://en.wikipedia.org/wiki/%E3%82%B8%E3%83%A7%E3%83%B3%E3%83%BB%E3%83%AC%E3% 82% B7% E3% 82% B0)))

Building an environment to compare Hu moments at hand

I think that more interesting results will be obtained depending on the sample, so I will summarize the execution procedure for Windows. You can make the same comparison by introducing Python2, numpy, and OpenCV.

Preparing for installation

I used Chocolatey as a package management tool. It's like the Windows version of apt-get or yum. Software with Nuget packages registered can be entered with a single chocolatey command and managed collectively.

OpenCV installation

Simply download and unzip the installer from the Official Distribution Page. It's very easy. This time I have installed 3.0.0-rc1.

Python installation

Use chocolatey. There are two Python2 packages (python2 and python2-x86_32), but Python, which automatically works with numpy distributed by chocolatey, can be installed from the following command.

$ chocolatey install python2-x86_32
$ chocolatey install numpy

OpenCV import

Cv2.pyd located in OPENCV_FILE_PATH \ opencv \ build \ python \ 2.7 \ x64 Copy to C: \ Python27 \ Lib \ site-packages.

sample.py


import cv2
#code
print "hoge"

You should now be able to use cv2 on Python. Easy. Please try various things.

Postscript

Depending on the installation procedure and environment, PATH may not be set properly. In that case, C:\OPENCV_FILE_PATH\opencv-3.0.0\build\x64\vc11\bin C:\python2-x86_32 Try through the path to.

Recommended Posts

I compared the identity of the images by Hu moment
Optical Flow, the dynamics of images captured by OpenCV
What I saw by analyzing the data of the engineer market
I compared the calculation time of the moving average written in Python
I investigated the mechanism of flask-login!
[Introduction to Python] I compared the naming conventions of C # and Python.
I found out by analyzing the reviews of the job change site! ??
Can I pass the first grade of math test by programming?
I checked the usage status of the parking lot from satellite images.
I replaced the numerical calculation of Python with Rust and compared the speed
I tried to find the optimal path of the dreamland by (quantum) annealing
I tried to verify and analyze the acceleration of Python by Cython
I checked the number of closed and opened stores nationwide by Corona
I tried to verify the result of A / B test by chi-square test
Low-rank approximation of images by HOSVD step by step
Low-rank approximation of images by Tucker decomposition
I checked the contents of docker volume
I tried the asynchronous server of Django 3.0
I checked the options of copyMakeBorder of OpenCV
I summarized the folder structure of Flask
Face detection by collecting images of Angers.
I didn't know the basics of Python
Pandas of the beginner, by the beginner, for the beginner [Python]
The Python project template I think of.
I read the implementation of golang channel
I compared the speed of go language web framework echo and python web framework flask
I compared the speed of regular expressions in Ruby, Python, and Perl (2013 version)
I compared the moving average of IIR filter type with pandas and scipy
I tried to predict the presence or absence of snow by machine learning.
I tried to rescue the data of the laptop by booting it on Ubuntu
Reconstruction of moving images by Autoencoder using 3D-CNN
I tried the pivot table function of pandas
Classification of guitar images by machine learning Part 1
Check the operation of OpenCV3 installed by Anaconda
I tried cluster analysis of the weather map
I read the implementation of range (Objects / rangeobject.c)
I solved the deepest problem of Hiroshi Yuki.
Low-rank approximation of images by singular value decomposition
Sort the elements of the array by specifying the conditions
I checked the list of shortcut keys of Jupyter
I tried to touch the API of ebay
Low-rank approximation of images by HOSVD and HOOI
I tried to correct the keystone of the image
Try the free version of Progate [Python I]
I checked the session retention period of django
I tried using the Datetime module by Python
I checked the processing speed of numpy one-dimensionalization
Minimize the number of polishings by combinatorial optimization
Judging the finish of mahjong by combinatorial optimization
I touched some of the new features of Python 3.8 ①
Classification of guitar images by machine learning Part 2
Search by the value of the instance in the list
I read and implemented the Variants of UKR
I want to customize the appearance of zabbix
I tried using the image filter of OpenCV
I tried to predict the price of ETF
I tried to vectorize the lyrics of Hinatazaka46!
The concept of reference in Python collapsed for a moment, so I experimented a little.
I compared the speed of the reference of the python in list and the reference of the dictionary comprehension made from the in list.
real-time-Personal-estimation (What should I do to prevent the estimation of images outside the category) * Failure.