Question: I was given this code function svd-figure(filename) % % svd-figure(filename) % % read in an image and spit out svd approximations more off; A =
I was given this code
function svd-figure(filename)
%
% svd-figure(filename)
%
% read in an image and spit out svd approximations
more off;
A = imread(filename);
A = double(A);
m = size(A,1);
n = size(A,2);
h = size(A,3);
for i=1:h
ranks(i) = rank(A(:,:,i));
end
rmax=min(ranks);
for i=1:h
[U(i).data,S(i).data,V(i).data] = svd(A(:,:,i));
end
indices = [1:5];
%indices = [1:10, 20:10:rmax];
for r=indices
fprintf(1,'r = %d ',r);
for i=1:h
Amod(:,:,i)=U(i).data(:,1:r)*S(i).data(1:r,1:r)*V(i).data(:,1:r)';
Adiff(:,:,i) = U(i).data(:,r)*S(i).data(r,r)*V(i).data(:,r)';
end
Amod = uint8(Amod);
Adiff = uint8(Adiff);
rstring = sprintf('%d.jpg',r);
imwrite(Amod, rstring,'jpg');
end
more on;
and use it to import a photo, with Matlabs imread command. Use the SVD to create 8:1, 4:1, and 2:1 compressed versions of the photo. Note that this compression refers to the total memory required to store the approximation. Please report how many singular values were required for each of the compression ratios.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
