在该图像上应用SVD之后如何检查该图像是否被压缩(关于磁盘上压缩图像的大小) [英] how to check whether the image is compressed or not after applying SVD on that image(regarding size of compressed image on disk)

查看:102
本文介绍了在该图像上应用SVD之后如何检查该图像是否被压缩(关于磁盘上压缩图像的大小)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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迭代后,磁盘上的映像大于原始映像.

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.

推荐答案

以下是一个示例:

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

这篇关于在该图像上应用SVD之后如何检查该图像是否被压缩(关于磁盘上压缩图像的大小)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆