PIL.Image的简单使用
来源:互联网 发布:淘宝助理打印机没反应 编辑:程序博客网 时间:2024/05/22 13:24
PIL:Python Imaging Library,是Python平台上的一个图像处理标准库。PIL功能非常强大,但API却非常简单易用。
安装PIL
在Debian/Ubuntu Linux下直接通过apt安装:
$ sudo apt-get install python-imaging
PIL官方手册网址:http://effbot.org/imagingbook/
一个简单的读取图片并显示的例子:
from PIL import Imageimport numpy as npimg_path = "./cat.59.jpg"im = Image.open(img_path)print(im.format) # 'JPEG'print(im.size) # (464, 331) (W,H)print(im.mode) # RGBprint(type(im)) # PIL.JpegImagePlugin.JpegImageFileim1 = im.convert('RGB') # PIL.Image.Image
im.show() # 显示图片,不会影响程序的运行。(在note book下直接输入im即可显示图像)
将彩色图片转成灰度
im_gray = im.convert("L")im_gray.show() # im_gray的类型为:PIL.Image.Image
或则:
im_CMYK = im.convert("CMYK")im_CMYK.show()
L代表亮度,为灰度图像。
RGB代表真彩色图像。
CMYK代表pre-press images
用Image.open读取图片,返回的是一个JpegImageFile实例。
直接输入im,不能查看图片中像素的值。
查看PIL.Image图片像素点的值
pix = im.load() # PixelAccesswidth = im.size[0]height = im.size[1]
pix[0,0] = (150, 141, 74) # 返回(0,0)处的RGB像素值
pix[width-1,height-1] = (183, 175, 128) # 返回右下角的RGB像素值
注:PIL.Image读取的图片,取值范围为:[0, 255]。且size为(W,H)形式。
pytorch中,torch.FloadTensor支持的取值范围为:[0, 1.0]。需要进行转换。
使用torchvision.transforms可以很方便的将PIL或则是Opencv读取的ndarray图像转换为torch.FloatTensor。
阅读全文
0 0
- PIL.Image的简单使用
- PIL:Image 和 cv2简单比较
- 使用python的PIL库简单的处理图像
- 使用 numpy 和 PIL 进行简单的图像处理
- 使用PIL Image裁切图片,制作缩略图代码
- Python PIL(Python Image Library)使用体会
- PIL 中的 Image 模块
- pil image插件地址
- PIL 中的 Image 模块
- PIL 中的 Image 模块
- PIL 中的 Image 模块
- PIL 中image
- Python3.4 PIL的使用
- PIL 的安装 及使用
- PIL 库的使用入门
- android Universal-Image-Loader的简单使用
- Android-Universal-Image-Loader的简单使用
- python图形处理库PIL(Python Image Library)的基本概念
- OpenCV Python calcOpticalFlowFarneback
- perl模块安装
- 不同vlan之间的通信
- 快速求和(炒鸡数据版)
- 树莓派配置usb无线网卡
- PIL.Image的简单使用
- 2144 数据结构实验之图论九:最小生成树
- 费曼技巧
- 总结--15个实用CSS属性
- 矩阵相乘和矩阵点乘
- 斐波那契数的实现与改进
- RevitAPI之关于Room、Area、Tag【比目鱼原创】
- HTML基础(1.head属性)
- java丨事件驱动程序设计学习笔记(二)