First time here? Check out the FAQ!

Ask Your Question
0

Reconstructing vector from given image

asked Aug 20 '14

Iona gravatar image

updated Aug 20 '14

thdrksdfthmn gravatar 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.

Preview: (hide)

1 answer

Sort by » oldest newest most voted
0

answered Aug 20 '14

thdrksdfthmn gravatar image

In the first code part: Who is J?

In the second: matimg.data 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 = (matimg.data + i2 * matimg.step)[j2  * matimg.elemSize() + k2 ];

or:

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

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

Preview: (hide)

Comments

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 (Aug 20 '14)edit

Question Tools

Stats

Asked: Aug 20 '14

Seen: 255 times

Last updated: Aug 20 '14