为了账号安全,请及时绑定邮箱和手机立即绑定

图像压缩后得到的灰度图像

图像压缩后得到的灰度图像

繁华开满天机 2021-07-02 14:07:36
我正在使用 K 均值聚类算法执行图像压缩。压缩后得到的图像是灰度图像,如何获得与原始图像质量相近的彩色图像?import osfrom skimage import iofrom sklearn.cluster import  MiniBatchKMeansimport numpy as npalgorithm = "full"for f in os.listdir('.'):    if f.endswith('.png'):        image = io.imread(f)        rows = image.shape[0]        cols = image.shape[1]        image = image.reshape(image.shape[0] * image.shape[1], image.shape[2])        kmeans = MiniBatchKMeans(n_clusters=128, n_init=10, max_iter=200)        kmeans.fit(image)        clusters = np.asarray(kmeans.cluster_centers_, dtype=np.uint8)        labels = np.asarray(kmeans.labels_, dtype=np.uint8)        labels = labels.reshape(rows, cols);        #  np.save('codebook'+f+'.npy', clusters)        io.imsave('compressed_' + f , labels);
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 125 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信