python - 使用欧氏距离显示图像

标签 python opencv

我正在使用python和opencv(cv2)做一个项目。在这里,我分别计算数据集的图像的红色,绿色和蓝色均值,还计算GLCM(对比度,能量,同质性和相关性)并将其保存在其他列表中。现在,我已经计算出查询图像与DB图像之间的欧式距离,但是我无法显示最小距离的图像。
我已经部分完成了代码,就像:

import cv2
from collections import *
import CBIR as cb
import experiment as ex
from scipy.spatial import distance
from matplotlib import pyplot as plt

result_list = list()
i = 0
a_list = list()
b_list = list()
a_list.append(ex.feature_matrix_ip)
while i < 50:
   b_list.append(cb.feature_matrix_db[i])
   dist = distance.euclidean(a_list,b_list[i])
   result_list.append(dist)
   result_list_sort = OrderedDict(sorted(enumerate(result_list),key=lambda x: x[0])).keys()
   i = i + 1
result_list.sort()
res_list_sort = zip(result_list,result_list_sort)

CBIR给出了DB图像的GLCM(对比度,能量,均匀性和相关性)的红色,绿色和蓝色平均值,实验将给出查询图像的值。

如何显示图像。欢迎任何建议

谢谢!

最佳答案

您可以使用numpy函数以最少的计算一次获得DB图像和查询图像之间的欧式距离。

#let DB_matrix be the database and queryImage be the query image values

values = np.square(np.linalg.norm(DB_matrix - queryImage, axis=1))
minValIndex=np.argmin(values)

#This will give you the index of the min euclidean distance image from the queryDB.

关于python - 使用欧氏距离显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59554712/

相关文章:

C++重新定义现有类的输出流

python - 检查单元测试中是否调用了Timer.cancel

python - 元组列表计算元组的最小-最大日期差异

python - Python 的 Oauth1.0 API 问题

python - 用 python 和 re 清理文本

python - 从图像中识别矩阵

OpenCV 连续速度测量使用相机

c++ - 我可以用 opencv 提供的函数替换这个插值函数吗?

opencv - 在 OpenCV 中查找点集的轮廓

python - Pandas :DataFrame.sum() 或 DataFrame().as_matrix.sum()