OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Wed, 05 Feb 2014 10:52:17 -0600Image processing project with an error I can not solvehttp://answers.opencv.org/question/27555/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](/upfiles/13911971324088192.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;
}
Fri, 31 Jan 2014 14:13:07 -0600http://answers.opencv.org/question/27555/image-processing-project-with-an-error-i-can-not-solve/Comment by residentelvio for <p>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.</p>
<p>As in this picture : <a href="/upfiles/13911971324088192.png">C:\fakepath\imag.png</a></p>
<p>the initial target is :</p>
<p>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().</p>
<p>Matlab' s code :</p>
<pre><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);
</code></pre>
<p>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:</p>
<p>Howewer here the colorDecorrelation function MAtlab's code:</p>
<pre><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
</code></pre>
<p>So In C++ what I did is:</p>
<pre><code>//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;
}
</code></pre>
http://answers.opencv.org/question/27555/image-processing-project-with-an-error-i-can-not-solve/?comment=27618#post-id-27618Yes it s more or less what u said. the C is the operation of whitening. It s done in the function colorDecorrelation. The work done in Matlab works , so it can be just a translation from it to C++ as I done in code. I suppose it s right this part. It s the first & second part I didn t do. Thanks to help meMon, 03 Feb 2014 03:44:20 -0600http://answers.opencv.org/question/27555/image-processing-project-with-an-error-i-can-not-solve/?comment=27618#post-id-27618Comment by residentelvio for <p>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.</p>
<p>As in this picture : <a href="/upfiles/13911971324088192.png">C:\fakepath\imag.png</a></p>
<p>the initial target is :</p>
<p>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().</p>
<p>Matlab' s code :</p>
<pre><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);
</code></pre>
<p>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:</p>
<p>Howewer here the colorDecorrelation function MAtlab's code:</p>
<pre><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
</code></pre>
<p>So In C++ what I did is:</p>
<pre><code>//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;
}
</code></pre>
http://answers.opencv.org/question/27555/image-processing-project-with-an-error-i-can-not-solve/?comment=27580#post-id-27580Hello keghn. Thanks for reply. You are very close. A & B ok. The whitening procedure consisting in decorrelation and variance normalization is simply applied to the r, g, b components of the image. Being x1=r, x2=g and x3=b the RGB coordinates of any pixel in the image, they are involved in the transformation (x1,x2,x3)→(z1,z2,z3). Thereby I obtain z contain z1 to z3 components.Z is whitened with a new vector associated to each pixel.
If x is the representation of the image in the original space, y the representation in principal components, and z (z-scores) the corresponding representation in the whitened coordinates. That is, x = (xj) →y = (yj) →z = (zj) with j=1…M, where M is the number of components. Look the picture I attached to understand better
Sat, 01 Feb 2014 09:00:09 -0600http://answers.opencv.org/question/27555/image-processing-project-with-an-error-i-can-not-solve/?comment=27580#post-id-27580Comment by keghn for <p>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.</p>
<p>As in this picture : <a href="/upfiles/13911971324088192.png">C:\fakepath\imag.png</a></p>
<p>the initial target is :</p>
<p>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().</p>
<p>Matlab' s code :</p>
<pre><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);
</code></pre>
<p>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:</p>
<p>Howewer here the colorDecorrelation function MAtlab's code:</p>
<pre><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
</code></pre>
<p>So In C++ what I did is:</p>
<pre><code>//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;
}
</code></pre>
http://answers.opencv.org/question/27555/image-processing-project-with-an-error-i-can-not-solve/?comment=27588#post-id-27588Maybe part c) would be more like take one of the mono colored images say the
green mat, and then for each green pixel change it over
to grey scale pixel. Then move it on to a new image at the same, intensity, and location.
Then hit that gray pixel with an optional constant. Then do the same for blue and red
mono colored images?Sat, 01 Feb 2014 14:34:28 -0600http://answers.opencv.org/question/27555/image-processing-project-with-an-error-i-can-not-solve/?comment=27588#post-id-27588Comment by keghn for <p>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.</p>
<p>As in this picture : <a href="/upfiles/13911971324088192.png">C:\fakepath\imag.png</a></p>
<p>the initial target is :</p>
<p>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().</p>
<p>Matlab' s code :</p>
<pre><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);
</code></pre>
<p>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:</p>
<p>Howewer here the colorDecorrelation function MAtlab's code:</p>
<pre><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
</code></pre>
<p>So In C++ what I did is:</p>
<pre><code>//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;
}
</code></pre>
http://answers.opencv.org/question/27555/image-processing-project-with-an-error-i-can-not-solve/?comment=27684#post-id-27684Yes. But sense I am new to OpenCV I am stopping and dwelling on all of interesting little detail
I come across.
Am is seeing three gray scale for each mono colored image? Or one gray scale image for each
mono colored picture?
Tue, 04 Feb 2014 15:18:06 -0600http://answers.opencv.org/question/27555/image-processing-project-with-an-error-i-can-not-solve/?comment=27684#post-id-27684Comment by residentelvio for <p>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.</p>
<p>As in this picture : <a href="/upfiles/13911971324088192.png">C:\fakepath\imag.png</a></p>
<p>the initial target is :</p>
<p>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().</p>
<p>Matlab' s code :</p>
<pre><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);
</code></pre>
<p>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:</p>
<p>Howewer here the colorDecorrelation function MAtlab's code:</p>
<pre><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
</code></pre>
<p>So In C++ what I did is:</p>
<pre><code>//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;
}
</code></pre>
http://answers.opencv.org/question/27555/image-processing-project-with-an-error-i-can-not-solve/?comment=27673#post-id-27673do you know how can I solve this part?Tue, 04 Feb 2014 06:24:00 -0600http://answers.opencv.org/question/27555/image-processing-project-with-an-error-i-can-not-solve/?comment=27673#post-id-27673Comment by residentelvio for <p>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.</p>
<p>As in this picture : <a href="/upfiles/13911971324088192.png">C:\fakepath\imag.png</a></p>
<p>the initial target is :</p>
<p>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().</p>
<p>Matlab' s code :</p>
<pre><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);
</code></pre>
<p>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:</p>
<p>Howewer here the colorDecorrelation function MAtlab's code:</p>
<pre><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
</code></pre>
<p>So In C++ what I did is:</p>
<pre><code>//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;
}
</code></pre>
http://answers.opencv.org/question/27555/image-processing-project-with-an-error-i-can-not-solve/?comment=27725#post-id-27725I did not understand your answer. Howewer we have an image.from this we obtain Rgb images inthe same array 3dimensional. In 3rd dimension you have the 3 images. After the matrix is whitened for every pixel. Wed, 05 Feb 2014 04:20:36 -0600http://answers.opencv.org/question/27555/image-processing-project-with-an-error-i-can-not-solve/?comment=27725#post-id-27725Comment by keghn for <p>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.</p>
<p>As in this picture : <a href="/upfiles/13911971324088192.png">C:\fakepath\imag.png</a></p>
<p>the initial target is :</p>
<p>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().</p>
<p>Matlab' s code :</p>
<pre><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);
</code></pre>
<p>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:</p>
<p>Howewer here the colorDecorrelation function MAtlab's code:</p>
<pre><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
</code></pre>
<p>So In C++ what I did is:</p>
<pre><code>//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;
}
</code></pre>
http://answers.opencv.org/question/27555/image-processing-project-with-an-error-i-can-not-solve/?comment=27560#post-id-27560Hello residentelvio
So you are taking an image:
a) make a copy of, blue, copy green, and red, from the original image.
b) turn all the single color images to a gray scale.
c) get and average gray scale for all gray scale images.
Am i close?
Fri, 31 Jan 2014 17:58:11 -0600http://answers.opencv.org/question/27555/image-processing-project-with-an-error-i-can-not-solve/?comment=27560#post-id-27560Comment by residentelvio for <p>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.</p>
<p>As in this picture : <a href="/upfiles/13911971324088192.png">C:\fakepath\imag.png</a></p>
<p>the initial target is :</p>
<p>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().</p>
<p>Matlab' s code :</p>
<pre><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);
</code></pre>
<p>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:</p>
<p>Howewer here the colorDecorrelation function MAtlab's code:</p>
<pre><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
</code></pre>
<p>So In C++ what I did is:</p>
<pre><code>//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;
}
</code></pre>
http://answers.opencv.org/question/27555/image-processing-project-with-an-error-i-can-not-solve/?comment=27785#post-id-27785Oh, maybe I understand reading better. 1 grayscale image for each mono colored picture, as in the picture attached.if you open it, you ll understan easily. Thanks Wed, 05 Feb 2014 10:52:17 -0600http://answers.opencv.org/question/27555/image-processing-project-with-an-error-i-can-not-solve/?comment=27785#post-id-27785