title: PCA project and backproject in Opencv
body: <p>I am working in Ubuntu Opencv.I am trying to do PCA analysis of a single image.I take the 3 channel image and change it to a single channel image with 3 columns and r*c number of rows.r and c being the rows and columns of the original image.When I try to display the reconstructed image after doing the backprojection on the PCA it gives me a green image.Here is my code</p>
  
  <pre><code>Mat pcaset=cvCreateMat(image-&gt;height*image-&gt;width,image-&gt;nChannels,CV_8UC1);
  for(int i=0;i&lt;image-&gt;height;i++)
      {
          for(int j=0;j&lt;image-&gt;width;j++)
          {
              for(int k=0;k&lt;image-&gt;nChannels;k++)
              (ptrpcaset+i*pcaset.step)[k]=((ptrimage+i*image-&gt;widthStep)[3*j+k]);
  
         }
  
      }
  int nEigens=3;
      Mat databackprojected;
      PCA pca(pcaset,Mat(),CV_PCA_DATA_AS_ROW,nEigens);
      Mat dataprojected(pcaset.rows,nEigens,CV_8UC1);
      pca.project(pcaset,dataprojected);
      pca.backProject(dataprojected,databackprojected);
      Mat backprojectnorm;//(databackprojected.rows,nEigens,CV_8UC1);
      normalize(databackprojected,backprojectnorm,0,255,NORM_MINMAX,-1);
      Mat finaldataafterreshaping(image-&gt;height,image-&gt;width,CV_8UC3);
      uchar* finalptr=(uchar*)finaldataafterreshaping.data;
      uchar* ptrnorm=(uchar*)backprojectnorm.data;
  
      int x=0,y=0,i=0;
  
      while(i&lt;backprojectnorm.rows)
      {
          while(x&lt;image-&gt;height)
          {
              while(y&lt;image-&gt;width)
              {
                  for(int k=0;k&lt;image-&gt;nChannels;k++)
                  {
                      (finalptr+x*finaldataafterreshaping.step)[3*y+k]=(ptrnorm+i*backprojectnorm.step)[k];
                  }
                  y=y+1;i=i+1;
              }
              x=x+1;y=0;
          }
      }
  imshow("Reconstructed data",finaldataafterreshaping);
  </code></pre>