# 改变图片位深度
import matplotlib.image as mpimg
from PIL import Image
import os
def reshapeFile(img_Dir):
img_pathDir = os.listdir(img_Dir) # 提取所有文件名,并存在列表中
for i in img_pathDir:
print(i)
img_path = 'D:/xxxxx/pythonProject/test/' + i
img = mpimg.imread(img_path)
if img.shape[2] > 3:
img = Image.open(img_path)
save_img = img.convert('RGB')
save_img.save(img_path)
return
if __name__ == '__main__':
img_Dir = r'D:\xxxxxx\pythonProject\test\' #本地文件路径
reshapeFile(img_Dir)
Python批量转换图片位深度
最新推荐文章于 2024-07-22 02:47:46 发布