forked from rockeyben/DCCF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resize_dataset_2048_2048.py
36 lines (27 loc) · 1.11 KB
/
resize_dataset_2048_2048.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
import cv2
import shutil
from tqdm import tqdm
from pathlib import Path
max_size = 2048
input_dataset_path = '/S4/MI/xueb/data/IDIH/HAdobe5k'
output_path = f'{input_dataset_path}_resized{max_size}_{max_size}'
input_dataset_path = Path(input_dataset_path)
output_path = Path(output_path)
assert not output_path.exists()
output_path.mkdir()
for subfolder in ['composite_images', 'masks', 'real_images']:
(output_path / subfolder).mkdir()
for annotation_path in input_dataset_path.glob('*.txt'):
shutil.copy(annotation_path, output_path / annotation_path.name)
images_list = sorted(input_dataset_path.rglob('*.jpg'))
images_list.extend(sorted(input_dataset_path.rglob('*.png')))
for x in tqdm(images_list):
image = cv2.imread(str(x), cv2.IMREAD_UNCHANGED)
new_path = output_path / x.relative_to(input_dataset_path)
new_width = max_size
new_height = max_size
image = cv2.resize(image, (new_width, new_height), interpolation=cv2.INTER_LANCZOS4)
if x.suffix == '.jpg':
cv2.imwrite(str(new_path), image, [cv2.IMWRITE_JPEG_QUALITY, 90])
else:
cv2.imwrite(str(new_path), image)