Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Image processing project with an error I can not solve

Hi people. I hope you can help me to solve this problem I can not solve from long time. I have to finish a project about image processing and I saw an error in the initial step. I have a code in Matlab I have to obtain it in C++ with OpenCV. I did not study Matlab and C++ neither too (just C) , so I don t know how continue my work. Please help.

As in this picture : C:\fakepath\imag.png

the initial target is :

Initial decorrelation on RGB color components of each image/frame to have an efficient codification (without duplication)of the input data through analysis of the principal components(PCA),adapted to local image statistics (rgbDecorr in Matlab's code). We obtain so 3 components Z1,Z2,Z3 in the image attached in the block figure Whitening color. This operation is performed by colorDecorrelaion function().

Matlab' s code :

 //initial stuff
 numColComp = compc; % 3 in case of color images, 1 in grayscale images
 inComp = reshape(im, r*c, numColComp);

 Decorr=colorDecorrelation(inComp,numColComp);

 rgbDecorr= reshape(Decorr, r, c, numColComp); //HERE

 clear Decorr;

 % Fourier transform of the achromatic component
 [imfft,sz2filt,padSize]=FourierTransform2D(rgbDecorr(:,:,1),achrLambda_max);

 //more stuff

 conspic2 = zeros(r,c);

   for i_c_comp=2:numColComp

     % FILTERING CHROMATIC COMPONENT rgbDecorr(:,:,2) and  rgbDecorr(:,:,2)
    [imfft,sz2filt,padSize]=FourierTransform2D(rgbDecorr(:,:,i_c_comp),chrLambda_max);

I don t understand in Matlab where is obtained the 3 components. I supposed where I commented HERE and I suppose but I m not sure that is created a 3dimensional array where in a dimension is located the 3 components. Am I right? How to do it and how to obtain this stuff? I don t understan where it obtain this 3 images of the image attached by the input image:

Howewer here the colorDecorrelation function MAtlab's code:

function Xdecorr=colorDecorrelation(X,numColComp){

 if numColComp>1  %color images                  
 mu = mean(X); %mean of each feature of the original data
 X = bsxfun(@minus, X, mu);
 A = X'*X; 
 [V,D,notused] = svd(A);

 Xdecorr=X*V;

 else % in case of a grayscale image
   Xdecorr = X;
   end

So In C++ what I did is:

//initial statements and Image control if empty or not

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

 // TO RETURN INITIAL VALUES BEACUSE I HAD TO CHANGE IT IN COLORDECORRELATION FUNCTION
 imgDecorr.convertTo(rgbDecorrImg,CV_8UC3); 

 //HERE ERROR FOR SURE
 rgbDecorrImg = rgbDecorrImg.reshape(numColComp,imgDecorr.rows);


...
...

 Mat colorDecorrelation(Mat img,int numColComp){

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

  if(numColComp>1){

    //I have to convert because of gemm function need a float
    img.convertTo(img_f,CV_32FC3);
    img_f=img_f.reshape(1,img.rows*img.cols); // 1 channel

     mu=mean(img_f); //media degli elementi della matrice
     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;
   }