飞道的博客

用SVD压缩彩色图片(MATLAB代码)

342人阅读  评论(0)

Write a MATLAB program to perform color image compression using singular value decomposition (SVD).
使用MATLAB,用奇异值分解(SVD)的方法压缩彩色图片
没找到matlab代码块,就用python代替了吧

src=imread('yasuo.jpg')
rank_list=[1,10,20,50,100,300,600];%set different ranks
figure(1);
subplot(ceil((length(rank_list)+1)/2),2,1)
%subplot(4,2,1:2)
imshow(mat2gray(src));
title('Original Image')
src=double(src);
%split into three channels
rr=rank(src(:,:,1));%source_red
rg=rank(src(:,:,2));%source_blue
rb=rank(src(:,:,3));%source_green
[sr vr dr]=svd(src(:,:,1));
[sg vg dg]=svd(src(:,:,2));
[sb vb db]=svd(src(:,:,3));

for i=1:length(rank_list)
%re=s*v*d'; Reconstruction
rer=sr(:,:)*vr(:,1:rank_list(i))*dr(:,1:rank_list(i))';
reg=sg(:,:)*vg(:,1:rank_list(i))*dg(:,1:rank_list(i))';
reb=sb(:,:)*vb(:,1:rank_list(i))*db(:,1:rank_list(i))';
re(:,:,1)=rer;
re(:,:,2)=reg;
re(:,:,3)=reb;
figure(1);
subplot(ceil((length(rank_list)+1)/2),2,i+1)
%subplot(4,2,i+2)
imshow(mat2gray(re));
%title('rank=rank_list(%d)',rank_list(i))
title(['Image for Rank=' num2str(rank_list(i))]) 
end

结果如下


转载:https://blog.csdn.net/kshz2135915/article/details/104578015
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场