Advertisement
KDOXG

compc_cpc

Dec 7th, 2020 (edited)
3,333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Octave 0.60 KB | None | 0 0
  1. function PSNR = compc_cpc(imagem, tx)
  2.   Im = imread(imagem);
  3.  
  4.   #imwrite(Im,"img.jp2","CompressionRatio",tx);
  5.   imwrite(Im,"img.jp2");
  6.  
  7.   Im_c = imread("img.jp2");
  8.   imshow(Im_c);
  9.  
  10.   memsize = numel(Im);
  11.   disk_size = imfinfo("img.jp2").FileSize;
  12.   taxa_comp = memsize / disk_size;
  13.  
  14.   if length(size(Im)) == 3
  15.     Im = rgb2ycbcr(Im);
  16.     Im_c = rgb2ycbcr(Im_c);
  17.     Im = Im(:,:,1);
  18.     Im_c = Im_c(:,:,1);
  19.   endif
  20.  
  21.   MSE = sum(sum((Im .- Im_c).^2)) / (rows(Im) * columns(Im));
  22.   if MSE == 0
  23.     PSNR = inf
  24.   else
  25.     PSNR = 10 * log10((2^8 - 1)^2/MSE);
  26.   endif
  27. endfunction
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement