python将灰度图转换为RGB彩色图
生活随笔
收集整理的這篇文章主要介紹了
python将灰度图转换为RGB彩色图
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
代碼如下:
from PIL import Image import ospath = r'圖片存儲的路徑' newpath = r'轉換后存儲圖片的路徑'def RGBtoGray(path):files = os.listdir(path)for file in files:imgpath = path + '/' + file#print(imgpath)#im = Image.open(imgpath).convert('RGB')#resize將圖像像素轉換成自己需要的像素大小img = im.resize((512, 512))dirpath = newpathfile_name, file_extend = os.path.splitext(f)dst = os.path.join(os.path.abspath(dirpath), file_name + '.jpg')img.save(dst) if __name__ == "__main__":RGBtoGray(path)總結
以上是生活随笔為你收集整理的python将灰度图转换为RGB彩色图的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PYTORCH:DenseNet做新冠肺
- 下一篇: python将图片转换为灰度图