Python图像处理库Pillow(PIL)简介

官方教程:https://pillow.readthedocs.io/en/stable/handbook/tutorial.html

之后再写教程

 读取图片转换格式并保存

import os
import shutil
from PIL import Image
import numpy as np

root_dir = 'F:/BaiduNetdiskDownload/COVID-19CTSeg/AutoML/patients_40/all/pngs/label/'
files_name = [os.path.splitext(i)[0] for i in os.listdir(root_dir)]
for file in files_name:
    print(file)
    outfile = file + ".png"
    img = Image.open(root_dir+file+'.png')
    img = img.convert('L')
    img.save(outfile)

# im = Image.open('1.2.840.473.8013.20200205.1163533.624.4664.24-2d7925d091984ca5ae3f115b70071678-100.png')
# print(im.mode)

 

posted @ 2020-04-11 01:07  DuanYongchun  阅读(402)  评论(0编辑  收藏  举报