wangsf5200
2009-04-15, 16:22
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.
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.