尽管这个问题很旧,但它对我理解SVD有所帮助。我已经修改了您在问题中编写的代码,以使其正常工作。
我相信您可能已经解决了该问题,但是,仅供以后访问此页面的任何人参考,我将在此处包括完整的代码以及输出图像和图形。
下面是代码:
close all
clear all
clc
%reading and converting the image
inImage=imread('fruits.jpg');
inImage=rgb2gray(inImage);
inImageD=double(inImage);
% decomposing the image using singular value decomposition
[U,S,V]=svd(inImageD);
% Using different number of singular values (diagonal of S) to compress and
% reconstruct the image
dispEr = [];
numSVals = [];
for N=5:25:300
% store the singular values in a temporary var
C = S;
% discard the diagonal values not required for compression
C(N+1:end,:)=0;
C(:,N+1:end)=0;
% Construct an Image using the selected singu