0

My question is pretty simple but I am new to SVD analysis. My final goal will be to implement denoise an Image using SVD but at the moment of time I am trying to comprehend the concept of Singular value decomposition.

As the title suggest , I want to decompose the image into its component matrices but I want to avoid using SVD command so I can get the concept of what is actually going on in the process.

The code :

a = double(rgb2gray(imread('Lenna.png')));
a_tp = a';

Z2 = a*a_tp;
Z1 = a_tp*a;

[U,U_val] = eig(Z1);

[V,V_val] = eig(Z2);

Sig = sqrt(U_val+V_val);

figure(1)
Img_new = imshow(((U*Sig*V')));

I thought U, V and Sigma are my components as U is the eigen vectors for a'*a and V are the eigen vectors for a*a' and Sigma are the corresponding eigen values but this ain't right ... There is some conceptual mistake , Help me please

PS >> This was the reference tutorial > http://www.youtube.com/watch?v=BmuRJ5J-cwE

Dang Khoa
  • 5,693
  • 8
  • 51
  • 80
MariaS
  • 1
  • 3
  • I'm pretty sure you don't need to do Z2 and Z1 step. If you want to do an image reconstruction, you can just use the image itself without doing any modifications. If you want to denoise an image, you simply need to modify the singular values themselves. Check this link out: http://math.gmu.edu/~sap/U09/m203/SVD/svd.html – rayryeng May 01 '14 at 14:09
  • Thanks for the response. For now my aim is just to decompose the image into U S and V matrices of SVD without using SVD in matlab ... tell me how am I doing it wrong . – MariaS May 01 '14 at 15:57
  • You're apparently trying to implement an SVD using eigendecomposition. That's clearly possible, but it is a rather strange approach numerically, since usually SVD is considered to be the simpler and more general operation. With regard to the Matlab functions, `svd` is implemented using QR decomposition. For more information, see https://en.wikipedia.org/wiki/Singular_value_decomposition#Calculating_the_SVD – A. Donda May 01 '14 at 17:38
  • How is it possible using eigen decomposition .. please help me with that – MariaS May 01 '14 at 19:03

1 Answers1

0

I figured it out. Posting the code for future reference and to help others.

clear all; clc;

a = double(rgb2gray(imread('Lenna.png')));
%a = [1 1 -1;0 1 1;-1 1 1];
[q d r] = svd(a);

a_tp = a';
Z1 = a_tp*a;

[Z1_vec,Z1_val] = eig(Z1);

[k p] = size(a);
[m n] = size(Z1_vec);
[o p] = size(Z1_val);


U = zeros(p,m);    % Size of U 
for i = 1:1:m

        U(:,i) = (a*Z1_vec(:,n))/sqrt(Z1_val(o,p)); % U in SVD

        o = o-1; p = p-1;
        n = n-1;

end

[o p] = size(Z1_val);
Sigma = sqrt(Z1_val);
Sig= zeros(o,p);

for i=1:1:p
    Sig(i,i) = Sigma(o-i+1,p-i+1);  % Diagnol matix
end


V = fliplr(Z1_vec);   % r in SVD 


figure(1)
Img_new = imshow((mat2gray(U*Sig*V')));

figure(2)
Img_svd = imshow((mat2gray(q*d*r')));
Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
MariaS
  • 1
  • 3