Hi all people. What I have to do is to decorrelate an image and obtain 3 components from it. First is achromatic and 2nd and 3rd components are chromatic. The decorellation is on the RGC components of an image to obtain an efficient decodification of input datas with PCA analysis, adapted to local statistics of image. I finally obtain 3 components. You can see Matlab's code to understand better:What I did is:

Code:
Mat colorDecorrelation(Mat img,int numColComp);

int main(){

if(img.empty()){
  cout<<"The image is empty \n";
  return -1;
}

namedWindow("Image Display", CV_WINDOW_AUTOSIZE);
imshow("Image Display", img);
waitKey(0);
destroyWindow("Image Display");

padSize = new int;
sz2filt_r = new int;
sz2filt_c = new int;

rows=img.rows;
cols= img.cols;
nChannels= img.channels();  
numColComp = nChannels ;

inCompImg = img.reshape(numColComp,rows*cols);

imgDecorr = colorDecorrelation(inCompImg,numColComp); //HERE I OBTAIN DECORRELATION, where I convert to CV_

rows=imgDecorr.rows;
cols=imgDecorr.cols;
nChannels= imgDecorr.channels();

imgDecorr.convertTo(rgbDecorrImg,CV_8UC3); //to return to first type CV_32FC3 or it doesn t work for compatibility with gemm function invocated by another one

// HERE I HAVE THE ERROR, BECAUSE I HAVE TO RESHAPE TO OBTAIN A MATRIXOF rgbDecorrImg as a matrix with size r-by-c-by-n with R=ROWS,C=COLS,,N= NUMBER OF CHANNELS. So I created 3 components. Do you know how to do it and how take any component to use it after in my work?

rgbDecorrImg = rgbDecorrImg.reshape(numColComp,img.rows); //ERROR
Howewer I put the colourDecorrelation function that is good for me.

Code:
Mat colorDecorrelation(Mat img,int numColComp){

   Mat V,D,A,Xdecorr,img_tr,img_f;
   Scalar mu;
   SVD svd;

   if(numColComp>1){

        img.convertTo(img_f,CV_32FC3);
        img_f=img_f.reshape(1,img.rows*img.cols); 
         mu=mean(img_f);
         subtract(img_f,mu,img_f);
        transpose(img_f,img_tr);
         A = img_tr * img_f;
        V = svd(A).u; 
        Xdecorr = img_f*V;

  }
  else 
      Xdecorr=img;

  return Xdecorr;
}