本文整理汇总了C++中PCA::backTransform方法的典型用法代码示例。如果您正苦于以下问题:C++ PCA::backTransform方法的具体用法?C++ PCA::backTransform怎么用?C++ PCA::backTransform使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PCA
的用法示例。
在下文中一共展示了PCA::backTransform方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc , char **argv) {
GetPot cl(argc,argv);
if(cl.search("-h")) {USAGE(); exit(0);}
string line;
if(cl.search("-E")) {
cout << "Estimating PCA" << endl;
ifstream filelist(cl.follow("filelist","-E"));
ImageFeature img;
getline(filelist,line);
img.load(line,true);
cout << line << endl;
PCA pca(img.size());
cout << img.size() << endl;
pca.putData(img.layerVector(0));
while(getline(filelist,line)) {
cout << line << endl;
img.load(line,true);
pca.putData(img.layerVector(0));
}
pca.dataEnd();
pca.save(cl.follow("covariance.pca","-c"));
pca.calcPCA();
pca.save(cl.follow("transformation.pca","-t"));
filelist.close();
} else if(cl.search("-T")) {
PCA pca;
pca.load(cl.follow("transformation.pca","-t"));
int dim=cl.follow(20,"-d");
ifstream filelist(cl.follow("filelist","-T"));
vector<double> tmp;
ImageFeature img;
while(getline(filelist,line)) {
cout << line << endl;
img.load(line,true);
tmp=pca.transform(img.layerVector(0),img.size());
tmp.resize(dim);
VectorFeature tmpvec(tmp);
tmpvec.save(line+".pca.vec.gz");
}
filelist.close();
} else if(cl.search("-B")) {
PCA pca;
pca.load(cl.follow("transformation.pca","-t"));
int x=cl.follow(16,"-x");
int y=cl.follow(16,"-y");
ifstream filelist(cl.follow("filelist","-B"));
vector<double> tmp;
VectorFeature tmpvec;
while(getline(filelist,line)) {
cout << line << endl;
tmpvec.load(line);
vector<double> tmp;
tmp=pca.backTransform(tmpvec.data());
ImageFeature img(tmp,x,y);
cutoff(img);
img.save(line+".backpca.png");
}
filelist.close();
} else if(cl.search("-M")) {
ImageFeature img; img.load(cl.follow("image.png","-M"),true);
PCA pca;
vector<double> backproj,vec;
pca.load(cl.follow("transformation.pca","-t"));
int w=cl.follow(16,"-x");
int h=cl.follow(16,"-y");
double scalefac=cl.follow(0.8333,"-s");
int dim=cl.follow(20,"-d");
ImageFeature scimg(img);
ImageFeature patch;
uint minX=100000, minY=100000;
uint maxX=100000, maxY=100000;
while(int(scimg.xsize())>=w and int(scimg.ysize())>=h) {
DBG(10) << VAR(scimg.xsize()) << " x " << VAR(scimg.ysize()) << endl;
ImageFeature faceprobmap(scimg.xsize(),scimg.ysize(),1);
double maxDist=0.0;
double minDist=numeric_limits<double>::max();
vector<double> tmpvec;
for(uint x=0;x<scimg.xsize();++x) {
DBG(10) << VAR(x) << endl;
for(uint y=0;y<scimg.ysize();++y) {
patch=getPatch(scimg,x,y,x+w,y+h);
vec=patch.layerVector(0);
vector<double> imgMinMean=vec;
for(uint i=0;i<imgMinMean.size();++i) {
imgMinMean[i]-=pca.mean()[i];
//.........这里部分代码省略.........
示例2: main
int main(int argc, char**argv) {
GetPot cl(argc, argv);
if(cl.search(2,"-h","--help")) {USAGE(); exit(0);}
string pcafile=cl.follow("pca.pca",2,"-p","--pca");
string imagefile=cl.follow("image",2,"-i","--img");
VectorFeature vec;
PCA pca; pca.load(pcafile);
uint width, height, depth;
if(cl.search(2,"-c","--color")) {
depth=3;
} else {
depth=1;
}
if(!cl.search(2,"-w","--width") && !cl.search(2,"-h","--height")) {
width=uint(sqrt(double(pca.dim())));
height=width;
if(int(height*width)!=pca.dim()) {
ERR << "pca not for squared images, specify width or height" << endl
<< "height=" << height << "* width=" << width << "!= size=" << pca.dim() << endl;
exit(20);
}
} else {
if(cl.search(2,"-w","--width") && !cl.search(2,"-h","--height")) {
width=cl.follow(10,2,"-w","--width");
height=pca.dim()/width;
if(int(height*width)!=pca.dim()) {
ERR << "pca images of this width, specify valid values" << endl
<< "height=" << height << "* width=" << width << "!= size=" << pca.dim() << endl;
exit(20);
}
} else if(!cl.search(2,"-w","--width") && cl.search(2,"-h","--height")) {
height=cl.follow(10,2,"-j","--height");
width=pca.dim()/height;
if(int(height*width)!=pca.dim()) {
ERR << "pca images of this height, specify valid values" << endl
<< "height=" << height << "* width=" << width << "!= size=" << pca.dim() << endl;
exit(20);
}
} else {
height=cl.follow(10,2,"-j","--height");
width=cl.follow(10,2,"-w","--width");
if(int(height*width)!=pca.dim()) {
ERR << "pca images of this height and width, specify valid values" << endl
<< "height=" << height << "* width=" << width << "!= size=" << pca.dim() << endl;
exit(20);
}
}
}
vector<double> backtransformed;
if(cl.search(2,"-v","--vec") && !cl.search(2,"-b","--base") && !cl.search(2,"-M","--mean")) {
string vecfile=cl.follow("vec.vec",2,"-v","--vec");
DBG(10) << "Loading Vectorfile " << vecfile << endl;
vec.load(vecfile);
DBG(10) << "Vector to be backtransformed" ;
for(uint i=0;i<vec.size();++i) {
BLINK(10) << " "<< vec[i];
}
BLINK(10) << endl;
if(cl.search("-n1st")) vec[0]=0;
if(cl.search("--nopca")) {
backtransformed=vec.data();
} else {
backtransformed=pca.backTransform(vec.data());
}
DBG(10) << "Backtransformed Vector" ;
for(uint i=0;i<backtransformed.size();++i) {
BLINK(10) << " " <<backtransformed[i];
}
BLINK(10) << endl;
} else if(cl.search(2,"-b","--base") && !cl.search(2,"-v","--vec") && !cl.search(2,"-M","--mean")) {
uint base=cl.follow(0,2,"-b","--base");
backtransformed=pca.eigenvector(base);
} else if(!cl.search(2,"-b","--base") && !cl.search(2,"-v","--vec") && cl.search(2,"-M","--mean")) {
backtransformed=pca.mean();
} else {
USAGE();
exit(20);
}
ImageFeature image(width,height,depth);
if(cl.search(2,"-m","--minMean")) {
DBG(10) << "Subtracting mean" << endl;
for(uint i=0;i<backtransformed.size();++i) {
backtransformed[i]-pca.mean()[i];
}
}
//.........这里部分代码省略.........
示例3: main
int main(int argc, char**argv) {
GetPot cl(argc, argv);
if(cl.search(2,"-h","--help") or !cl.search("-lf")) {USAGE(); exit(0);}
bool nonorm = cl.search(1, "-nonorm");
LocalFeatures lf; lf.load(cl.follow("test.lf.gz","-lf"));
uint sc = cl.follow(1, "-scale");
uint w=uint(lf.winsize()*2+1);
ImageFeature img(w,w,lf.zsize());
string savefilename = cl.follow("", "-save");
bool backtransform = false;
PCA pca;
if(cl.search("-unpca"))
{
if( !pca.load(cl.follow("", "-unpca")) )
{
ERR << "Error loading PCA file!" << endl;
abort();
}
backtransform = true;
}
bool dontshow = cl.search("-dontshow");
for(uint i=0;i<lf.size();++i) {
DBG(10) << "lf " << i << endl;
if(!backtransform) {
for(uint j=0;j<lf.dim();++j) {
img[j] = lf.getData()[i][j];
}
} else {
vector<double> backtransformed = pca.backTransform(lf.getData()[i]);
for(uint j=0;j<(uint)pca.dim();++j) {
img[j] = backtransformed[j];
}
}
if (sc != 1) {
img = scale(img, w * sc, w * sc);
}
if (!nonorm) {
normalize(img);
}
if(!dontshow) {
if(cl.search("-layerwise")) {
for(uint c=0;c<img.zsize();++c) {
BLINK(10) << " " << c;
img.display(c,c,c);
}
BLINK(10) << endl;
} else {
BLINK(10) << "all layers" << endl;;
img.display();
}
}
if (savefilename != "") {
std::ostringstream filenamewithnr;
filenamewithnr << savefilename << "_" << setw(3) << setfill('0') << i << ".png";
img.save(filenamewithnr.str());
}
}
}