Ask Your Question

# image step not continuous after dividing an image

Hi everyone,

I am try to divide an image into blocks in opencv and i get the "Error image step is not continuous". Pls here is my code need your help.

vector<Mat> ilmage;
int N = (images[0].cols * images[0].rows) / (x*y);
Mat t;

int m = images[0].rows / x;
int n = images[0].cols / y;
int i2, i3, i4, i5;
Size smallsize(n, m);

for (int i = 0; i < images.size(); i++){
for (int j = 0; j < images[i].rows; j += smallsize.height){
for (int k = 0; k < images[i].cols; k += smallsize.width ){
//i2 = k*n, i3 = n, i4 = j*m; i5 = m;
t = images[i](Rect(k, j, smallsize.width,smallsize.height));
ilmage.push_back(transpose(t.reshape(0, N)));
}
}
pImage.push_back(ilmage);
ilmage.clear();
}


Regards.

edit retag close merge delete

## Comments

2

i did not try your code. i suggest you to try

t = images[i](Rect(k, j, smallsize.width,smallsize.height)).clone(); // try changing this line

( 2015-08-24 06:59:10 -0500 )edit

@berak could you convert your comment as answer

( 2015-08-24 07:36:03 -0500 )edit
2

i got another idea: @valentine, would you apply the proposed changes, and submit the successful results as an answer ?

( 2015-08-24 07:41:06 -0500 )edit

Its working now. i had to clone the image before reshaping. @berak the x and y values are the different blocks am dividing the cols and rows of the image into. Thanks sturkmen and berak.

( 2015-08-24 07:41:42 -0500 )edit

## 1 answer

Sort by ยป oldest newest most voted

^^ ah, nicely spotted. indeed, you cannot reshape() a roi (without cloning).

@valentine, i got 2 other objections:

 int m = images[0].rows / x;  // y !!
int n = images[0].cols / y;    // x !!


and:

for (int j = 0; j < images[i].rows - m; j += m) {
for (int k = 0; k < images[i].cols - n; k += n) {

more

Official site

GitHub

Wiki

Documentation

## Stats

Asked: 2015-08-24 06:31:52 -0500

Seen: 56 times

Last updated: Aug 24 '15