def compute(self, X, y): [D, self.W, self.mu] = fisherfaces(asRowMatrix(X),y, self.num_components) # store labels self.y = y # store projections for xi in X: self.projections.append(project(self.W, xi.reshape(1,-1), self.mu))
def compute(self, X, y): [D, self.W, self.mu] = fisherfaces(asRowMatrix(X), y, self.num_components) # store labels self.y = y # store projections for xi in X: self.projections.append(project(self.W, xi.reshape(1, -1), self.mu))
import numpy as np # import tinyfacerec modules from tinyfacerec.subspace import fisherfaces from tinyfacerec.util import normalize, asRowMatrix, read_images from tinyfacerec.visual import subplot if __name__ == '__main__': if len(sys.argv) != 2: print "USAGE: example_fisherfaces.py </path/to/images>" sys.exit() # read images [X,y] = read_images(sys.argv[1]) # perform a full pca [D, W, mu] = fisherfaces(asRowMatrix(X), y) #import colormaps import matplotlib.cm as cm # turn the first (at most) 16 eigenvectors into grayscale # images (note: eigenvectors are stored by column!) E = [] for i in xrange(min(W.shape[1], 16)): e = W[:,i].reshape(X[0].shape) E.append(normalize(e,0,255)) # plot them and store the plot to "python_fisherfaces_fisherfaces.pdf" subplot(title="Fisherfaces AT&T Facedatabase", images=E, rows=4, cols=4, sptitle="Fisherface", colormap=cm.jet, filename="python_fisherfaces_fisherfaces.png") from tinyfacerec.subspace import project, reconstruct E = [] for i in xrange(min(W.shape[1], 16)):
import numpy as np # import tinyfacerec modules from tinyfacerec.subspace import fisherfaces from tinyfacerec.util import normalize, asRowMatrix, read_images from tinyfacerec.visual import subplot if __name__ == '__main__': if len(sys.argv) != 2: print "USAGE: example_fisherfaces.py </path/to/images>" sys.exit() # read images [X, y] = read_images(sys.argv[1]) # perform a full pca [D, W, mu] = fisherfaces(asRowMatrix(X), y) #import colormaps import matplotlib.cm as cm # turn the first (at most) 16 eigenvectors into grayscale # images (note: eigenvectors are stored by column!) E = [] for i in xrange(min(W.shape[1], 16)): e = W[:, i].reshape(X[0].shape) E.append(normalize(e, 0, 255)) # plot them and store the plot to "python_fisherfaces_fisherfaces.pdf" subplot(title="Fisherfaces AT&T Facedatabase", images=E, rows=4, cols=4, sptitle="Fisherface", colormap=cm.jet,