| 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.  | 
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 		
			
			 | 
		#2 | 
| 
			
			 高级会员 
			
			
			
			注册日期: 2008-11-01 
				
				年龄: 39 
				
					帖子: 406
				 
				
				
				声望力: 27 ![]()  | 
	
	
	
		
		
			
			 
			
			lz 代码中矩阵乘法有误 具体位置在New=New+D(k,k)*(U(:,k)*V(:,k)); 
		
		
		
		
		
		
		
	(U(:,k)*V(:,k))中U的列数和V的行数不相等 是不能做乘法的 根据我对SVD分解和阅读lz的理解 U(:,k)改为U(:,k)' 但是没有在MatlAB中调试 lz调试看看 Thx for reading. PS:若还算满意,直接点击“Thanks”,再次登陆时亦便于查看回答是否真的帮到你了。 个人观点 仅供参考 多多交流 相互学习  | 
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 |