-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_augmentation.py
More file actions
38 lines (29 loc) · 1.17 KB
/
image_augmentation.py
File metadata and controls
38 lines (29 loc) · 1.17 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
# program to create synthetic images using the real images by rotating, mirroring, etc.
from __future__ import print_function
import os
from os.path import splitext
from PIL import Image
# out_path = '../images/Synthetic_Images/'
# img_path = '../images/Original_Images/IR_Images/'
out_path = 'data/train/notcorroded/'
img_path = 'data/train/notcorroded/'
# for each image in the images dir, create a few syntheic ones
def img_out(img_name, trans):
name, ext = os.path.splitext(img_name)
return out_path + name + '_' + trans + ext
for img_in in os.listdir(img_path):
try:
with Image.open(img_path + img_in) as im:
out = im.transpose(Image.FLIP_LEFT_RIGHT)
out.save(img_out(img_in, 'FLR'))
out = im.transpose(Image.FLIP_TOP_BOTTOM)
out.save(img_out(img_in, 'FTB'))
out = im.transpose(Image.ROTATE_90)
out.save(img_out(img_in, 'ROT90'))
out = im.transpose(Image.ROTATE_180)
out.save(img_out(img_in, 'ROT180'))
out = im.transpose(Image.ROTATE_270)
out.save(img_out(img_in, 'ROT270'))
except IOError:
print('error', img_path)
pass