% % % for the illustration of SVD over 2D image for the course of "Multimedia % Analysis and Indexing" % % Winston Hsu % -- last update, 04/03/2007 % % demo. % test if vectors in U, V are orthogonal % the engery of those sigma (or singular values) % IMG_SRC = 'nj_gray'; egNs = [1, 5, 10, 50, 200]; gim = imread([IMG_SRC, '.jpg']); figure; imagesc(gim); colormap(gray); title('original image'); [U,S,V] = svd(double(gim)); % X = U*S*V'; Sd = diag(S); %the for n=egNs if n > min(size(S)), continue; end; St = zeros(size(S)); for i=1:n, St(i, i) = Sd(i); end; imgT = U*St*V'; msg = sprintf('%d dim.', n); figure; imagesc(imgT); colormap(gray); title(msg); axis off; end;