- Load the image called mandrill.mat, via:
>> load
mandrill;
This loads a matrix X containing a face of mandrill, and a map containing
the colormap of the image. If you cannot load this data in your MATLAB, then
download this data from this
link. Then, do the load
command
again. Display this matrix on your screen by:
>>
image(X); colormap(map)
-
Compute the SVD of this mandrill image and plot the distribution
of its singular values on your screen (Note that the MATLAB
svd function returns three matrices U, S, V for a given input matrix. So, the singular values are plotted by:
>>
plot(diag(S));
Then print this figure.
- Let σj, uj, vj be a singular value, the left and
right singular vectors of the mandrill image, respectively.
In other words, they are S(j,j), U(:,j), V(:,j) of the SVD of X
in MATLAB. Let us
define the rank k
approximation
of the image x as
xk
:= σ1
u1 v'1
+ ... + σk uk v'k, where
v'j is
a transpose of vj.
Then, for k=1,6,11,31, compute xk of
the mandrill, and display the results. Fit these four images in one
page by using
subplot function in MATLAB (i.e., use
subplot(2,2,1) to display the first image,
subplot(2,2,2) to display the second image, etc.)
- For k=1,6,11,31, display the residuals, i.e., x-xk,
fit them in one page, and print them.
matlab commands
load mandrill;
who;
image(X);
colormap(map);
size(X)
[U,S,V]=svd(X);
figure(2)
plot(diag(S));
semilogy(diag(S));
grid
figure(3)
image(S(1,1)*U(:,1)*V(:,1)');
image(X);
figure(3);image(S(1,1)*U(:,1)*V(:,1)');
colormap(map)
app=S(1,1)*U(:,1)*V(:,1)';
image(app);
app=app+S(2,2)*U(:,2)*V(:,2)';
image(app);
app=app+S(3,3)*U(:,3)*V(:,3)';
image(app)
for k=4:31
app=app+S(k,k)*U(:,k)*V(:,k)';
end
image(app)
colormap(map)
- Finally, submit those three printouts as HW.