-
Notifications
You must be signed in to change notification settings - Fork 0
/
rotate.py
28 lines (24 loc) · 1.01 KB
/
rotate.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
__author__ = 'mrtyormaa'
import glob
import os
from PIL import Image
# im = Image.open("435.jpg")
# im.rotate(180).save("435-rotated" + ".jpg", "JPEG")
# get the classnames from the directory structure
directory_names = list(set(glob.glob(os.path.join("train-all-data", "*"))
).difference(set(glob.glob(os.path.join("train-all-data", "*.*")))))
# Rescale the images and create the combined metrics and training labels
# get the total training images
numberofImages = 0
for folder in directory_names:
for fileNameDir in os.walk(folder):
for fileName in fileNameDir[2]:
# Only read in the images
if fileName[-4:] != ".jpg":
continue
numberofImages += 1
# print(os.path.splitext(fileName)[0])
fullName = fileNameDir[0] + '/' + fileName
newName = fileNameDir[0] + '/' + os.path.splitext(fileName)[0] + '-rotated.jpg'
im = Image.open(fullName)
im.rotate(180).save(newName, "JPEG")