各位好哥哥们,在学习Kmeans图片压缩时遇到了这一段代码,整体读起来特别困难,能不能帮忙解释一下
compressed_palette = estimator.cluster_centers_
print(compressed_palette)
a = np.apply_along_axis(func1d=lambda x: np.uint8(compressed_palette[x]), arr=cluster_assignments, axis=0)
img = a.reshape(src_shape[0], src_shape[1], depth)
print(compressed_palette[0, 0])
threshold = (compressed_palette[0, 0] + compressed_palette[1, 0]) / 2
img[img[:, :, 0] > threshold] = 255
img[img[:, :, 0] < threshold] = 0
cv2.imshow('sd0', img)
不知道你这个问题是否已经解决, 如果还没有解决的话: