source: libs/magicsquares/python/plot_faces.py @ 213

Revision 213, 1.0 KB checked in by dave, 10 years ago (diff)

moved FaceET

Line 
1#!/usr/bin/env python
2
3import glob,string
4from magicsquares import *
5from faces import *
6       
7#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8
9def get_params(filename,pca,w,h):
10        i = Image(filename)
11        v = i.Scale(w,h).RGB2GRAY().ToFloatVector()
12        p = pca.Project(v)
13        return str(p[0])+" "+str(p[1])+" "+str(p[2])
14
15def plot_all(path, w, h):
16        images = glob.glob(path)
17        ret = ""
18        for image in images:
19                ret=ret+get_params(image,pca,w,h)+"\n"
20        return ret
21       
22def plot_individual(n):
23        f = open("individual"+str(n),"w")
24        f.write(plot_all("../data/benchmark/yale/training/"+str(n)+"/*.jpg",w,h))
25        f.close()
26
27def plot_test_individual(n):
28        f = open("individual"+str(n),"w")
29        f.write(plot_all("../data/benchmark/yale/test/yaleB0"+str(n)+"*.jpg",w,h))
30        f.close()
31
32#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33
34pca = load_pca("../data/eigenspaces/spacek-20x30.pca")
35w = 20
36h = 30
37pca.Compress(36,40)
38
39plot_test_individual(0)
40plot_test_individual(1)
41plot_test_individual(2)
42plot_test_individual(3)
43plot_test_individual(4)
44plot_test_individual(5)
45
Note: See TracBrowser for help on using the repository browser.