# Revision history [back]

ahh, remember the strange find, that the matlab code was making a 3 row, 1 channel img of it ? seems, you got to do the same here.

below code compiles and runs, but no idea, if the outcome is the right thing

Mat colorDecorrelation(Mat img,int numColComp)
{
Mat imgf;
Mat V,D,A,Xdecorr,img_tr;
SVD svd;
Scalar mu;
if(numColComp>1){
img.convertTo(imgf,CV_32FC3);
imgf = imgf.reshape(1,img.rows*img.cols); // r=3,c=314928,chan=1

mu=mean(imgf);
subtract(imgf,mu,imgf);
transpose(imgf,img_tr);
A = img_tr*imgf;
V = svd(A).u;
Xdecorr = imgf*V;
}
else
Xdecorr = img;

return Xdecorr;
}


ahh, remember the strange find, that the matlab code was making a 3 row, 1 channel img of it ? seems, you got to do the same here.

below code compiles and runs, but no idea, if the outcome is the right thing

Mat colorDecorrelation(Mat img,int numColComp)
{
Mat imgf;
Mat V,D,A,Xdecorr,img_tr;
SVD svd;
Scalar mu;
if(numColComp>1){
img.convertTo(imgf,CV_32FC3);
imgf = imgf.reshape(1,img.rows*img.cols); // r=3,c=314928,chan=1

mu=mean(imgf);
subtract(imgf,mu,imgf);
transpose(imgf,img_tr);
A = img_tr*imgf;
V = svd(A).u;
Xdecorr = imgf*V;
Xdecorr = Xdecorr.reshape(3,img.rows); // back to original shape
// do we need to convert back to CV_8UC3 ?
}
else
Xdecorr = img;

return Xdecorr;
}


ahh, remember the strange find, that the matlab code was making a 3 row, 1 channel img of it ? seems, you got to do the same here.

below code compiles and runs, but no idea, if the outcome is the right thing

Mat colorDecorrelation(Mat img,int numColComp)
{
Mat imgf;
Mat V,D,A,Xdecorr,img_tr;
SVD svd;
Scalar mu;
if(numColComp>1){
img.convertTo(imgf,CV_32FC3);
imgf = imgf.reshape(1,img.rows*img.cols); // r=3,c=314928,chan=1

mu=mean(imgf);
subtract(imgf,mu,imgf);
transpose(imgf,img_tr);
A = img_tr*imgf;
V = svd(A).u;
Xdecorr = imgf*V;
Xdecorr = Xdecorr.reshape(3,img.rows); // back to original shape
// do we need to convert back to CV_8UC3 ?
}
else
Xdecorr = img;

return Xdecorr;
}


ahh, remember the strange find, that the matlab code was making a 3 row, 1 channel img of it ? seems, you got to do the same here.

below code compiles and runs, but no idea, if the outcome is the right thing

Mat colorDecorrelation(Mat img,int numColComp)
{
Mat imgf;
Mat V,D,A,Xdecorr,img_tr;
SVD svd;
Scalar mu;
if(numColComp>1){
img.convertTo(imgf,CV_32FC3);
imgf = imgf.reshape(1,img.rows*img.cols); // r=3,c=314928,chan=1

mu=mean(imgf);
subtract(imgf,mu,imgf);
transpose(imgf,img_tr);
A = img_tr*imgf;
V = svd(A).u;
Xdecorr = imgf*V;
Xdecorr = Xdecorr.reshape(3,img.rows); // back to original shape
// do we need to convert back to CV_8UC3 ?
}
else
Xdecorr = img;

return Xdecorr;
}

int main(int argc, char **argv)
{

Mat img = imread("herring.jpeg");
Mat r = colorDecorrelation(img,3);
imshow("i",r);
imwrite("herrin_decorr.jpeg",r);
waitKey(0);
return 0;
}