对图像应用 SVD 后如何检查图像是否被压缩(关于磁盘上压缩图像的大小)

发布于 2024-11-23 21:47:09 字数 336 浏览 2 评论 0原文

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 迭代后的磁盘大于原始图像。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不再让梦枯萎 2024-11-30 21:47:09

这是一个说明性示例:

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

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

忆伤 2024-11-30 21:47:09

我认为你忽略了 SVD 分解的要点。重建图像的大小将与像素数保持相同。 SVD 的作用是允许您存储/传输更少的信息...换句话说,在您的情况下,您可以传输 256^2 双精度数或 (256*j)+j+(256*j)。对于 90 的 j 来说,它是 46170(对比 65536)

I think you're missing the point of SVD decomposition. the size of the reconstructed image will remain the same re the number of pixels. what SVD does is allow you to store/transmit less information... in other words, in your case, you can transmit 256^2 doubles or (256*j)+j+(256*j). for j of 90 it's 46170 (vs 65536)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文