图片的相似度,jaccard_similarity_score和precision_score不足够

时间:2019-02-12 14:44:58

标签: python scikit-learn

我目前正在努力解决以下问题: 我想将一些图像(B + C,通过算法生成)与一个图像(A,用户生成)进行比较。结果,我想得到一些数字,表示B或C代表最佳图片A。

Jaccar和准确性有点起作用(即使计算结果完全相同)。但是B的图像肯定没有像我想要的那样匹配A,但是仍然获得很高的amout分数(0.94)。图片C获得0.99,应该是这样。图片B的得分应该非常低。

我该如何解决?我想它必须用灰色做一些事情(127,127,127)。好像B匹配了A的大量灰色像素

Picture B

Gets a high score but is not that what i wanted

good example, gets the highest score

from PIL import Image
import numpy as np
import glob
from sklearn.metrics import jaccard_similarity_score, accuracy_score

def get1DArray(img_path):
    return np.array(Image.open(img_path).convert("RGB")).flatten()

org = get1DArray("/path/to/file/user.png")
files = []
for file in glob.glob('/path/to/file/*png'):
    if "org" not in file and "user" not in file:        
        files.append([file[file.rfind("/")+1:],get1DArray(file)])

for file in files:
    print("Name: {} Score: {}".format(file[0],jaccard_similarity_score(org,file[1])))

for file in files:
    print("Name: {} Score: {}".format(file[0],accuracy_score(org,file[1])))

0 个答案:

没有答案