-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_eigenfaces.py
More file actions
32 lines (25 loc) · 876 Bytes
/
plot_eigenfaces.py
File metadata and controls
32 lines (25 loc) · 876 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
29
30
31
32
# python3 plot_eigenfaces.py /userdata/eigenfaces.dat eigenfaces/ 20
import sys
import os
import numpy as np
import core.eigenfaces as ef
import core.image as im
picklefile = str(sys.argv[1])
output_directory = str(sys.argv[2])
if not os.path.exists(output_directory):
os.makedirs(output_directory)
if len(sys.argv) == 4:
truncate = int(sys.argv[3])
else:
truncate = sys.maxint
eigenfaces = ef.Eigenfaces()
eigenfaces.load_picklefile(picklefile)
truncate = min(eigenfaces.U.shape[0], truncate)
digits = int(np.log10(truncate)) + 1
i = 0
for u, eigenvalue in zip(eigenfaces.U[:truncate], eigenfaces.s[:truncate]):
p = u * np.sqrt(eigenvalue) * 0.5 + eigenfaces.meanface
string_i = str(i).zfill(digits)
filename = os.path.join(output_directory, "eigenface{0}.png".format(string_i))
im.save_image(p, eigenfaces.resolution, filename)
i += 1