Python 图像保存与复制

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来保持单通道

猜你喜欢

转载自www.cnblogs.com/JunzhaoLiang/p/12144779.html