Function iastat

Synopse

Calculates MSE, PSNR and Pearson correlation between two images.

  • MSE, PSNR, PC = iastat(f1, f2)
    • MSE: Double.
    • PSNR: Double.
    • PC: Double.
    • f1: Image. Input image 1.
    • f2: Image. Input image 2 (Ex.: input image 1 degraded).
01. from numpy import *
02. 
03. def iastat(f1, f2):
04. 
05.     f1_, f2_ = 1.*ravel(f1), 1.*ravel(f2)
06. 
07.     #-- MSE --
08.     MSE = sum((f1_-f2_)**2)/product(f1.shape[:2])
09. 
10.     #-- PSNR --
11.     if MSE == 0:
12.         PSNR = 1E309 # infinito
13.     else:
14.         PSNR= 10*log10(255./MSE)
15.         PSNR = 0.0007816*(PSNR**2) - 0.06953*PSNR + 1.5789
16. 
17.     #-- PC --
18.     N = len(f1_)
19.     r1 = sum(f1_*f2_) - sum(f1_)*sum(f2_)/N
20.     r2 = sqrt((sum(f1_**2)-(sum(f1_)**2)/N)*(sum(f2_**2)-(sum(f2_)**2)/N))
21.     PC = r1/r2
22.     return MSE, PSNR, PC

Description

Calculates the mean square error (MSE), the peak signal noise ratio (PSNR), and the correlation of the product of the moments of Pearson (PC), between two images.

Examples

Example 1

01. from ia636 import iastat
02. 
03. f1 = array([[2,5,3],[4,1,2]])
04. print f1
05. f2 = array([[4,9,5],[8,3,3]])
06. print f2
07. (mse, psnr, pc) = iastat(f1, f2)
08. print mse
09. print psnr
10. print pc
[[2 5 3]
 [4 1 2]]
[[4 9 5]
 [8 3 3]]
7.5
0.697381335929
0.964763821238

Equation