输出结果
代码实现
def Cosin(self, img_pat1, img_pat2):
image1 = Image.open(img_pat1)
image2 = Image.open(img_pat2)
image1 = self.get_thum(image1)
image2 = self.get_thum(image2)
image1_array = np.array(image1)
images = [image1, image2]
vectors = []
norms = []
for image in images:
vector = []
for pixel_tuple in image.getdata():
vector.append(average(pixel_tuple))
vectors.append(vector)
norms.append(linalg.norm(vector, 2))
vectors_array=np.array(vectors)
a, b = vectors
a_array=np.array(a)
a_norm, b_norm = norms
res = dot(a / a_norm, b / b_norm)
return res