Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
748 views
in Technique[技术] by (71.8m points)

matlab - how to check whether the image is compressed or not after applying SVD on that image(regarding size of compressed image on disk)

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)

this is the code i have written for SVD decomposition ,i got correct output.But the size of compressed image is greater than original image,so how to calculate whether after svd image is compressed or not,that means i got size of the image on disk after applying svd iterations is greater than the original image.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here is an illustrative example:

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

var svd_approx


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...