示例#1
0
	def compute(self, X, y):
		[D, self.W, self.mu] = pca(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] = pca(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))
示例#3
0
def fisherfaces(X,y,num_components=0):
	y = np.asarray(y)
	[n,d] = X.shape
	c = len(np.unique(y))
	[eigenvalues_pca, eigenvectors_pca, mu_pca] = pca(X, y, (n-c))
	[eigenvalues_lda, eigenvectors_lda] = lda(project(eigenvectors_pca, X, mu_pca), y, num_components)
	eigenvectors = np.dot(eigenvectors_pca,eigenvectors_lda)
	return [eigenvalues_lda, eigenvectors, mu_pca]
示例#4
0
def fisherfaces(X, y, num_components=0):
    y = np.asarray(y)
    [n, d] = X.shape
    c = len(np.unique(y))
    [eigenvalues_pca, eigenvectors_pca, mu_pca] = pca(X, y, (n - c))
    [eigenvalues_lda,
     eigenvectors_lda] = lda(project(eigenvectors_pca, X, mu_pca), y,
                             num_components)
    eigenvectors = np.dot(eigenvectors_pca, eigenvectors_lda)
    return [eigenvalues_lda, eigenvectors, mu_pca]
def reconstruct (W , Y , mu = None ) :
if mu is None :
return np . dot (Y ,W.T)
return np . dot (Y , W .T) + mu



# read images
[X , y] = read_images ('D:\homework and assignments\computer vision\face and gender recognition\images')
# perform a full pca
[D , W , mu ] = pca ( asRowMatrix (X ) , y)
# import tinyfacerec modules
from tinyfacerec.subspace import pca
from tinyfacerec.util import normalize, asRowMatrix, read_images
from tinyfacerec.visual import subplot

if __name__ == '__main__':

    if len(sys.argv) != 2:
        print "USAGE: example_eigenfaces.py </path/to/images>"
        sys.exit()

    # read images
    [X, y] = read_images(sys.argv[1])

    # perform a full pca
    [D, W, mu] = pca(asRowMatrix(X), y)

    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(len(X), 16)):
        e = W[:, i].reshape(X[0].shape)
        E.append(normalize(e, 0, 255))
    # plot them and store the plot to "python_eigenfaces.pdf"
    subplot(title="Eigenfaces AT&T Facedatabase",
            images=E,
            rows=4,
            cols=4,
            sptitle="Eigenface",
示例#7
0
import sys
# append tinyfacerec to module search path
sys.path.append("..")
# import numpy and matplotlib colormaps
import numpy as np
# import tinyfacerec modules
from tinyfacerec.subspace import pca
from tinyfacerec.util import normalize, asRowMatrix, read_images
from tinyfacerec.visual import subplot

# read images
[X,y] = read_images('att_faces')
# perform a full pca
[D, W, mu] = pca(asRowMatrix(X[1:]), y)

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 range(min(len(X), 16)):
	e = W[:,i].reshape(X[0].shape)
	E.append(normalize(e,0,255))
# plot them and store the plot to "python_eigenfaces.pdf"
subplot(title="Eigenfaces AT&T Facedatabase", images=E, rows=4, cols=4, sptitle="Eigenface", colormap=cm.gray, filename="python_pca_eigenfaces.pdf")

from tinyfacerec.subspace import project, reconstruct

# reconstruction steps
steps=[i for i in range(10, min(len(X), 400), 20)]
E = []
示例#8
0
# import tinyfacerec modules
from tinyfacerec.subspace import pca
from tinyfacerec.util import normalize, asRowMatrix, read_images
from tinyfacerec.visual import subplot

if __name__ == '__main__':

    if len(sys.argv) != 2:
        print "USAGE: example_eigenfaces.py </path/to/images>"
        sys.exit()
    
    # read images
    [X,y] = read_images(sys.argv[1])

    # perform a full pca
    [D, W, mu] = pca(asRowMatrix(X), y)

    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(len(X), 16)):
	    e = W[:,i].reshape(X[0].shape)
	    E.append(normalize(e,0,255))
    # plot them and store the plot to "python_eigenfaces.pdf"
    subplot(title="Eigenfaces AT&T Facedatabase", images=E, rows=4, cols=4, sptitle="Eigenface", colormap=cm.jet, filename="python_pca_eigenfaces.png")

    from tinyfacerec.subspace import project, reconstruct

    # reconstruction steps