-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
28 lines (24 loc) · 817 Bytes
/
utils.py
File metadata and controls
28 lines (24 loc) · 817 Bytes
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
from sklearn.preprocessing import MinMaxScaler
from sklearn.decomposition import PCA
def normalize_data(dr_object, data):
if dr_object == 'pca':
"""Normalize data between range 0, 1"""
scaler = MinMaxScaler()
return scaler.fit_transform(data)
else:
"""reduce to 300 dimensions"""
pca = PCA(n_components=300)
return pca.fit_transform(data)
def crop_box(image, x, y, w, h):
"""Create a centralized squared bounding box based on largest size"""
if w > h:
h_diff = int((w - h)/2)
if y - h_diff > 0:
y -= h_diff
img_out = image.crop((x, y, x + w, y + w))
else:
w_diff = int((h - w)/2)
if x - w_diff > 0:
x -= w_diff
img_out = image.crop((x, y, x + h, y + h))
return img_out