0% found this document useful (0 votes)
30 views3 pages

All All: % Enter The Image

This document performs singular value decomposition (SVD) on an 8x8 test image to extract eigenimages and reconstruct the original image using varying numbers of eigenimages. It displays the original and eigenimages, reconstructed images from 1 to 8 eigenimages, and calculates the reconstruction error for each case. The errors decrease from 334.0981 to 0 as more eigenimages are used, with the original image perfectly reconstructed using all 8 eigenimages.

Uploaded by

VishnuVardhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views3 pages

All All: % Enter The Image

This document performs singular value decomposition (SVD) on an 8x8 test image to extract eigenimages and reconstruct the original image using varying numbers of eigenimages. It displays the original and eigenimages, reconstructed images from 1 to 8 eigenimages, and calculates the reconstruction error for each case. The errors decrease from 334.0981 to 0 as more eigenimages are used, with the original image perfectly reconstructed using all 8 eigenimages.

Uploaded by

VishnuVardhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

clc

clearall
closeall
%entertheimage
g=255*ones(8,8);
g(2,4:6)=100;g(3,3:7)=100;g(3,4:6)=150;
g(4,:)=g(3,:);g(4,5)=200;g(5,:)=g(4,:);
g(5,5)=150;g(6,:)=g(2,:);g(7,5)=50;g(8,1:4)=50;
%performSVDdecompositionoftheimage
[U,S,V]=svd(g);
%computeeigenimages
eig_images=zeros(8,8,8);
fori=1:8
eig_images(:,:,i)=U(:,i)*V(:,i)';
end
%originalimage
figure(1)
image(g)
title('OriginalImage')
%eigenimages
figure(2)
str='Eigenimage%d';
fori=1:8
subplot(2,4,i);image(abs(eig_images(:,:,i)));
title(sprintf(str,i))
end
%reconstructedimagesusingk=1to8significanteigenimages
figure(3)
rimage=zeros(8,8,8);
str='Reconstrdwithk=%d';
fork=1:8
fori=1:k
rimage(:,:,k)=rimage(:,:,k)+S(i,i)*eig_images(:,:,i);
end
subplot(2,4,k);image(rimage(:,:,k));
title(sprintf(str,k));
end
%errorsofrecon.imagesusingk=1to8significanteigenimages
errors=zeros(8,1);
fork=1:8
errors(k,1)=norm(grimage(:,:,k));
end
disp('SumofsquareerrorsforeachreconstructedimageforK=1to8')
errors

SumofsquareerrorsforeachreconstructedimageforK=1to8
errors=
334.0981
267.8401
186.5231

109.0080
0.0000
0.0000
0.0000
0.0000

PublishedwithMATLAB7.12

You might also like