python 中如何将RGB图像模式转为灰度?

 时间:2026-02-12 09:18:43

1、安装pil 扩展,如果没有安装。

pip install pillow

2、安装后,直接引用

from PIL import Image

3、img = Image.open(r'D:/cat.jpg')

4、grey = img.convert('L')

参数L,代表灰度

5、grey.save('D:/grey.jpg')

将转换后的灰度图像对象存储。

python 中如何将RGB图像模式转为灰度?

6、img.show() 原图查看

grey.show()更改为灰色模式后图查

更新模式前后效果比较。

python 中如何将RGB图像模式转为灰度?

  • 销售怎么找客户资料
  • int和Integer的区别
  • 如何在QQ群中分享图片
  • 中国式幸福家庭的七要素
  • exercises什么单词怎么读
  • 热门搜索
    青岛旅游景点 雅安旅游 开封旅游攻略 汉中旅游 瓦屋山旅游攻略 峨眉山旅游 普吉岛旅游 安康旅游 无锡旅游 桂林旅游攻略