-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflipping_images_90deg_clockwise.py
72 lines (52 loc) · 1.5 KB
/
flipping_images_90deg_clockwise.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
65
66
67
68
69
70
71
72
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
def get_2by2_Rotation_matrix(alpha):
R = np.array([[ np.cos(np.deg2rad(alpha)), -np.sin(np.deg2rad(alpha))],
[ np.sin(np.deg2rad(alpha)), np.cos(np.deg2rad(alpha))]])
return R
def NpFlip90Clockwise(image):
return np.rot90(image, 3)
def ManuallyFlip90Clockwise(image):
H, W = image.shape
res = np.zeros((W, H))
for i in range(H):
for j in range(W):
res[i, j] = image[W-j-1, i]
return res
def ManuallyFlip90AntiClockwise(image):
H, W = image.shape
res = np.zeros((W, H))
for i in range(H):
for j in range(W):
res[i, j] = image[j, H-i-1]
return res
#def Flip45degClockwise(image):
# H, W = image.shape
# R = getRotation_matrix(-45)
# res = np.zeros((W, H))
# for i in range(H):
# for j in range(W):
# res[i, j] = R.dot(image[i, j])
# return res
#def Flip45degAntiClockwise(image):
# H, W = image.shape
# R = getRotation_matrix(45)
# res = np.zeros((W, H))
# for i in range(H):
# for j in range(W):
# res[i, j] = R.dot([[image[i]], [image[j]]])
# return res
#Flip General Image Data for an arbitrary image at an arbitrary angle
#def flipImagePixels(image, angle):
mnist_set = pd.read_csv("train.csv")
data = mnist_set.values
images = data[:, 1:]
labels = data[:, 0]
for i in range(10):
IMi = images[labels == i]
Mean = IMi.mean(axis=0)
im = Mean.reshape(28, 28)
im = NpFlip90Clockwise(im)
plt.imshow(im, cmap='gray')
plt.show()