本文整理汇总了C++中PCA::dim方法的典型用法代码示例。如果您正苦于以下问题:C++ PCA::dim方法的具体用法?C++ PCA::dim怎么用?C++ PCA::dim使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PCA
的用法示例。
在下文中一共展示了PCA::dim方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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];
}
}
//.........这里部分代码省略.........
示例2: 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());
}
}
}