基于python的图像格式转换(将RGB图像转换为灰度图像)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/littlle_yan/article/details/79204544

1.将RGB图像转换为灰度图像:

from PIL import Image
I = Image.open('F:\\pycharm\\picture_format\\data\\lena.jpg')
I.show()
L = I.convert('L')
L.show()

输出图像结果图为:



2.将RGB图像转换为1模式图像:

from PIL import Image
I = Image.open('F:\\pycharm\\picture_format\\data\\lena.jpg')
I.show()
L = I.convert('1')
L.show()
输出结果图为:



猜你喜欢

转载自blog.csdn.net/littlle_yan/article/details/79204544