Accessing slices of a 3d Matrix

asked 2014-06-02 10:20:41 -0600

mytimetorise gravatar image

updated 2015-01-09 03:08:07 -0600

I would like to store 592 47x47 arrays into a 47x47x592 Matrix. I created the 3d Matrix as follows:

int sizes[] = {47,47,592};

Mat 3dmat(3, sizes, CV_32FC1);

I then thought I could access it by using a set of ranges as in the following.

Range ranges[3];

ranges[0] = Range::all();

ranges[1] = Range::all();

ranges[2] = Range(x,x+1) //within a for loop.

Mat 2dmat = 3dmat(ranges);

However, when I try to use the copyTo function to input an existing data set, it does not work.

data.copyTo(2dmat); //data is my 47x47 matrix

The 3d matrix does not get updated when I do this.

Any information is appreciated! Thanks!

edit retag flag offensive close merge delete

Comments

2

What I do is create a vector of matrix elements. This allows me to easily access the vector index. But it is possible that this is not as effective as the suggestion below.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-01-09 03:39:56 -0600 )edit