imStats.m 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. % imStats(IM1,IM2)
  2. %
  3. % Report image (matrix) statistics.
  4. % When called on a single image IM1, report min, max, mean, stdev, skew,
  5. % and kurtosis (4th moment about the mean, divided by squared variance)
  6. %
  7. % When called on two images (IM1 and IM2), report min, max, mean,
  8. % stdev of the difference, and also SNR (relative to IM1).
  9. % Eero Simoncelli, 6/96.
  10. function [] = imStats(im1,im2)
  11. if (~isreal(im1))
  12. error('Args must be real-valued matrices');
  13. end
  14. if (exist('im2') == 1)
  15. difference = im1 - im2;
  16. [mn,mx] = range2(difference);
  17. mean = mean2(difference);
  18. v = var2(difference,mean);
  19. if (v < realmin)
  20. snr = Inf;
  21. else
  22. snr = 10 * log10(var2(im1)/v);
  23. end
  24. fprintf(1, 'Difference statistics:\n');
  25. fprintf(1, ' Range: [%c, %c]\n',mn,mx);
  26. fprintf(1, ' Mean: %f, Stdev (rmse): %f, SNR (dB): %f\n',...
  27. mean,sqrt(v),snr);
  28. else
  29. [mn,mx] = range2(im1);
  30. mean = mean2(im1);
  31. var = var2(im1,mean);
  32. stdev = sqrt(real(var))+sqrt(imag(var));
  33. sk = skew2(im1, mean, stdev^2);
  34. kurt = kurt2(im1, mean, stdev^2);
  35. fprintf(1, 'Image statistics:\n');
  36. fprintf(1, ' Range: [%f, %f]\n',mn,mx);
  37. fprintf(1, ' Mean: %f, Stdev: %f, Skew: %f, Kurt: %f\n',mean,stdev,sk,kurt);
  38. end