# 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
    steps = [i for i in xrange(10, min(len(X), 320), 20)]
    E = []
    for i in xrange(min(len(steps), 16)):
        numEvs = steps[i]
        P = project(W[:, 0:numEvs], X[0].reshape(1, -1), mu)
        R = reconstruct(W[:, 0:numEvs], P, mu)
        # reshape and append to plots
        R = R.reshape(X[0].shape)
        E.append(normalize(R, 0, 255))
    # plot them and store the plot to "python_reconstruction.pdf"
    subplot(title="Reconstruction AT&T Facedatabase",
            images=E,
            rows=4,
            cols=4,
            sptitle="Eigenvectors",
            sptitles=steps,
            colormap=cm.gray,
            filename="python_pca_reconstruction.png")
        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)):
	    e = W[:,i].reshape(-1,1)
	    P = project(e, X[0].reshape(1,-1), mu)
	    R = reconstruct(e, P, mu)
	    # reshape and append to plots
	    R = R.reshape(X[0].shape)
	    E.append(normalize(R,0,255))
    # plot them and store the plot to "python_reconstruction.pdf"
    subplot(title="Fisherfaces Reconstruction Yale FDB", images=E, rows=4, cols=4, sptitle="Fisherface", colormap=cm.gray, filename="python_fisherfaces_reconstruction.png")
Esempio n. 3
0
    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
    steps=[i for i in xrange(10, min(len(X), 320), 20)]
    E = []
    for i in xrange(min(len(steps), 16)):
	    numEvs = steps[i]
	    P = project(W[:,0:numEvs], X[0].reshape(1,-1), mu)
	    R = reconstruct(W[:,0:numEvs], P, mu)
	    # reshape and append to plots
	    R = R.reshape(X[0].shape)
	    E.append(normalize(R,0,255))
    # plot them and store the plot to "python_reconstruction.pdf"
    subplot(title="Reconstruction AT&T Facedatabase", images=E, rows=4, cols=4, sptitle="Eigenvectors", sptitles=steps, colormap=cm.gray, filename="python_pca_reconstruction.png")

########NEW FILE########
__FILENAME__ = example_fisherfaces
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 fisherfaces
Esempio n. 4
0
    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)):
        e = W[:, i].reshape(-1, 1)
        P = project(e, X[0].reshape(1, -1), mu)
        R = reconstruct(e, P, mu)
        # reshape and append to plots
        R = R.reshape(X[0].shape)
        E.append(normalize(R, 0, 255))
    # plot them and store the plot to "python_reconstruction.pdf"
    subplot(title="Fisherfaces Reconstruction Yale FDB",
            images=E,
            rows=4,
            cols=4,
            sptitle="Fisherface",
            colormap=cm.gray,
            filename="python_fisherfaces_reconstruction.png")