Decorrelation ask [closed]

asked 2013-11-20 12:10:58 -0500

residentelvio gravatar image

Hi what I have to do is todo a decorellation on RGC components of an image to obtain an efficient decodification of input datas with PCA analysis, adapted to local statistics of image (rbgDecorr in matlab code. I finally obtain 3 components. This is done with colorDecorolletion() You can see Matlab's code to understand better:

main (I put here my question):

 [r c compc] = size(image);

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

 rgbDecorr= reshape(Decorr, r, c, numColComp); //does it create a 3dimensional array?
 clear Decorr;

 % Color Decorrelation
 % Input Parameters:
 %  im           - image matrix
 %  numColComp   - number of image channels
 % Output value:
 %  Xdecorr  - decorrelated image, same dimensions as the original one

 function Xdecorr=colorDecorrelation(X,numColComp)

 if numColComp>1 
 mu = mean(X); 
 X = bsxfun(@minus, X, mu);
 A = X'*X; 
[V,D,notused] = svd(A);


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

My C++ code:

#include <stdio.h>
#include <cxcore.h>
#include <cv.h>
#include <highgui.h> 
#include <math.h>
#include <vector>

using namespace cv;
using namespace std;

#define PI 3.14159265

Mat colorDecorrelation(Mat img,int numColComp);

int main(){

  cout<<"The image is empty \n";
  return -1;

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

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

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

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

imgDecorr = colorDecorrelation(inCompImg,numColComp);

nChannels= imgDecorr.channels();

imgDecorr.convertTo(rgbDecorrImg,CV_8UC3); //to return to first type

rgbDecorrImg = rgbDecorrImg.reshape(numColComp,img.rows); //is it a 2D image? so maybe I have an error

namedWindow("Image Display", CV_WINDOW_AUTOSIZE);
imshow("Image Display", rgbDecorrImg);
destroyWindow("Image Display");
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-10-07 18:55:22.160393