Skip to content

Commit

Permalink
add mean face back
Browse files Browse the repository at this point in the history
  • Loading branch information
orbxball committed May 11, 2017
1 parent c3c2377 commit f79ee35
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions hw4/pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def read_pic(file, obj_size=10, pic_size=10):
def save_img(data, filename='default', subplot=False, size=0):
global width, height

print('Drawing {}...'.format(filename))
if subplot:
fig = plt.figure(figsize=(16, 16))
for i in range(size):
Expand Down Expand Up @@ -54,8 +55,9 @@ def pca(x, face_size):
return mu.reshape(width, height), weights, picked_faces


def reconstruct(weights, eigen_faces, eigen_size=0):
def reconstruct(mu, weights, eigen_faces, eigen_size=0):
pics = np.dot(weights, eigen_faces)
pics += mu.flatten()
save_img(pics, filename='original_eigen_{}.png'.format(eigen_size),
subplot=True, size=pics.shape[0])

Expand Down Expand Up @@ -89,7 +91,7 @@ def main():

# Reconstrcut by eigen faces
mu, weights, eigen_faces = pca(pics_matrix, 5)
reconstruct(weights, eigen_faces, eigen_size=eigen_faces.shape[0])
reconstruct(mu, weights, eigen_faces, eigen_size=eigen_faces.shape[0])

# Calculate the RSME
min_size_of_eigen_faces = cal_error(pics_matrix, 0.01)
Expand Down

0 comments on commit f79ee35

Please sign in to comment.