forked from shibing624/python-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresize_demo.py
More file actions
47 lines (36 loc) · 957 Bytes
/
resize_demo.py
File metadata and controls
47 lines (36 loc) · 957 Bytes
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
# -*- coding: utf-8 -*-
"""
@author:XuMing([email protected])
@description:
"""
import cv2
import os
from PIL import Image
def display_cv(image_path):
img = cv2.imread(image_path)
height, width = img.shape[:2]
print(height, width)
# 缩小图像
size = (200, 200)
print(size)
shrink = cv2.resize(img, size, interpolation=cv2.INTER_AREA)
# 放大图像
fx = 1.6
fy = 1.2
enlarge = cv2.resize(img, (0, 0), fx=fx, fy=fy, interpolation=cv2.INTER_CUBIC)
# 显示
cv2.imshow("src", img)
cv2.imshow("shrink", shrink)
cv2.imshow("enlarge", enlarge)
cv2.waitKey(0)
def display_pil(image_path):
img = Image.open(image_path)
# 缩小图像
size = (200, 200)
print(size)
new_img = img.resize((200, 200), Image.BILINEAR)
new_img.show()
new_img.save('pil_resize_' + image_path)
if __name__ == '__main__':
# display_cv('flower.png')
display_pil('flower.png')