pip install pillow
Image
对象 r
from PIL import Image
im = Image.open(path)
Image
对象 Image
对象1Image
对象2from PIL import Image
im1 = Image.open(path1)
im2 = Image.open(path2)
im3 = Image.alpha_composite(im1,im2)
Image
对象 Image
对象1Image
对象2如果alpha为0.0,则返回第一个图像的副本。如果alpha为1.0,则返回第二个图像的副本,基本的算法如下:
out = image1 * (1.0 - alpha ) + image2 * alpha
Image
对象 Image
对象from PIL import Image
def func(a):
return a
im1 = Image.open(path1)
img = Image.eval(img1,func,1)
Image
对象 Pillow支持的模式表
Image
对象。烦会一个Image
对象 Pillow支持的模式表
ImageColor
对象from PIL import Image
# 单个整数值
img = Image.new("RGBA",(1024,768),215)
# 元组
img = Image.new("RGBA",(1024,768),(215,0,0)
# ImageColor
from PIL import ImageColor
color = ImageColor.getrgb("#FF0000")
img = Image.new("RGBA",(1024,768),color)
img.show()
从上面代码运行结果显示是一个红色,1024*768的图像
alpha_composite(im, dest=(0,0), source=(0,0)):在Image
对象中符合im
,效果与类方法alpha_composite
相似。无返回值
Image
对象copy():复制此图片
from PIL import Image
img = Image.new("RGBA",(1024,768),215)
img_copy = img.copy()
Image
对象 from PIL import Image
img = Image.new("RGBA",(1024,768),215)
img_copy = img.crop(box=(0,0,500,500))
draft(mode, size):配置图像文件加载器,以便返回尽可能接近给定模式和大小的图像版本,无返回值
filter(filter):使用给定的过滤器过滤此图像,返回一个Image
对象
getbands():获取此图像中每个波段名称的元组。返回一个tuple
from PIL import Image
img = Image.new("RGBA",(1024,768),215)
print img.getbands() # ('R', 'G', 'B', 'A')
tuple
from PIL import Image
img = Image.new("RGBA",(1024,768),215)
print img.getbbox() # (0, 0, 1024, 768)
from PIL import Image
img = Image.new("RGBA",(1024,768),215)
print img.getcolors() # [(786432, (215, 0, 0, 0))]
from PIL import Image
img = Image.new("RGBA",(1024,768),215)
for item in img.getdata():
print item
# 打印结果:
(215, 0, 0, 0)
(215, 0, 0, 0)
(215, 0, 0, 0)
...
from PIL import Image
img = Image.new("RGBA",(1024,768),215)
print img.getextrema() # ((215, 215), (0, 0), (0, 0), (0, 0))
list
对象。如果没有调色板,则返回Nonefrom PIL import Image
img = Image.new("RGBA",(1024,768),215)
print img.getpalette() # None
tuple
from PIL import Image
img = Image.new("RGBA",(1024,768),215)
print img.getpixel((500,500)) # (215, 0, 0, 0)
import os
from PIL import Image
path1 = os.path.join(os.getcwd(),"23.png")
img1 = Image.open(path1)
img = Image.new("RGBA",(1024,768),215)
img1.paste(img)
img1.show()
from PIL import Image
img = Image.new("RGBA",(1024,768),215)
img_c = Image.new("RGBA",(1024,768),-100)
img.putdata(img_c.getdata())
img.show()
P
或者L
。返回一个Image
对象 from PIL import Image
img = Image.new("P",(1024,768),215)
img_c = Image.new("P",(1024,768),-100)
img_c.putpalette(img.getpalette())
img_c.show()
P
模式图像,返回一个Image
对象 from PIL import Image
img = Image.new("RGBA",(1024,768),215)
img_q = img.quantize(colors=256,method=2)
print img_q # <PIL.Image.Image image mode=P size=1024x768 at 0x2BF7E80>
Image
对象 Image.NEAREST
、Image.BOX
、Image.BILINEAR
、Image.HAMMING
、Image.BICUBIC
或者Image.LANCZOS
。如果省略,或者图像模式为1
或者P
,则设置Image.NEAREST
。from PIL import Image
img = Image.new("RGBA",(1024,768),215)
img_r = img.resize(size=(500,500))
print img_r # <PIL.Image.Image image mode=RGBA size=500x500 at 0x37A6E80>
Image
对象 Image.NEAREST
、Image.BILINEAR
或者Image.BICUBIC
。如果省略,或者图像模式为1
或者P
,则设置Image.NEAREST
。import os
from PIL import Image
path1 = os.path.join(os.getcwd(),"23.png")
img1 = Image.open(path1)
img_r = img1.rotate(45,Image.BICUBIC)
img_r.show()
可以看到,图像已经逆时针旋转了45度
import os
from PIL import Image
path1 = os.path.join(os.getcwd(),"23.png")
img1 = Image.open(path1)
img_r = img1.rotate(45,Image.BICUBIC)
img_r.save(os.path.join(os.getcwd(),"rotate.png"))
seek(frame):在这个序列文件中寻找给定的帧。如果您在序列结束之外寻找方法,则会 引发EOFError异常。当序列文件被打开时,库会自动寻找0帧。无返回值
show(title=None, command=None):显示这个图像,此方法主要用于调试目的。无返回值
tuple
from PIL import Image
path1 = os.path.join(os.getcwd(),"23.png")
img1 = Image.open(path1)
data = img1.split()
print data # (<PIL.Image.Image image mode=L size=3500x3500 at 0x2DEC438>, <PIL.Image.Image image mode=L size=3500x3500 at 0x2DEC860>, <PIL.Image.Image image mode=L size=3500x3500 at 0x2DEC898>, <PIL.Image.Image image mode=L size=3500x3500 at 0x2DEC8D0>)
Image
对象 from PIL import Image
path1 = os.path.join(os.getcwd(),"23.png")
img1 = Image.open(path1)
im = img1.getchannel(0)
或者:
im = img1.getchannel("R")
int
Image.NEAREST
、Image.BILINEAR
、Image.BICUBIC
或者Image.LANCZOS
。如果省略,则默认为Image.BICUBIC
from PIL import Image
path1 = os.path.join(os.getcwd(),"23.png")
img1 = Image.open(path1)
img1.thumbnail(size=(500,500),resample=Image.BICUBIC)
print img1 # <PIL.PngImagePlugin.PngImageFile image mode=RGBA size=500x500 at 0x311C3C8>
1
的图像,返回一个str
from PIL import Image
img = Image.new("1",(1024,768),215)
data = img.tobitmap(name='abc')
print data
# 结果如下:
"""
#define abc_width 1024
#define abc_height 768
static char abc_bits[] = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
...
};
"""
str
对象Image
对象 Image.FLIP_LEFT_RIGHT
、Image.FLIP_TOP_BOTTOM
、Image.ROTATE_90
、Image.ROTATE_180
、Image.ROTATE_270
、Image.TRANSPOSE
或者Image.TRANSVERSE
from PIL import Image
path1 = os.path.join(os.getcwd(),"23.png")
img1 = Image.open(path1)
im = img1.transpose(Image.FLIP_LEFT_RIGHT)
im.show()
可以看出图像已经翻转了
open
方法构建的图像对象才具有此属性import os
from PIL import Image
path1 = os.path.join(os.getcwd(),"23.png")
img = Image.open(path1)
print img.filename # 、/aaa/bbb/ccc/23.png
None
import os
from PIL import Image
path1 = os.path.join(os.getcwd(),"23.png")
img = Image.open(path1)
print img.format # PNG
img = Image.new("RGBA",(1024,768),215)
print img.format # None
from PIL import Image
img = Image.new("RGBA",(1024,768),215)
print img.mode # RGBA
tuple
from PIL import Image
img = Image.new("RGBA",(1024,768),215)
print img.size # (1024, 768)
int
from PIL import Image
img = Image.new("RGBA",(1024,768),215)
print img.width # 1024
int
from PIL import Image
img = Image.new("RGBA",(1024,768),215)
print img.height # 768
P
,这应该是ImagePalette
类的一个实例。否则为None
from PIL import Image
img = Image.new("RGBA",(1024,768),215)
print img.palette # None
img = Image.new("P",(1024,768),215)
print img.palette # <PIL.ImagePalette.ImagePalette object at 0x0000000002EF9828>
import os
from PIL import Image
path1 = os.path.join(os.getcwd(),"23.png")
img = Image.open(path1)
print img.info
# 结果如下:
'''
{
'chromaticity': (0.31269, 0.32899, 0.63999, 0.33001, 0.3, 0.6, 0.15, 0.05999),
'icc_profile': 'xxxx/...',
'dpi': (300, 300)
}
'''
img = Image.new("RGBA",(1024,768),215)
print img.info # {}
模式 | 说明 |
---|---|
1 | 1位像素,黑白,每字节一个像素存储 |
L | 8位像素,黑白 |
P | 8位像素,使用调色板映射到任何其他模式 |
RGB | 3x8位像素,真彩色 |
RGBA | 4×8位像素,带透明度掩模的真彩色 |
CMYK | 4x8位像素,分色 |
YCbCr | 3x8位像素,彩色视频格式 |
LAB | 3×8位像素,L * a * b颜色空间 |
HSV | 3x8位像素,色调,饱和度,值颜色空间 |
I | 32位有符号整数像素 |
F | 32位浮点像素 |
更多关于Image的操作:http://pillow.readthedocs.io/en/latest/reference/Image.html
文章浏览阅读1.2w次,点赞12次,收藏79次。idea卸载与重装。_idea卸载干净并重新安装
文章浏览阅读870次,点赞3次,收藏5次。今天学vue到webpack,大无语了家人们,从第一步npm installl的安装开始,就逐渐陷入了npm的坑!首先,从官网下载node.js,链接Download | Node.js,根据自己的电脑配置选择安装版本(推荐LST稳定版本的),然后按照安装步骤操作就行,直到测试安装的时候,开始报错了:网上查找了许多博文之后找到了解决方法:1、删除C:Users用户下的.npmrc文件这里我的.npmrc是正常显示的,如果你的没有,看是不是因为将隐藏的项目勾选上了,然后去掉勾选。2、在命令行输入_>npm init vue@latest npm err! code eperm npm err! syscall open npm err! path
文章浏览阅读4.7k次,点赞5次,收藏19次。这里是使用一个自定义类的集合和一个Integer类的集合做的一次栗子,两个封装类的操作,或者两个基本类型的集合操作都是类似的。public class CollectionTest { public static void main(String[] args) { List<Customer> list = new ArrayList<>(); Customer customer = new Customer(); cus_java 根据某个属性判断两个集合中的差集
文章浏览阅读68次。JQuery:ajax后台返回list,前台用jquery遍历list
文章浏览阅读516次。6月23日,中国抗衰老促进会康养产业分会成立大会在京举行。原国家卫生部副部长孙隆椿、原总后卫生部部长李深、中国抗衰老促进会法人理事长刘仁富,副理事长朱怡霖、北京师范大学系..._中国抗衰老促进会证书含金量
文章浏览阅读360次。 There is a problem happen when download firmware to the LPC2214 with JFlash v3.42b, the unit will not be turned on when power is on. But the download will be ok when I use JFlash v4.02 and v4.08, t_jflash checksum
文章浏览阅读361次。VMware下载官网 我下载的是14版本 来源网站(https://www.douban.com/note/639107631/) 下载链接: https://download3.vmware.com/software/wkst/file/VMware-workstation-full-14.0.0-6661328.exe 安装密钥 VMware 14 Pro 永久许可证激活密钥..._vmware 安装ubantu csdn
文章浏览阅读2.1w次,点赞74次,收藏185次。现在终于进入框架的学习中了,前面还有好几个框架等待着我们呢。我们先来学习Struts1框架,然后再过渡到Struts2框架的学习中。下面我们开始学习Struts1框架。Struts简介Struts是apache开发的一个web层的框架,它主要用于简化web层的开发,Struts针对web层的一些常用操作,例如:表单数据的封装、校验和数据的回显国际化开发文件上传异常处理等等…Struts都提_struts1
文章浏览阅读708次。IntelliJ IDEA简单创建JavaSE项目的使用IntelliJ IDEA简单创建JavaSE项目的使用IntelliJ IDEA简单创建JavaSE项目的使用创建一个新的项目创建包和类创建一个新的项目1、打开IDEA,点击 Create New Project2、在Project SDK中选择下载好的JDK,根据路径选择,一般安装好JDK后IDEA会默认JDK的路径,所以一般可以不用管这里。然后Next。3、一般默认Next4、在红框中输入项目名称,在绿框中输入项目保存路径。一般_爱迪尔怎么创建java se
文章浏览阅读2.5k次,点赞12次,收藏15次。破解版matlab安装Higher Order Spectral Analysis Toolbox-亲测成功1.下载所需toolbox,随意保存于某个文件夹!2.解压该压缩文件——继续解压hosa_d.exe文件——将hosa文件夹(及hosademo)copy到电脑安装matlab的toolbox文件夹中。并且,将hosa文件夹中的文件后缀“.M”改为“.m”3.打开matlab主页——设置路径——添加文件夹——将上述文件夹导入——保存——关闭。4.打开matlab主页——预设——常规——_hosa - higher order spectral analysis toolbox
文章浏览阅读3.7k次,点赞5次,收藏13次。JSON Web Token 入门教程前言:最近一直忙着Python的Jwt和Java的Jwt认证互转,以及无缝对接,所以想把这些记录一下。JSON Web Token(缩写 JWT)是目前最流行的跨域认证解决方案,本文介绍它的原理和用法。一、跨域认证的问题互联网服务离不开用户认证。一般流程是下面这样。1、用户向服务器发送用户名和密码。2、服务器验证通过后,在当..._jwt typ
文章浏览阅读2.3k次,点赞2次,收藏8次。一般的功能,可以使用现有的节点来完成。但如果有比较复杂,或有自己特殊业务需求的,可能就需要自定义了。按[官方教程](https://thingsboard.io/docs/user-guide/contribution/rule-node-development/)来基本就可以入门,如果需要深入,可以参考ThingsBoard自有节点的实现,见[源码](https://github.com/thingsboard/thingsboard)_thingsboard 规则链ui