-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandWritingPreprocess.py
More file actions
43 lines (32 loc) · 1.41 KB
/
handWritingPreprocess.py
File metadata and controls
43 lines (32 loc) · 1.41 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
39
40
41
42
43
import os
from PIL import Image
from tqdm import tqdm
def rotate_images(filePath, outputPath):
os.makedirs(outputPath, exist_ok=True)
angles = [i * 0.5 for i in range(1, 11)]
all_angles = angles + [-a for a in angles]
extensions = ('.png', '.jpg', '.jpeg', '.bmp', '.gif', '.tiff', '.webp')
for filename in tqdm(os.listdir(filePath)):
if not filename.lower().endswith(extensions):
continue
img_path = os.path.join(filePath, filename)
try:
with Image.open(img_path) as img:
for angle in all_angles:
rotated = img.rotate(angle, expand=True)
name, ext = os.path.splitext(filename)
out_filename = f"{name}_rot{angle:+.1f}{ext}"
out_path = os.path.join(outputPath, out_filename)
rotated.save(out_path)
#print(f"Processed: {filename}")
except Exception as e:
print(f"Error processing {filename}: {e}")
for i in range(10):
print(i)
filePath = f"D:\\Machine Learning\\1-0to6-2\\{i}"
outputPath = f"D:\\Machine Learning\\tmnist_data\\{i}"
rotate_images(filePath, outputPath)
print("NaN")
filePath = "D:\\Machine Learning\\1-0to6-2\\NaN"
outputPath = "D:\\Machine Learning\\tmnist_data\\NaN"
rotate_images(filePath, outputPath)