SVD图片有损压缩测试
注意文件名别保持成svd.m,这样与系统的默认svd程序冲突
图片处理函数生成的三组二维数组对应RGB,处理时保留一组
clear all; close all; clc; a1=imread('C:\1.jpg'); [m n]=size(a1); a1=double(a1); a=a1(:,:,3); %图片有三个通道 imshow(mat2gray(a)) r=rank(a); [U S V]=svd(a); %re=s*v*d'; re=U(:,:)*S(:,1:1)*V(:,1:1)'; figure; imshow(mat2gray(re)); imwrite(mat2gray(re),'a.jpg') %实际保存是S可以只保存20个字节,U,V按二维数组保存 re=U(:,1:20)*S(1:20,1:20)*V(:,1:20)'; figure; imshow(mat2gray(re)); imwrite(mat2gray(re),'b.jpg') re=U(:,1:80)*S(1:80,1:80)*V(:,1:80)'; figure; imshow(mat2gray(re)); imwrite(mat2gray(re),'c.jpg') re=U(:,1:150)*S(1:150,1:150)*V(:,1:150)'; figure; imshow(mat2gray(re)); imwrite(mat2gray(re),'d.jpg') re=U(:,1:250)*S(1:250,1:250)*V(:,1:250)'; figure; imshow(mat2gray(re)); imwrite(mat2gray(re),'e.jpg')