Get the data of 3-dimension Mat

I have a 256*256*16 mat, symbolizing 16 256*256pixel images. And I want to get the pixel information of specific image. This can be easily done in python and Matlab. But I don’t know how to implement in C++ and I haven’t found proper func in OpenCV. It seems the expression Mat B = A(cv::Range(0, 2), cv::Range(0, 2), 1) is wrong.

#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;
using namespace cv;

int main()
{
	int Dimensions[3] = {16, 16, 2};
	auto A = cv::Mat(3, Dimensions, CV_8UC1);
	for (int i = 0; i < Dimensions[2]; i++)
	{
		for (int j = 0; j < Dimensions[1]; j++)
		{
			for (int k = 0; k < Dimensions[0]; k++)
			{
				A.at<uchar>(k, j, i) = i + j + k;
			}
		}
	}
	Mat B = A(cv::Range(0, 2), cv::Range(0, 2), 1);
}

where did you get this from ?
please show resp. code snippet, and explain the “context”

why not simply use a vector<Mat> ?
and IF you have to use a multidimensional Mat, why not make it 16*256*256 ?
(so you have 16 consecutive planes in memory, and Mat(256,256,CV_8UC1, A.ptr(4)) would be the 5th 2d plane)

indeed, it is. applying ranges makes only sense with 2d Mat’s here.