% test SVD on real image clear clc I = imread('baboon.bmp'); % I = 128 * ones(256); I = double(I); [U, S, V] = svd(I); % Irec = U * S * V'; Vtranspose = V'; Irec = zeros(256); myPSNR = []; mySSIM = []; for i = 1 : 255 tempIter = S(i,i) * U(:,i) * Vtranspose(i,:); Irec = Irec + tempIter; myPSNR(end+1) = psnr(I,Irec,255); mySSIM(end+1) = ssim(I,Irec); imshow(Irec,[0 255]), xlabel(i) if rem(i,5)==0 drawnow end end figure, subplot(1,2,1), imshow(I,[0 255]) subplot(1,2,2), imshow(Irec,[0 255]) figure, subplot(1,2,1), plot(myPSNR), title('PSNR vs. Iteration'), xlabel('Iteration'), ylabel('PSNR'), grid on subplot(1,2,2), plot(mySSIM), title('SSIM vs. Iteration'), xlabel('Iteration'), ylabel('SSIM'), grid on q = inf;