import matplotlib.image as mpimg
from PIL import Image
def bit_depth_convert():
img_path = r'图片位置'
img = mpimg.imread(img_path)
print('img_shape', img.shape)
"""
获取位深
im = Image.open(img_path)
print(im.getbands())
"""
'''
位深:(1、L、P、RGB等全是str类型)
1:1位像素,表示黑和白,但是存储的时候每个像素存储为8bit。二值化图
L:8位像素,表示黑和白。 灰度图
P:8位像素,使用调色板映射到其他模式。
RGB:3x8位像素,为真彩色。
RGBA:4x8位像素,有透明通道的真彩色。
CMYK:4x8位像素,颜色分离。
YCbCr:3x8位像素,彩色视频格式。
I:32位整型像素。
F:32位浮点型像素。")
'''
if img.shape[2] > 3:
img = Image.open(img_path)
save_img = img.convert('RGB') # 转换位24位
save_img.save('转换后图片位置')
if __name__ == '__main__':
bit_depth_convert()
python的matplotlib模块实现图片位深的转化
最新推荐文章于 2024-05-19 23:31:32 发布