我试图将图像分成n个相等的部分,然后比较每个块以定义一个"均衡"在插图中。 例如,在下图所示的图像中,与顶部相比,底部往往相似。
我写过这篇文章,但是我被困住了,不知道该怎么做,有什么帮助吗?
import math
import io
import numpy as np
from sklearn.cluster import KMeans
from PIL import Image
import image_slicer
from scipy import sum, average
tiles = image_slicer.slice('img/eq1.jpg', 2, save=False)
vectors = []
for tile in tiles:
image = tile.image
image = image.convert('RGB')
colors = np.array(image).tolist()
colors = [average(x, -1) for x in colors][0]
vectors.append(colors)
#lista = np.array(tile.image)
#print np.array(tile.image)
image.show()
from sklearn.metrics.pairwise import cosine_similarity
print cosine_similarity(vectors)
答案 0 :(得分:0)
好吧我解决了这个问题:
import math
import io
import numpy as np
from sklearn.cluster import KMeans
from PIL import Image
import image_slicer
from scipy import sum, average
from scipy.linalg import norm
import sklearn.metrics.pairwise
tiles = image_slicer.slice('img/ad.jpg', 4, save=False)
vectors = []
for tile in tiles:
image = tile.image
image = image.convert('RGB')
colors = np.array(image).tolist()
colors = [average(x, -1) for x in colors][0]
vectors.append(colors)
#lista = np.array(tile.image)
#print np.array(tile.image)
# image.show()
from sklearn.metrics.pairwise import cosine_similarity
print np.around(sklearn.metrics.pairwise.manhattan_distances(vectors))