Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

try to use more high-level opencv functionality. don't write for-loops, and use the builtin PCA:

// assumes: im1.channels() == im2.channels()
Mat fuse_pca(const Mat &im1, const Mat &im2)
{
    Mat c1 = im1.reshape(1, im1.total() * im1.channels());
    Mat c2 = im2.reshape(1, im2.total() * im1.channels());

    Mat dat;
    hconcat(c1,c2,dat);
    dat.convertTo(dat,CV_32F);

    PCA pca(dat, noArray(), 0, 1);
    Mat_<double> ev = pca.eigenvectors;
    Mat_<double> mu = pca.mean;

    Mat fusion;
    addWeighted(c1-mu(0,0), ev(0,0), c2-mu(0,1), ev(0,1), 0, fusion);
    return fusion.reshape(im1.channels(), im1.rows);
}

try to use more high-level opencv functionality. don't write for-loops, and use the builtin PCA:

// assumes: im1.channels() == im2.channels()
Mat fuse_pca(const Mat &im1, const Mat &im2)
{
    Mat c1 = im1.reshape(1, im1.total() * im1.channels());
    Mat c2 = im2.reshape(1, im2.total() * im1.channels());

    Mat dat;
    hconcat(c1,c2,dat);
    dat.convertTo(dat,CV_32F);

    PCA pca(dat, noArray(), 0, 1);
1); // keep 1 largest ev. only
    Mat_<double> ev = pca.eigenvectors;
    Mat_<double> mu = pca.mean;

    Mat fusion;
    addWeighted(c1-mu(0,0), ev(0,0), c2-mu(0,1), ev(0,1), 0, fusion);
    return fusion.reshape(im1.channels(), im1.rows);
}

try to use more high-level opencv functionality. don't write for-loops, and use the builtin PCA:

// assumes: im1.channels() == im2.channels()
im2.channels() &&
//          im1.size() == im2.size() 
Mat fuse_pca(const Mat &im1, const Mat &im2)
{
    Mat c1 = im1.reshape(1, im1.total() * im1.channels());
    Mat c2 = im2.reshape(1, im2.total() * im1.channels());
im2.channels());

    Mat dat;
    hconcat(c1,c2,dat);
    dat.convertTo(dat,CV_32F);

    PCA pca(dat, noArray(), 0, 1); // keep 1 largest ev. only
    Mat_<double> ev = pca.eigenvectors;
    Mat_<double> mu = pca.mean;

    Mat fusion;
    addWeighted(c1-mu(0,0), ev(0,0), c2-mu(0,1), ev(0,1), 0, fusion);
    return fusion.reshape(im1.channels(), im1.rows);
}

try to use more high-level opencv functionality. don't write for-loops, and use the builtin PCA:

// assumes: im1.channels() == im2.channels() &&
//          im1.size() == im2.size() 
Mat fuse_pca(const Mat &im1, const Mat &im2)
{
    Mat c1 = im1.reshape(1, im1.total() * im1.channels());
    Mat c2 = im2.reshape(1, im2.total() * im2.channels());

    Mat dat;
    hconcat(c1,c2,dat);
    dat.convertTo(dat,CV_32F);

    PCA pca(dat, noArray(), 0, 1); // keep 1 largest ev. only
    Mat_<double> ev = pca.eigenvectors;
    Mat_<double> mu = pca.mean;

    Mat fusion;
    addWeighted(c1-mu(0,0), ev(0,0), c2-mu(0,1), ev(0,1), 0, fusion);
    return fusion.reshape(im1.channels(), im1.rows);
}

mri pet pca