我正在尝试K-均值图像压缩,但出现此错误
Command PrecompileSwiftBridgingHeader failed with a nonzero exit code
我的代码:
File "C:/Users/[user]/PycharmProjects/project/CompressMe.py", Line23, in <module>
final[pixel_centroids == cluster_no] = cluster_centers[cluster_no]
ValueError: shape mismatch: value array of shape (4,) could not be broadcast to indexing result of shape (267049,3)
答案 0 :(得分:0)
初始化“ final”数组时,将png输出通道的数量硬编码为3,这可能与输入不同。更正以下几行:
final = np.zeros((pixel_centroids.shape[0], img_np.shape[2]))
和
comp_image = final.reshape(img_np.shape[0], img_np.shape[1], img_np.shape[2])