Hi everyone. I am new user to matlab. I found this code from internet, but i cant run the code due some error. The first error encountered was;
Error in SVD_C (line 8) %ERROR [Uh,Sh,Vh]= svd(double(hostimage)); %ERROR
can anyone please debug this code? Thank you
________________________________________________________________
function []= SVD_C() hostimage= imread('lena.bmp'); k=10; % determine size of host image Mc=size(hostimage,1); %Height Nc=size(hostimage,2); %Width
[Uh,Sh,Vh]= svd(double(hostimage));
VhT=transpose(Vh(1:Nc,1:k)); compressed_image= Uh(1:Mc,1:k)*Sh(1:k,1:k)*VhT;
%PSNR
[PSNR_SVD,MSE_SVD]= psnr(hostimage,compressed_image)
imwrite(compressed_image,'lena_svd.jpg','jpg');
figure(1) imshow(hostimage,[]); title('Host Image'); figure(2) imshow(compressed_image,[]) title('Compressed Image');
end
% Function to calculate psnr used above function [p mse]= psnr(original,reconstructed)
Mc= size(original,1); Nc= size(original,2); a1= original(1:Mc,1:Nc); a2= reconstructed(1:Mc,1:Nc);
error=double(a1)-double(a2);
sum=0; for (i=1:Mc) for(j=1:Nc) sum = sum + ((error(i,j))^2); end end
mse = sum/(Mc*Nc); p = 10*log(double((255*255)/mse));
end
Best Answer