首页 > 技术文章 > Python 图像保存与复制

JunzhaoLiang 2020-01-03 14:33 原文

import matplotlib.image as img
import os
from shutil import copyfile

path = 'D:\_Data\GTC_t1'
savePath = 'D:\_Data\GTC_t1_selected'

img_list = os.listdir(path)

for i in img_list:
    t1 = img.imread(path+'\\'+i, 'gray')
    if t1.shape == (256, 170):
        img.imsave(savePath+'\\'+i, t1, cmap='gray') # 1
        
        copyfile(path+'\\'+i,savePath+'\\'+i) # 2

用matplotlib复制.png,源图像(256,170),保存图像(256,170,4)
需要用copyfile来保持单通道

推荐阅读