我是MATLAB的新手,但我正在尝试为灰度图像做一些图像压缩代码.
问题
如何使用SVD修剪低值特征值来重建压缩图像?
到目前为止的工作/尝试
到目前为止我的代码是:
B=imread('images1.jpeg');
B=rgb2gray(B);
doubleB=double(B);
%read the image and store it as matrix B, convert the image to a grayscale
photo and convert the matrix to a class 'double' for values 0-255
[U,S,V]=svd(doubleB);
Run Code Online (Sandbox Code Playgroud)
这允许我用存储在变量S中的特征值成功地分解图像矩阵.
如何截断S(167x301,类double)?让我们说一下167个特征值我只想要前100个(或任何n个),我该怎么做并重建压缩图像?
更新了代码/想法
这不是在评论部分放置一堆代码,而是我现有的草案.我已经能够通过手动更改N来成功创建压缩图像,但我还想做两件事:
1-显示各种压缩图像的面板(i/e,运行N = 5,10,25等的循环)
2-以某种方式计算每个图像与原始图像之间的差异(误差)并绘制图形.
我理解循环和输出很糟糕,但这是我尝试过的:
B=imread('images1.jpeg');
B=rgb2gray(B);
doubleB=im2double(B);%
%read the image and store it as matrix B, convert the image to a grayscale
%photo and convert the image to a class 'double'
[U,S,V]=svd(doubleB);
C=S;
for N=[5,10,25,50,100]
C(N+1:end,:)=0;
C(:,N+1:end)=0;
D=U*C*V';
%Use …Run Code Online (Sandbox Code Playgroud)