Changeset 97 for foam/trunk/eigentools
- Timestamp:
- 08/03/2009 01:42:48 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
foam/trunk/eigentools/src/main.cpp
r96 r97 39 39 #include "Vector.h" 40 40 #include "PCA.h" 41 #include <glob.h>41 #include "FileTools.h" 42 42 43 43 using namespace std; … … 58 58 Image src("../data/images/faces/dave/dave.png"); 59 59 60 void Recalc() 61 { 62 glob_t g; 63 64 glob("../data/images/faces/dave/*.png",GLOB_PERIOD,NULL,&g); 65 for (unsigned int n=0; n<g.gl_pathc; n++) 66 { 67 string path=g.gl_pathv[n]; 68 cerr<<path<<endl; 69 Image im(path); 70 //im.SubMean(); 60 void Generate(PCA &pca, const string &imagepath) 61 { 62 vector<string> images=Glob(imagepath); 63 for (vector<string>::iterator i=images.begin(); i!=images.end(); i++) 64 { 65 cerr<<*i<<endl; 66 Image im(*i); 71 67 Vector<float> v(im.Scale(w,h).RGB2GRAY().ToFloatVector()); 72 68 v-=v.Mean(); 73 69 pca.AddFeature(v); 74 } 75 globfree (&g); 76 70 } 77 71 pca.Calculate(); 72 } 73 74 PCA MakeSubspace(const PCA &space, const string &imagepath) 75 { 76 PCA subspace(space.GetFeatureSize()); 77 78 // find the transform based on the parameters 79 vector<string> images=Glob(imagepath); 80 for (vector<string>::iterator i=images.begin(); i!=images.end(); i++) 81 { 82 cerr<<*i<<endl; 83 Image im(*i); 84 Vector<float> v(im.Scale(w,h).RGB2GRAY().ToFloatVector()); 85 v-=v.Mean(); 86 subspace.AddFeature(space.Project(v)); 87 } 88 89 subspace.Calculate(); 90 91 // project back each row 92 // think there must be a much much better way to do this... 93 for (int i=0; i<subspace.EigenTransform().GetRows(); i++) 94 { 95 cerr<<"row: "<<i<<endl; 96 Vector<float> row = subspace.EigenTransform().GetRowVector(i); 97 subspace.EigenTransform().SetRowVector(i, 98 pca.Synth(row)); 99 } 100 101 return subspace; 78 102 } 79 103 … … 87 111 } 88 112 113 void SavePCA(const PCA &pca, string filename) 114 { 115 FILE *f=fopen(filename.c_str(), "wb"); 116 pca.Save(f); 117 fclose(f); 118 } 119 89 120 void TestPCA() 90 121 { … … 93 124 //pca.Save(f); 94 125 pca = LoadPCA("../data/eigenspaces/spacek-20x30.pca"); 95 96 PCA davelight = LoadPCA("davelight-20x30.pca"); 97 //pca.Mult(davelight); 98 pca = davelight; 99 100 pca.Compress(0,100); 126 PCA subspace = LoadPCA("dave-resynthed-sub.pca"); 127 128 //pca.Compress(0,10); 129 //pca.Compress(0,30); 130 131 //pca.EigenTransform() *= subspace.EigenTransform().Transposed(); 132 133 PCA davesubspace = MakeSubspace(pca,"../data/images/faces/dave/*.png"); 134 SavePCA(davesubspace,"davelight-spacek-20x30.pca"); 135 101 136 src = src.Scale(w,h).RGB2GRAY(); 102 137 Vector<float> d(src.ToFloatVector()); … … 325 360 326 361 static float t=0; 327 cerr<<sin(t)<<endl; 328 for (unsigned int i=0; i<100; i++) 329 { 330 camera.Blit(Image(w,h,1,(pca.GetEigenTransform().GetRowVector(i)*50*sin(t))/((i+1) * 1)+pca.GetMean() 362 363 for (unsigned int i=0; i<10; i++) 364 { 365 //camera.Blit(Image(w,h,1,(pca.GetEigenTransform().GetRowVector(i)*50*sin(t))/((i+1) * 1) //+pca.GetMean() 366 // ),(i%30)*(w+2),0+(i/30)*(h+2)); 367 camera.Blit(Image(w,h,1,pca.GetEigenTransform().GetRowVector(i)*3 //+pca.GetMean() 331 368 ),(i%30)*(w+2),0+(i/30)*(h+2)); 332 369 }
Note: See TracChangeset
for help on using the changeset viewer.