Python Imaging Library: ImageOps Module(图像运算模块)
2017-10-30 20:13
901 查看
Python Imaging Library: ImageOps Module(图像运算模块)
(版本1.1.3) ImageOps模块包含许多“现成的”图像处理操作。这个模块是实验性的,大多数操作符只支持“L”和“RGB”。
图像对比度最大化(规范化)。
该函数计算输入图像的直方图,根据截止百分比删除直方图中最亮和最暗的像素,
并对图像进行重排,使最黑的像素变为黑色(0),最亮的像素变为白色(255)。
灰度图像彩色化。
黑、白参数应该是RGB数组或颜色名称。
该函数计算一个颜色楔形,将源图像中的所有黑像素映射到第一个颜色,将所有的白色像素映射到第二个颜色。
从所有四边删除边框像素。这个函数适用于所有的图像模式。
使用给定的deobject对象来变形图像。
deobject对象应该提供一个getmesh方法,它返回一个适合于图像转换方法的网格(MESH)列表。
直方图均衡化。
该函数将非线性映射应用于输入图像,以在输出图像中创建灰度值的均匀分布。
向图像的所有四个边添加边框像素。
返回一个指定大小的裁剪版图像。size参数输出图像的大小,以(宽度,高度)元组表示。
method参数是指重新采样的方法。缺省值是图像最近邻方法。
bleed参数允许您删除图像外部的边框(从所有的四个边)。它的值是一个小数(用0.01表示1%)。默认值为0(没有边框)。
centering参数用于控制剪切位置。(0.5, 0.5) 是剪切中心。
(0.0,0.0)将从左上角开始。
(1.0,0.0)将从左下角开始。
垂直翻转图像(上到下)。
将图像转换为灰度值图像。
反转(取反)图像。
水平翻转图像(从左到右)。
减少每个颜色通道的位数。
将给定阈值之上所有像素值取反。
# 图像对比度最大化(规范化)(autocontrast)
# ImageOps.autocontrast(image, cutoff=0) ⇒ image
PilImg_Autocontrast1 = Image.open('图像5.jpg')
PilImg_Autocontrast = ImageOps.autocontrast(PilImg_Autocontrast1,
cutoff=0.9)
# PilImg_Autocontrast.show()
# 灰度图像彩色化(colorize)
# ImageOps.colorize(image, black, white) ⇒ image
PilImg_Colorize1 = Image.open('图像5.jpg').convert('L')
PilImg_Colorize = ImageOps.colorize(PilImg_Colorize1,
black=(100, 126, 189),
white=(56, 146, 231))
# PilImg_Colorize.show()
# 删除边框像素(crop)
# ImageOps.crop(image, border=0) ⇒ image
PilImg_Crop1 = Image.open('图像5.jpg').convert('L')
PilImg_Crop = ImageOps.crop(PilImg_Crop1, border=500)
# PilImg_Crop1.show()
# 直方图均衡化(equalize)
# ImageOps.equalize(image) ⇒ image
PilImg_Equalize1 = Image.open('图像5.jpg')
PilImg_Equalize = ImageOps.equalize(PilImg_Equalize1)
# PilImg_Equalize.show()
# 添加边框像素(expand)
# ImageOps.expand(image, border=0, fill=0) ⇒ image
PilImg_Expand1 = Image.open('图像5.jpg')
PilImg_Expand = ImageOps.expand(PilImg_Expand1, border=1, fill=1)
# PilImg_Expand.show()
# 垂直翻转图像(flip)
# ImageOps.flip(image) ⇒ image
PilImg_Flip1 = Image.open('图像5.jpg')
PilImg_Flip = ImageOps.flip(PilImg_Flip1)
# PilImg_Flip.show()
# 水平翻转图像(mirror)
# ImageOps.mirror(image) ⇒ image
PilImg_Mirror1 = Image.open('图像5.jpg')
PilImg_Mirror = ImageOps.mirror(PilImg_Mirror1)
# PilImg_Mirror.show()
# 将图像转换为灰度值图像(grayscale)
# ImageOps.grayscale(image) ⇒ image
PilImg_Grayscale1 = Image.open('图像5.jpg')
PilImg_Grayscale = ImageOps.grayscale(PilImg_Grayscale1)
# PilImg_Grayscale.show()
# 反转(取反)图像(invert)
# ImageOps.invert(image) ⇒ image
PilImg_Invert1 = Image.open('图像5.jpg')
PilImg_Invert = ImageOps.invert(PilImg_Invert1)
# PilImg_Invert.show()
# 减少每个颜色通道的位数(posterize)
# ImageOps.posterize(image, bits) ⇒ image
PilImg_Posterize1 = Image.open('图像5.jpg')
PilImg_Posterize = ImageOps.posterize(PilImg_Posterize1, bits=2)
# PilImg_Posterize.show()
# 将给定阈值之上所有像素值取反(solarize)
# ImageOps.solarize(image, threshold=128) ⇒ image
PilImg_Solarize1 = Image.open('图像5.jpg')
PilImg_Solarize = ImageOps.solarize(PilImg_Solarize1, threshold=250)
# PilImg_Solarize.show()
(版本1.1.3) ImageOps模块包含许多“现成的”图像处理操作。这个模块是实验性的,大多数操作符只支持“L”和“RGB”。
函数
autocontrast
ImageOps.autocontrast(image, cutoff=0) ⇒ image
图像对比度最大化(规范化)。该函数计算输入图像的直方图,根据截止百分比删除直方图中最亮和最暗的像素,
并对图像进行重排,使最黑的像素变为黑色(0),最亮的像素变为白色(255)。
colorize
ImageOps.colorize(image, black, white) ⇒ image
灰度图像彩色化。黑、白参数应该是RGB数组或颜色名称。
该函数计算一个颜色楔形,将源图像中的所有黑像素映射到第一个颜色,将所有的白色像素映射到第二个颜色。
crop
ImageOps.crop(image, border=0) ⇒ image
从所有四边删除边框像素。这个函数适用于所有的图像模式。
deform
ImageOps.deform(image, deformer, filter=Image.BILINEAR) ⇒ image
使用给定的deobject对象来变形图像。deobject对象应该提供一个getmesh方法,它返回一个适合于图像转换方法的网格(MESH)列表。
equalize
ImageOps.equalize(image) ⇒ image
直方图均衡化。该函数将非线性映射应用于输入图像,以在输出图像中创建灰度值的均匀分布。
expand
ImageOps.expand(image, border=0, fill=0) ⇒ image
向图像的所有四个边添加边框像素。
fit
ImageOps.fit(image, size, method, bleed, centering) ⇒ image
返回一个指定大小的裁剪版图像。size参数输出图像的大小,以(宽度,高度)元组表示。method参数是指重新采样的方法。缺省值是图像最近邻方法。
bleed参数允许您删除图像外部的边框(从所有的四个边)。它的值是一个小数(用0.01表示1%)。默认值为0(没有边框)。
centering参数用于控制剪切位置。(0.5, 0.5) 是剪切中心。
(0.0,0.0)将从左上角开始。
(1.0,0.0)将从左下角开始。
flip
ImageOps.flip(image) ⇒ image
垂直翻转图像(上到下)。
grayscale
ImageOps.grayscale(image) ⇒ image
将图像转换为灰度值图像。
invert
ImageOps.invert(image) ⇒ image
反转(取反)图像。
mirror
ImageOps.mirror(image) ⇒ image
水平翻转图像(从左到右)。
posterize
ImageOps.posterize(image, bits) ⇒ image
减少每个颜色通道的位数。
solarize
ImageOps.solarize(image, threshold=128) ⇒ image
将给定阈值之上所有像素值取反。
例程
# 图像对比度最大化(规范化)(autocontrast)# ImageOps.autocontrast(image, cutoff=0) ⇒ image
PilImg_Autocontrast1 = Image.open('图像5.jpg')
PilImg_Autocontrast = ImageOps.autocontrast(PilImg_Autocontrast1,
cutoff=0.9)
# PilImg_Autocontrast.show()
# 灰度图像彩色化(colorize)
# ImageOps.colorize(image, black, white) ⇒ image
PilImg_Colorize1 = Image.open('图像5.jpg').convert('L')
PilImg_Colorize = ImageOps.colorize(PilImg_Colorize1,
black=(100, 126, 189),
white=(56, 146, 231))
# PilImg_Colorize.show()
# 删除边框像素(crop)
# ImageOps.crop(image, border=0) ⇒ image
PilImg_Crop1 = Image.open('图像5.jpg').convert('L')
PilImg_Crop = ImageOps.crop(PilImg_Crop1, border=500)
# PilImg_Crop1.show()
# 直方图均衡化(equalize)
# ImageOps.equalize(image) ⇒ image
PilImg_Equalize1 = Image.open('图像5.jpg')
PilImg_Equalize = ImageOps.equalize(PilImg_Equalize1)
# PilImg_Equalize.show()
# 添加边框像素(expand)
# ImageOps.expand(image, border=0, fill=0) ⇒ image
PilImg_Expand1 = Image.open('图像5.jpg')
PilImg_Expand = ImageOps.expand(PilImg_Expand1, border=1, fill=1)
# PilImg_Expand.show()
# 垂直翻转图像(flip)
# ImageOps.flip(image) ⇒ image
PilImg_Flip1 = Image.open('图像5.jpg')
PilImg_Flip = ImageOps.flip(PilImg_Flip1)
# PilImg_Flip.show()
# 水平翻转图像(mirror)
# ImageOps.mirror(image) ⇒ image
PilImg_Mirror1 = Image.open('图像5.jpg')
PilImg_Mirror = ImageOps.mirror(PilImg_Mirror1)
# PilImg_Mirror.show()
# 将图像转换为灰度值图像(grayscale)
# ImageOps.grayscale(image) ⇒ image
PilImg_Grayscale1 = Image.open('图像5.jpg')
PilImg_Grayscale = ImageOps.grayscale(PilImg_Grayscale1)
# PilImg_Grayscale.show()
# 反转(取反)图像(invert)
# ImageOps.invert(image) ⇒ image
PilImg_Invert1 = Image.open('图像5.jpg')
PilImg_Invert = ImageOps.invert(PilImg_Invert1)
# PilImg_Invert.show()
# 减少每个颜色通道的位数(posterize)
# ImageOps.posterize(image, bits) ⇒ image
PilImg_Posterize1 = Image.open('图像5.jpg')
PilImg_Posterize = ImageOps.posterize(PilImg_Posterize1, bits=2)
# PilImg_Posterize.show()
# 将给定阈值之上所有像素值取反(solarize)
# ImageOps.solarize(image, threshold=128) ⇒ image
PilImg_Solarize1 = Image.open('图像5.jpg')
PilImg_Solarize = ImageOps.solarize(PilImg_Solarize1, threshold=250)
# PilImg_Solarize.show()
相关文章推荐
- Python Imaging Library: ImageMath Module(图像数学运算模块)
- Python Imaging Library:ImageDraw Module(图像绘制模块)
- Python Imaging Library: ImageGrab Module(图像采集模块)
- Python Imaging Library: ImageStat Module(图像统计模块)
- Python Imaging Library: ImagePath Module(图像路径模块)
- Python Imaging Library: ImageFile Module(图像文件模块)
- Python Imaging Library: ImageQt Module(图像QT模块)
- Python Imaging Library: ImageEnhance Module(图像增强模块)
- Python Imaging Library: ImageSequence Module(图像序列模块)
- Python Imaging Library: ImageWin Module(图像Windows模块)
- Python Imaging Library: ImageChops Module(图像通道操作模块)
- Python Imaging Library: ImageTk Module(图像Tkinter模块)
- Python Imaging Library: ImageFilter Module(图像滤波模块)
- Python Imaging Library: ImageColor Module(图像颜色模块)
- Python Imaging Library: PSDraw Module(Postscript打印机模块)
- Python中第三方的库(library)、模块(module),包(package)的安装方法以及ImportError: No module named
- Python中第三方的库(library)、模块(module),包(package)的安装方法
- 通过 Python + Python Imaging Library (PIL) 生成简单函数图像
- python图像融合(基于PIL Image模块)
- (转载)【总结】Python中第三方的库(library)、模块(module),包(package)的安装方法