Reputation: 21
I want to divide an image into peices of smaller images. I have a 8192x8192 pixel image which I want to divide into 1024 smaller images with 256x256 pixels. So i woulde get a Matrix that looks like 256x256x1024.
I try to do it like this:
im = 8192x8192x1 pixel, grayscale image ( only the Red spectra for example)
Mat imSeparate(Mat im) {
Mat tmp = im;
Mat tmp1;
int tmp_x = tmp.rows / 256;
int tmp_y = tmp.cols / 256;
int tmp_tot = tmp_x*tmp_y;
tmp1 = tmp.reshape(tmp_tot, 256);
return tmp1;
}
But for some wierd reason i cannot understand, it reshapes it to 512x256x256 matrix.
According to opencv:s homepage (http://docs.opencv.org/modules/core/doc/basic_structures.html#mat-reshape) the product of rowscolschannels() must be the same after transformation which duuh is obvious.
So at first the image is 8192x8192 = 67108864 pixels, then after my requested reshape it should be as mentioned 256x256x1024 = 67108864 pixels. But no no its 256x256x512 = 33554432 pixels.... where did half of the image go???
Myabe Im just to retarded to see what the fault is, but does anyone have any clue about this or any other good suggestion to divide the image into smaller peices?
Also I dont know exactly how reshape is doing this, but I assume that the first channel will be the x = 1 to 256, y = 1 to 256 pixels and the 2nd channel will be x = 257 to 512, y = 1 to 256 pixels or the other way around depending if takes it row-wise or col-wise.
Upvotes: 0
Views: 1152
Reputation: 20130
the maximum number of channels is limited:
The maximum possible number of channels is defined by the CV_CN_MAX constant, which is currently set to 512
taken from
http://docs.opencv.org/opencv2refman.pdf
page 5 or 11
not sure if you can compile openCV simply with another value for CV_CN_MAX
Upvotes: 2