-
Notifications
You must be signed in to change notification settings - Fork 10
/
data_rotation_2nd.py
35 lines (30 loc) · 1.22 KB
/
data_rotation_2nd.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
#!/usr/bin/env python
# coding=utf-8
#Author: Perfe
#E-mail: [email protected]
from __future__ import print_function
import numpy as np
import cv2
train_images = np.load("./generated_data/train_images.npy")
#train_masks = np.load("./generated_data/train_masks.npy")
w = train_images[0,0].shape[0]
h = train_images[0,0].shape[1]
print((w,h))
rotation_center = (w/2,h/2)
rotation_angle = 350
rotation_scale = 1
transform_matrix = cv2.getRotationMatrix2D(center=rotation_center,angle=rotation_angle,scale=rotation_scale)
train_images_rotation = np.empty_like(train_images,dtype=np.uint8)
#train_masks_rotation = np.empty_like(train_images,dtype=np.uint8)
for i in range(train_images.shape[0]):
newimg = cv2.warpAffine(train_images[i,0],transform_matrix,(h,w))
# newmask = cv2.warpAffine(train_masks[i,0],transform_matrix,(h,w))
# print(newimg.shape)
# cv2.imshow("old",train_images[i,0])
# cv2.imshow("newimg",newimg)
train_images_rotation[i,0] = newimg
# train_masks_rotation[i,0] = newmask
print(train_images_rotation.shape)
#print(train_masks_rotation.shape)
np.save("./generated_data/train_images_rotation_2.npy",train_images_rotation)
#np.save("./generated_data/train_masks_rotation_2.npy",train_masks_rotation)