Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 工程数学软件 > MATLAB论坛
MATLAB论坛 一切MATLAB相关问题在此讨论。
回复
 
主题工具 显示模式
旧 2009-04-15, 16:22   #1
wangsf5200
初级会员
 
注册日期: 2009-04-15
帖子: 2
声望力: 0
wangsf5200 正向着好的方向发展
默认 帮忙看看奇异值分解的图像压缩程序的问题

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.
wangsf5200 当前离线   回复时引用此帖
旧 2009-04-16, 05:19   #2
silas_xue
高级会员
 
注册日期: 2008-11-01
年龄: 39
帖子: 406
声望力: 26
silas_xue 是一个将要出名的人
默认 回复: 帮忙看看奇异值分解的图像压缩程序的问题

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”,再次登陆时亦便于查看回答是否真的帮到你了。
个人观点 仅供参考 多多交流 相互学习
silas_xue 当前离线   回复时引用此帖
回复


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛禁用 HTML 代码



所有时间均为北京时间。现在的时间是 11:37


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.