Gointerface接口声明实现及作用详解
411
2022-09-03
【图像压缩】基于奇异值分解svd进行图像压缩matlab代码(基于奇异值分解的图像压缩)
1 简介
根据奇异值分解的基本原理及其特点,给出了运用奇异值分解进行图像压缩的方法.通过简单的例子说明了该方法进行图像压缩的基本过程,给出了压缩流程.并通过MAT-LAB编程对实际图像进行处理,表明了该方法的有效性.
2 完整代码
% Read the image into A as a matrix of uint8clcclear allclose all[X,map] = imread('witchhead.jpg');Im = X;% Convert image from uint8 to doubles for svdX = im2double(X);% Seperate [U_r,S_r,V_r] = svd(X(:,:,1));[U_g,S_g,V_g] = svd(X(:,:,2));[U_b,S_b,V_b] = svd(X(:,:,3));%=============================% Test Scripts%=============================%confirmation checking for redout_red = U_r*S_r*V_r';red = X(:,:,1);%-----------------------------% S_r has size 640x1138, thus 640 diagonal valuessize(S_r)% Find the largest k singular valuesk = 30;redk = zeros(k,1);greenk = zeros(k,1);bluek = zeros(k,1);% Discovered that the diagonal of the sum matrix is in orderfor i = 1:k redk(i) = S_r(i,i); greenk(i) = S_g(i,i); bluek(i) = S_b(i,i);end%-----------------------------% Storage AnalysisinitialStorage = 640*1138;currentStorage = (640+1138)*k+k;%-----------------------------% Error Analysissume = 0;for i = 1:640 sume = sume + S_r(i,i) + S_g(i,i) + S_b(i,i);enderror = sum(redk+greenk+bluek) / sume;%-----------------------------NewImage_r = zeros(640,1138);NewImage_g = zeros(640,1138);NewImage_b = zeros(640,1138);for i = 1:k NewImage_r = NewImage_r + redk(i)* U_r(:,i)*V_r(:,i)'; NewImage_g = NewImage_g + greenk(i) * U_g(:,i)*V_g(:,i)'; NewImage_b = NewImage_b + bluek(i) * U_b(:,i)*V_b(:,i)';end%-----------------------------% Normalize the matrices to fit the rgb formatfor i = 1:640 for j = 1:1138 if(NewImage_r(i,j) < 0) NewImage_r(i,j) = 0; end if(NewImage_g(i,j) < 0) NewImage_g(i,j) = 0; end if(NewImage_b(i,j) < 0) NewImage_b(i,j) = 0; end endend%-----------------------------rgbImage = cat(3, NewImage_r, NewImage_g, NewImage_b);% image(rgbImage);% image(X);difference = rgbImasge-Xfiguresubplot(121)imshow(X,[]);title('原图')subplot(122)imshow(NewImage_b,[]);title('压缩后的图')%-----------------------------
3 仿真结果
4 参考文献
[1]胡乡峰, 卫金茂. 基于奇异值分解(SVD)的图像压缩[J]. 东北师大学报:自然科学版, 2006, 38(3):4.
博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。
部分理论引用网络文献,若有侵权联系博主删除。
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~