-
Notifications
You must be signed in to change notification settings - Fork 5
/
get-pixels-cv.py
70 lines (61 loc) · 1.83 KB
/
get-pixels-cv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# -*- coding: utf-8 -*-
"""
Created on Wed Jan 24 20:00:35 2018
@author: April
"""
# 导入pillow
from PIL import Image
# 加载原始图片
img = Image.open("00010.bmp")
# -------------------------------从左上角开始 剪切 200*200的图片
img2 = img.crop((0, 0, 200, 200))
img2.save("lena.jpg")
# ---------------------------------逆时针旋转方向,顺时针那么就输入-45,
img2 = img.rotate(45)
img2.save("rota.jpg")
img33 = img.rotate(90)
img33.save("rotate2.jpg")
# ------------------------------------不变化大小的旋转,重采样
img4 = img.rotate(45, resample = Image.NEAREST)# 近邻采样(默认)
img4.save("rotate-no.jpg")
img5 = img.rotate(45,resample=Image.BILINEAR) #线性插值
img5.save("img5.jpg")
img8 = img.rotate(45, resample=Image.BICUBIC)# 三次样条插值
img8.save("rubberwhale8.jpg")
# --------------------------------不同的位置开始,右下角开始
width = img.size[0] # 图片大小
height = img.size[1]
img3 = img.crop(
(
width - 200,
height - 200,
width,
height
)
)
img3.save("lena3.jpg")
# -------------------------------------------中间开始切割
half_the_width = img.size[0] / 2
half_the_height = img.size[1] / 2
img4 = img.crop(
(
half_the_width - 50,
half_the_height - 75,
half_the_width + 50,
half_the_height + 75
)
)
img4.save("lena4.jpg")
# -------------------------------------------填充为正方形
longer_side = max(img4.size)
horizontal_padding = (longer_side - img4.size[0]) / 2
vertical_padding = (longer_side - img4.size[1]) / 2
img5 = img4.crop(
(
-horizontal_padding,
-vertical_padding,
img4.size[0] + horizontal_padding,
img4.size[1] + vertical_padding
)
)
img5.save("lena5.jpg")