![]() |
帮忙看看奇异值分解的图像压缩程序的问题
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 程序运行后输入压缩图片以及存储位置后 出现错误提示: [COLOR="Red"] ???error using==>mtimes inner matrix dimensions must agree.[/COLOR] |
回复: 帮忙看看奇异值分解的图像压缩程序的问题
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”,再次登陆时亦便于查看回答是否真的帮到你了。 个人观点 仅供参考 多多交流 相互学习 |
所有时间均为北京时间。现在的时间是 11:12。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.