# Reconstructing vector from given image

Hello,

I have a vector:

```
vector<vector<double> > output2(rr1, vector<double>(cc1));
output2 = wt_output;
IplImage *OutputImg;
CvSize img;
```

output2 holds the image information which is basically the output of 2D discrete wavelet transform, wt_output. I wanted to construct an image out of the vector. So I went through the following loop:

```
for (int i = 0; i < img.height; i++ )
{
for (int j = 0; j < img.width; j++ )
{
if ( wt_output[i][j] <= 0.0)
{
wt_output[i][j] = 0.0;
}
if ( i <= (img.height/pow(2.0,double(J))) && j<=(img.width/pow(2.0,double(J))) )
{
((uchar*)(OutputImg->imageData + OutputImg->widthStep*i))[j]=(char) ( (wt_output[i][j] / max) * 255.0);
}
else
{
((uchar*)(OutputImg->imageData + OutputImg->widthStep*i))[j]=(char) (wt_output[i][j]) ;
}
}
}
```

I am able to construct and display the scaled image, OutputImg. However, the problem starts here: I need to convert OutputImg to vector again. Due to certain constraints, I do not want to use output2. Hence I went through the following loop to convert OutputImg to vector equivalent to output2.

```
int height2, width2;
height2 = OutputImg.rows;
width2 = OutputImg.cols;
CvSize size2;
size2.width =width2;
size2.height=height2;
int rows2 =(int) height2;
int cols2 =(int) width2;
Mat matimg(OutputImg);
vector<vector<double> > vec2(rows2, vector<double>(cols2));
int k2 =1;
for (int i2=0; i2 < rows2; i2++) {
for (int j2 =0; j2 < cols2; j2++){
unsigned char temp2;
temp2 = ((uchar*) matimg.data + i2 * matimg.step)[j2 * matimg.elemSize() + k2 ];
vec2[i2][j2] = (double) temp2;
}
}
```

The problem is the output vec2 is not equivalent to output2. What could be the problem in this loop. Any help would be appreciated.