MariaS
MariaS

Reputation: 1

Find Image SVD without using SVD command

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

Upvotes: 0

Views: 1418

Answers (1)

MariaS
MariaS

Reputation: 1

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')));

Upvotes: 0

Related Questions