I=imread('cameraman.tif');
figure(1),imshow(I)
I1=im2double(I);
[U,S,V]=svd(I1);
figure(2),imshow(I1)
for j=1:90
I2=U(:,1:j)*S(1:j,1:j)*V(:,1:j)';
end
figure(3),imshow(I2)
I3=U*S*V';
figure(4),imshow(I3)
这是我为SVD分解编写的代码,我得到了正确的输出。但是压缩图像的大小比原始图像大,所以如何计算在svd图像被压缩之后,这意味着我得到的大小应用svd迭代后磁盘上的图像大于原始图像。
答案 0 :(得分:4)
以下是一个说明性示例:
I = imread('cameraman.tif');
X = im2double(I);
%# SVD
[U S V] = svd(X);
%# variance explained by each eigenvector
variances = abs(diag(S).^2);
plot(cumsum(variances)./sum(variances), 'b.-'), ylim([0 1])
title('SVD'), xlabel('i^{th} Component'), ylabel('Variance explained')
%# iterate over number of components to keep
figure
subplot(121), imshow(X), title( sprintf('size=%d',numel(X)) )
subplot(122)
for p = 1:(size(U,2)/2-1)
%# truncated SVD
Up = U(:,1:p);
Vp = V(:,1:p);
Sp = diag(S(1:p,1:p));
%# reconstruct/compress
XHat = Up * diag(Sp) * Vp'; %'# approximation
err = mean( abs(X(:)-XHat(:)) ); %# mean absolute error
sz = (numel(Up) + numel(Vp) + numel(Sp)); %# new size
%# show
imshow(XHat)
title( sprintf('p=%d, size=%d, err=%g', p, sz, err) )
%# flush output
drawnow
end
答案 1 :(得分:1)
我认为你错过了SVD分解的重点。重建图像的大小将保持与像素数相同。 SVD的作用是允许您存储/传输较少的信息......换句话说,在您的情况下,您可以传输256 ^ 2双打或(256 * j)+ j +(256 * j)。对于90的j,它是46170(vs 65536)