如何计算截断和近似值?

时间:2016-04-25 00:33:54

标签: matlab matrix octave

Screenshot of the reading

我要拍摄一张图片,使用imread()将其转换为一组3个矩阵,然后使用N=1,2,3,4,8,16,32,64,128项计算每个矩阵的截断和近似值。< / em>我有矩阵,但我对最后一部分并不十分确定,阅读有点模糊。截断和近似是什么意思?

根据给定答案进行更新:

我尝试了以下内容:

A = double(imread("image.jpg"))/255;

  [U1, S1, V1] = svd(A(:,:,1));
  [U2, S2, V2] = svd(A(:,:,2));
  [U3, S3, V3] = svd(A(:,:,3));

N = 128;    
trunc_image = (U1(1:763,1:N)*S1(1:N,1:N)*V1(1:N,1:691))*255;

imwrite(trunc_image, "truncimg.jpg", "jpg");

...但是生成的图像如下所示:

screenshot of resulting image

1 个答案:

答案 0 :(得分:2)

When you perform svd on an image I:

[U,S,V] = svd(I,'econ'); %//you get matrices U, S, V

S will be a diagonal matrix, with decreasing singular values along the diagonals.

Approximation by truncating... means that I can reconstruct I' by zeroing out singular values in S:

I_recon = U(1:256,1:N)*S(1:N,1:N)*V(1:256,1:N).'; %//Reconstruct by keeping the first N singular values in S.

What happens here is that I_recon is an image reconstructed from the N most significant singular values. The purpose of doing this is so that we can remove less significant contributions to the image I, and represent I with less data.

This is an example of reconstructed images with varying N:

SVD reconstruction of I