Recently doing work there need a place to go to compute the similarity between the given different image, the image is on its essence is a 3-dimensional matrix of RGB data, know this feature in the future, a lot of similarity calculation method gradually being proposed and implemented, and here I realized for specific applications to name a few similarity calculation methods I used, the following is a specific code to achieve:
#!usr/bin/env python
#encoding:utf-8
from __future__ import division
'''
__Author__:沂水寒城
功能: 图片相似度计算方法集合
《python实现常用的相似度计算方法》可以看我之前的文章:
https://yishuihancheng.blog.csdn.net/article/details/89927608
里面有常用相似度计算方法的原理讲解与代码实现
'''
import os
import cv2
import sys
import numpy as np
from numpy import *
from PIL import Image
from sklearn import metrics
from matplotlib import pyplot as plt
from skimage.measure import compare_ssim
from scipy.stats import pearsonr,spearmanr,kendalltau
if sys.version_info==2:
reload(sys)
sys.setdefaultencoding('utf-8')
def image2Vector(img):
'''
图像向量化处理
'''
vec_list=[]
for i in range(3):
for one in img[i].tolist():
vec_list+=[O/255 for O in one]
return vec_list
def pearsonrSimilarity(image1, image2):