Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#1 |
初级会员
注册日期: 2009-04-15
帖子: 2
声望力: 0 ![]() |
![]()
clear;
stop=0; while stop<1 InputName=input('\ninput the name of your image to be compressed! (with extension)\n\nfor example,flower.jpg\n\n','s'); ImageExt='jpg'; A=imread(InputName,ImageExt); A=im2double(A); [m,n,k]=size(A); Dimensions_of_the_picture_matrix=[m,n]; Rank=input('\nInput rank you want to use!\n\nRank here must be an interger!\n\nand its value is between 1 and the minimun of the above dimensions\n\n'); OutputName=input('\nInput the name of the output file used to store image compressed !(with extension)\n\n','s'); OutputExt='jpg'; NewArray=im2uint8(zeros(m,n,k)); for i=1:1:3 AA=A(:,:,i); [U,D,V]=svd(AA); [m n]=size(D); New=zeros(m,n); for k=1:Rank New=New+D(k,k)*(U(:,k)*V(:,k)); end NewArray(:,:,i)=im2uint8(New); clear New; end OutputExt='ipg'; imwrite(NewArray,OutputName,OutputExt); clear NewArray; clear A; clear InputName; clear OutputName; YN=input('\nDo your another image needs to be compressed?\n\n answer 1 or 0:\n'); if YN==0; stop=1; end end 程序运行后输入压缩图片以及存储位置后 出现错误提示: ???error using==>mtimes inner matrix dimensions must agree. |
![]() |
![]() |