-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathpreprocess_padding.py
More file actions
29 lines (20 loc) · 862 Bytes
/
preprocess_padding.py
File metadata and controls
29 lines (20 loc) · 862 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
import os
from PIL import Image
import numpy as np
from tqdm import tqdm
img_names = os.listdir('test_image/')
for name in tqdm(img_names):
img = np.asarray(Image.open('test_image/'+name))
max_dim_img = max(img.shape[0], img.shape[1])
row_img = max_dim_img - img.shape[0]
cols_img = max_dim_img - img.shape[1]
padded_img = np.pad(img, ((row_img//2,row_img//2), (cols_img//2,cols_img//2)), mode ='constant')
img = Image.fromarray(padded_img)
img.save('Images_padded_test/'+name)
mask = np.asarray(Image.open('test_mask/Mask/'+name))
max_dim_mask = max(mask.shape[0], mask.shape[1])
row_mask = max_dim_mask- mask.shape[0]
cols_mask = max_dim_mask - mask.shape[1]
padded_mask = np.pad(mask, ((row_mask//2,row_mask//2), (cols_mask//2,cols_mask//2)), mode ='constant')
mask = Image.fromarray(padded_mask)
mask.save('Mask_padded_test/'+name)