# 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
    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)
Example #2
0
    # 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
    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")
Example #3
0
[X,y] = read_images("/home/priyanka/Desktop/CV/scripts/att_faces")


[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 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.jet, filename="python_pca_eigenfaces.pdf")

from tinyfacerec.subspace import project, reconstruct

# reconstruction steps
steps=[i for i in range(10, min(len(X), 320), 20)]
E = []
for i in range(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)
	# print(R)
	# print(E)
	# reshape and append to plots
	R = R.reshape(X[0].shape)
	
        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")
Example #5
0
    [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"