generated from Nirmala-research/Image-Reconstruction
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_augment.py
40 lines (28 loc) · 1.06 KB
/
data_augment.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
37
38
39
40
# -*- coding: utf-8 -*-
"""Data augment.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/15CXWy3aN0qKCyoEIhssxo1jiTRLcXnwL
"""
class augmentation(object):
def __call__(self, sample):
LR_img, GT_img = sample['LR'], sample['GT']
hor_flip = random.randrange(0,2)
ver_flip = random.randrange(0,2)
rot = random.randrange(0,2)
if hor_flip:
temp_LR = np.fliplr(LR_img)
LR_img = temp_LR.copy()
temp_GT = np.fliplr(GT_img)
GT_img = temp_GT.copy()
del temp_LR, temp_GT
if ver_flip:
temp_LR = np.flipud(LR_img)
LR_img = temp_LR.copy()
temp_GT = np.flipud(GT_img)
GT_img = temp_GT.copy()
del temp_LR, temp_GT
if rot:
LR_img = LR_img.transpose(1, 0, 2)
GT_img = GT_img.transpose(1, 0, 2)
return {'LR' : LR_img, 'GT' : GT_img}