Ask Your Question
0

how can i reshape a Mat 2D to vector<vector<Mat>>

asked 2017-07-25 04:10:51 -0600

Alvaro gravatar image

updated 2017-07-25 05:31:28 -0600

i would like to convert a Mat whose dimensions are [2000][256] and i want to convert this to a vector<vector<mat>> with dimensions [256][20][10][10]. In matlab it is posible to do reshape(Mat2d, 10, 10, 20, 256), i would like to do the same

edit retag flag offensive close merge delete

Comments

So you want a vector<vector<vector<uint8>>> containing 10 continuous elements? I don't think that is usefull but you could write a function for this purpose. Do you know how to access the pixels in a mat?

Franz Kaiser gravatar imageFranz Kaiser ( 2017-07-25 12:03:00 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-07-26 04:46:28 -0600

Alvaro gravatar image

i found a solution:

vector<vector<Mat>> B;
for (int i = 0; i<dim1; i++) {
    B.push_back(vector<Mat>());
    for (int j = 0; j<dim2; j++)
        B[i].push_back(Mat(dim3, dim4, CV_64F, Scalar::all(1)));
}
Mat in = A.reshape(1, 1);
Mat subImg;
for (int i = 0; i < 256; i++)
{
    for (int j = 0; j < 20; j++)
    {
        subImg = in(cv::Range(0, 1), cv::Range(100 * j, 100 * j + 100));
        subImg.reshape(10, 10);
        B[i][j] = subImg;
    }
}
return B;
edit flag offensive delete link more

Comments

Okay, i didn't use the reshape command before. Is the performance sufficient for you?

Franz Kaiser gravatar imageFranz Kaiser ( 2017-07-26 05:36:56 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-07-25 04:10:51 -0600

Seen: 511 times

Last updated: Jul 25 '17