-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimg_process.py
More file actions
52 lines (36 loc) · 1016 Bytes
/
Copy pathimg_process.py
File metadata and controls
52 lines (36 loc) · 1016 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
48
49
50
51
import torchvision
import cv2
# Image,imageio 读取的图片
# [h,w,c]
# img[0 , 0] 表示在最左上角
# 纵坐标 横坐标
# 蓝
# img_color[100:200,100:200] = [0,0,255]
# 绿
# img_color[200:300,100:200] = [0,255,0]
# 红
# img_color[300:400,100:200] = [255,0,0]
# 黄
# img_color[400:500,100:200] = [255,255,0]
# 粉
# img_color[500:600,100:200] = [255,0,255]
# 青
# img_color[600:700,100:200] = [0,255,255]
# 保存numpy array的图像
# 保存torch tensor的图像
# 读取图像
# 图像裁剪
# loc_h:原点离左上角的纵向处理
# loc_w:原点离左上角的横向距离
# h:从原点向下裁剪的距离
# w:从原点向右裁剪的距离
# (0,0)
# (loc_h,loc_w) (loc_h,loc_w+w)
# crop zone
# (loc_h+h,loc_w) (loc_h+h,loc_w+w)
def img_crop(img,loc_h,loc_w,h,w):
return torchvision.transforms.functional.crop(img,loc_h,loc_w,h,w)
# 图像resize
def resize(img, h, w):
return cv2.resize(img, (w,h))
# gif使用