Repository navigation
Expand file tree
/
Copy pathresize.py
More file actions
107 lines (99 loc) · 4.55 KB
/
Copy pathresize.py
File metadata and controls
107 lines (99 loc) · 4.55 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# import albumentations as A
import os
import jpeg4py as jpeg
import cv2
import numpy as np
import imageio
import torchvision.transforms as T
from PIL import Image
import torch
def resize_img(path):
resize_path = path + '_resize'
transform = T.Resize([256, 128], interpolation=3)
if not os.path.exists(resize_path):
os.makedirs(resize_path)
for name in os.listdir(path):
if name.split('.')[-1] == 'jpg':
# img = jpeg.JPEG(os.path.join(path, name)).decode()
img = Image.open(os.path.join(path, name)).convert('RGB')
img = transform(img)
# imageio.imwrite(os.path.join(resize_path, name), result['image'])
img.save(os.path.join(resize_path, name), lossless=True)
def resize_Occluded_img(path):
resize_path = path + '_resize'
transform = T.Resize([256, 128], interpolation=3)
for sub_dir in os.listdir(path):
temp_path = os.path.join(path, sub_dir)
temp_resize_path = os.path.join(resize_path, sub_dir)
if not os.path.exists(temp_resize_path):
os.makedirs(temp_resize_path)
for name in os.listdir(temp_path):
if name.split('.')[-1] == 'tif':
# img = jpeg.JPEG(os.path.join(path, name)).decode()
img = Image.open(os.path.join(temp_path, name)).convert('RGB')
img = transform(img)
# imageio.imwrite(os.path.join(resize_path, name), result['image'])
img.save(os.path.join(temp_resize_path, name), lossless=True)
def resize_P_Duke_img(path):
resize_path = path + '_resize'
transform = T.Resize([256, 128], interpolation=3)
for sub_dir in os.listdir(path):
for subsub_dir in os.listdir(os.path.join(path, sub_dir)):
temp_path = os.path.join(path, sub_dir, subsub_dir)
temp_resize_path = os.path.join(resize_path, sub_dir, subsub_dir)
if not os.path.exists(temp_resize_path):
os.makedirs(temp_resize_path)
for name in os.listdir(temp_path):
if name.split('.')[-1] == 'jpg':
# img = jpeg.JPEG(os.path.join(path, name)).decode()
img = Image.open(os.path.join(temp_path, name)).convert('RGB')
img = transform(img)
# imageio.imwrite(os.path.join(resize_path, name), result['image'])
img.save(os.path.join(temp_resize_path, name), lossless=True)
def resize_P_Duke_mask(path):
resize_path = path + '_resize'
transform = T.Resize([256, 128], interpolation=3)
for sub_dir in os.listdir(path):
temp_path = os.path.join(path, sub_dir)
temp_resize_path = os.path.join(resize_path, sub_dir)
if not os.path.exists(temp_resize_path):
os.makedirs(temp_resize_path)
for name in os.listdir(temp_path):
if name.split('.')[-1] == 'npy':
masks = np.load(os.path.join(temp_path, name))
# masks = np.transpose(masks, (1, 2, 0))
masks = torch.Tensor(masks)
masks = transform(masks)
# masks = np.transpose(masks, (2, 0, 1))
np.save(os.path.join(temp_resize_path, name), masks)
def resize_Occluded_mask(path):
resize_path = path + '_resize'
transform = T.Resize([256, 128], interpolation=3)
if not os.path.exists(resize_path):
os.makedirs(resize_path)
for name in os.listdir(path):
if name.split('.')[-1] == 'npy':
masks = np.load(os.path.join(path, name))
# masks = np.transpose(masks, (1, 2, 0))
masks = torch.Tensor(masks)
masks = transform(masks)
# masks = np.transpose(masks, (2, 0, 1))
np.save(os.path.join(resize_path, name), masks)
def resize_mask(path):
resize_path = path + '_resize'
transform = T.Resize([256, 128], interpolation=3)
if not os.path.exists(resize_path):
os.makedirs(resize_path)
for name in os.listdir(path):
if name.split('.')[-1] == 'npy':
masks = np.load(os.path.join(path, name))
masks = np.transpose(masks, (1, 2, 0))
masks = torch.Tensor(masks)
result = transform(masks)
masks = np.transpose(masks, (2, 0, 1))
np.save(os.path.join(resize_path, name), masks)
if __name__ == '__main__':
path = '/ReID_datasets/Occluded_REID/masks/pifpaf_maskrcnn_filtering/whole_body_images'
resize_Occluded_mask(path)
path = '/ReID_datasets/Occluded_REID/masks/pifpaf_maskrcnn_filtering/occluded_body_images'
resize_Occluded_mask(path)