Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

there is no magic, it is just a lot of "footwork":

Mat_<float> M(6,6); // demo data
M << 1,2,3,4,5,6, 
     2,3,4,5,6,7,
     3,4,5,6,7,8,
     4,5,6,7,8,9,
     5,6,7,8,9,0,
     6,7,8,9,0,1;

Mat N; // target
int offset = 0; // 0 for odd, 1 for even
for (int i=offset; i<M.cols; i+=2)
{
    Mat col = M.col(i);
    if (N.empty()) // 1st time, copy
        N = col; 
    else
        hconcat(N,col,N); // append to the right
}

cerr << N << endl;

[1, 3, 5;
  2, 4, 6;
  3, 5, 7;
  4, 6, 8;
  5, 7, 9;
  6, 8, 0]

there is no magic, it is just a lot of "footwork":

Mat_<float> M(6,6); // demo data
M << 1,2,3,4,5,6, 
     2,3,4,5,6,7,
     3,4,5,6,7,8,
     4,5,6,7,8,9,
     5,6,7,8,9,0,
     6,7,8,9,0,1;

Mat N; // target
int offset = 0; // 0 for odd, even, 1 for even
odd
for (int i=offset; i<M.cols; i+=2)
{
    Mat col = M.col(i);
    if (N.empty()) // 1st time, copy
        N = col; 
    else
        hconcat(N,col,N); // append to the right
}

cerr << N << endl;

[1, 3, 5;
  2, 4, 6;
  3, 5, 7;
  4, 6, 8;
  5, 7, 9;
  6, 8, 0]