Python图像处理 PIL中convert函数的mode总结
2023-03-14 22:31:29 时间
1. img = img.convert()
PIL有九种不同模式: 1
,L
,P
,RGB
,RGBA
,CMYK
,YCbCr
,I
,F
。
1.1 img.convert('1')
为二值图像,非黑即白。每个像素用8个bit表示,0表示黑,255表示白。
代码示例
from PIL import Image
def convert_1():
image = Image.open("D:/pytorch_code/pytorch_study/fusion_datasets/1.jpg")
image_1 = image.convert('1')
image.show()
image_1.show()
1.2 img.convert('L')
转化为灰度图像,每个像素用8个bit表示,0表示黑,255表示白,其他数字表示不同的灰度。
转换公式:L = R * 299/1000 + G * 587/1000+ B * 114/1000。
代码示例
from PIL import Image
def convert_L():
image = Image.open("D:/pytorch_code/pytorch_study/fusion_datasets/1.jpg")
image_L = image.convert('L')
image.show()
image_L.show()
对比上图可以发现,1
模式得到图顿点很多,有点像高斯噪声的感觉,而L
模式更平滑一些。
1.3 img.convert('P')
代码示例
from PIL import Image
def convert_P():
image = Image.open("D:/pytorch_code/pytorch_study/fusion_datasets/1.jpg")
image_P = image.convert('P')
image.show()
image_P.show()
相关文章
- 图像处理工具Python扩展库,你了解吗?
- 十个常用的损失函数解释以及Python代码实现
- 30 个数据科学工作中必备的 Python 包
- 如何在 Windows 上安装 Python
- 几行 Python 代码就可以提取数百个时间序列特征
- 使用Python快速搭建接口自动化测试脚本实战总结
- 哪种编程语言最适合开发网页抓取工具?
- 不要在 Python 中使用循环,这些方法其实更棒!
- 震惊!用Python探索《红楼梦》的人物关系!
- 如何最简单、通俗地理解Python模块?
- 酷炫,Python实现交通数据可视化!
- 为什么急于寻找Python的替代者?
- 30 个数据工程必备的Python 包
- 去字节面试被面这题能答上来吗?谈谈你对时间轮的理解?
- 火山引擎在行为分析场景下的 ClickHouse JOIN 优化
- 用Python爬取了某宝1166家月饼数据进行可视化分析,终于找到最好吃的月饼~
- 在 Linux 上试试这个基于 Python 的文件管理器
- Python列表解析式到底该怎么用?
- 如何快速把你的 Python 代码变为 API
- 十个Python初学者常犯的错误