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

2025-03-21 11:32:32

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图像模式转为灰度
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢