Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

well assuming vector[row][channel][col] it would be like:

std::vector< std::vector< std::vector  <uint16_t> > > BIL;

vector<Mat> chans(3); // 3 mat's with seperate channels, initially empty (!)
for (int r=0; r<nrows; r++) {
    for (int c=0; c<nchannels; c++) {
        // vectors can be converted, but they're originally vertical.
        Mat row = Mat(BIL[r][c]).reshape(1,1); 
        chans[c].push_back(row); // append a per-channel line
    }
}

note, that this needs to copy all of of your data. opencv's Mat's need consecutive memory, not row-pointers.

well assuming vector[row][channel][col] it would be like:

std::vector< std::vector< std::vector  <uint16_t> > > BIL;

vector<Mat> chans(3); // 3 mat's with seperate channels, initially empty (!)
for (int r=0; r<nrows; r++) {
    for (int c=0; c<nchannels; c++) {
        // vectors can be converted, but they're originally vertical.
        Mat row = Mat(BIL[r][c]).reshape(1,1); 
        chans[c].push_back(row); // append a per-channel line
    }
}

note, that this needs to copy all of of your data. opencv's Mat's need consecutive memory, not row-pointers.

edit:

here's a somewhat less intuitive, but slightly more effective version, avoiding the reallocations:

vector<Mat> chans(3); // 3 mat's with seperate channels, initially empty (!)
for (int c=0; c<nchannels; c++) { // loops reordered !
    int ncols = BIL[0][0].size();
    chans[i].create(nrows, ncols, CV_16U); // allocate mem for a whole channel.
    for (int r=0; r<nrows; r++) {
        // vectors can be converted, but they're originally vertical.
        Mat row = Mat(BIL[r][c]).reshape(1,1); 
        row.copyTo(chans[c]); 
    }
}

well assuming vector[row][channel][col] it would be like:

std::vector< std::vector< std::vector  <uint16_t> > > BIL;

vector<Mat> chans(3); // 3 mat's with seperate channels, initially empty (!)
for (int r=0; r<nrows; r++) {
    for (int c=0; c<nchannels; c++) {
        // vectors can be converted, but they're originally vertical.
        Mat row = Mat(BIL[r][c]).reshape(1,1); 
        chans[c].push_back(row); // append a per-channel line
    }
}

note, that this needs to copy all of of your data. opencv's Mat's need consecutive memory, not row-pointers.

edit:

here's a somewhat less intuitive, but slightly more effective version, avoiding the reallocations:

vector<Mat> chans(3); // 3 mat's with seperate channels, initially empty (!)
for (int c=0; c<nchannels; c++) { // loops reordered !
    int ncols = BIL[0][0].size();
    chans[i].create(nrows, ncols, CV_16U); // allocate mem for a whole channel.
    for (int r=0; r<nrows; r++) {
        // vectors can be converted, but they're originally vertical.
        Mat row = Mat(BIL[r][c]).reshape(1,1); 
        row.copyTo(chans[c]); row.copyTo(chans[c].row(r)); 
    }
}

well assuming vector[row][channel][col] it would be like:

std::vector< std::vector< std::vector  <uint16_t> > > BIL;

vector<Mat> chans(3); // 3 mat's with seperate channels, initially empty (!)
for (int r=0; r<nrows; r++) {
    for (int c=0; c<nchannels; c++) {
        // vectors can be converted, but they're originally vertical.
        Mat row = Mat(BIL[r][c]).reshape(1,1); 
        chans[c].push_back(row); // append a per-channel line
    }
}

note, that this needs to copy all of of your data. opencv's Mat's need consecutive memory, not row-pointers.

edit:

here's a somewhat less intuitive, but slightly more effective version, avoiding the reallocations:

vector<Mat> chans(3); // 3 mat's with seperate channels, initially empty (!)
 for (int c=0; c<nchannels; c++) { // loops reordered !
    int ncols = BIL[0][0].size();
    chans[i].create(nrows, chans[c].create(nrows, ncols, CV_16U); // allocate mem for a whole channel.
    for (int r=0; r<nrows; r++) {
        // vectors can be converted, but they're originally vertical.
        Mat row = Mat(BIL[r][c]).reshape(1,1);  // now horizontal
        row.copyTo(chans[c].row(r)); 
    }
}