-
Notifications
You must be signed in to change notification settings - Fork 0
/
transformations.py
64 lines (48 loc) · 1.69 KB
/
transformations.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import numpy as np
import matplotlib.pyplot as plt
import os
from scipy import ndimage
from PIL import Image
from pathlib import Path
def data_load(path):
file_list = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f))]
cloud_images = []
for file in file_list:
image_obj = Image.open(path + file)
image = np.asarray(image_obj)
cloud_images.append(image)
return cloud_images
def rotation(input_images):
rotated_90 = []
rotated_180 = []
rotated_270 = []
overall = []
for image in input_images:
img_90 = ndimage.rotate(image, angle=90)
img_180 = ndimage.rotate(image, angle=180)
img_270 = ndimage.rotate(image, angle=270)
rotated_90.append(img_90)
rotated_180.append(img_180)
rotated_270.append(img_270)
overall.append(image)
overall.append(img_90)
overall.append(img_180)
overall.append(img_270)
return rotated_90, rotated_180, rotated_270, overall
def reflection(input_images):
overall = []
for image in input_images:
vertically_reflected_img = np.flip(image, 0)
horizontally_reflected_img = np.flip(image, 1)
overall.append(image)
overall.append(vertically_reflected_img)
overall.append(horizontally_reflected_img)
return overall
def save_images(input_images, save_path):
Path(save_path).mkdir(parents=True, exist_ok=True)
for (idx,image) in enumerate(input_images):
#print(image.shape)
#print("Minimum Value = ", np.min(image), "; Maximum Value = ", np.max(image))
im = Image.fromarray(image)
im = im.convert("L")
im.save(save_path + str(idx+1) + '.png')