資源簡介
將某一文件夾的所有類型的圖片文件全部轉變為灰度圖片。
代碼片段和文件信息
#?coding=utf-8
#?author??yyy??2018/11/28
#?彩色圖片變為灰度圖片
from?PIL?import?Image
import?os
import?os.path
file_path?=?‘C:/Users/yyy/Desktop/test2/‘
def?main():
????global?start_num
????start_num?=?0
????files?=?os.listdir(file_path)
????print(len(files))
????if?not?os.path.exists(file_path?+?‘gray‘):
????????os.mkdir(file_path?+?‘gray‘)
????while?(start_num?????????pic_path?=?file_path+files[start_num]
????????img?=?Image.open(pic_path)
????????if?img?is?None:
????????????break
????????#?模式L”為灰色圖像,它的每個像
- 上一篇:Python 爬蟲
- 下一篇:UWB中的chan算法
評論
共有 條評論