Ask Your Question

Reconstructing vector from given image

asked 2014-08-19 18:01:53 -0500

Iona gravatar image

updated 2014-08-20 04:36:11 -0500

thdrksdfthmn gravatar image


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);
          ((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;

    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*) + 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.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2014-08-20 04:47:20 -0500

thdrksdfthmn gravatar image

In the first code part: Who is J?

In the second: is a pointer (uchar*), so you always put in temp the value linked to the first element in the Mat. You shall use something like (I did not test it):

temp2 = ( + i2 * matimg.step)[j2  * matimg.elemSize() + k2 ];


temp2 = matimg.ptr(i2)[j2 + k2];

Anyway, the code does not seems to be the same...

edit flag offensive delete link more


J decides how many levels of dwt the image would go through. If J is 1, then 2 levels of dwt and if J is 2 then 3 levels of dwt.

I really appreciate your help. But your suggestion distorted the image completely.

Iona gravatar imageIona ( 2014-08-20 12:54:22 -0500 )edit
Login/Signup to Answer

Question Tools


Asked: 2014-08-19 18:01:53 -0500

Seen: 88 times

Last updated: Aug 20 '14