mirror of
https://github.com/zebrajr/opencv.git
synced 2025-12-06 12:19:50 +01:00
Updated Tutorial PSNR for identical images
This commit is contained in:
parent
e9bded6ff3
commit
acc76304d5
|
|
@ -181,15 +181,14 @@ double getPSNR(const Mat& I1, const Mat& I2)
|
|||
|
||||
double sse = s.val[0] + s.val[1] + s.val[2]; // sum channels
|
||||
|
||||
if( sse <= 1e-10) // for small values return zero
|
||||
return 0;
|
||||
else
|
||||
{
|
||||
double mse = sse /(double)(I1.channels() * I1.total());
|
||||
|
||||
// For very small SSE, add epsilon to approximate infinite PSNR (~361 dB)
|
||||
if( sse <= 1e-10) mse+= DBL_EPSILON;
|
||||
|
||||
double psnr = 10.0*log10((255*255)/mse);
|
||||
return psnr;
|
||||
}
|
||||
}
|
||||
//! [getpsnr]
|
||||
|
||||
//! [getpsnropt]
|
||||
|
|
@ -206,15 +205,14 @@ double getPSNR_CUDA_optimized(const Mat& I1, const Mat& I2, BufferPSNR& b)
|
|||
|
||||
double sse = cuda::sum(b.gs, b.buf)[0];
|
||||
|
||||
if( sse <= 1e-10) // for small values return zero
|
||||
return 0;
|
||||
else
|
||||
{
|
||||
double mse = sse /(double)(I1.channels() * I1.total());
|
||||
|
||||
// For very small SSE, add epsilon to approximate infinite PSNR (~361 dB)
|
||||
if (sse <= 1e-10) mse += DBL_EPSILON;
|
||||
|
||||
double psnr = 10.0*log10((255*255)/mse);
|
||||
return psnr;
|
||||
}
|
||||
}
|
||||
//! [getpsnropt]
|
||||
|
||||
//! [getpsnrcuda]
|
||||
|
|
@ -234,15 +232,14 @@ double getPSNR_CUDA(const Mat& I1, const Mat& I2)
|
|||
Scalar s = cuda::sum(gs);
|
||||
double sse = s.val[0] + s.val[1] + s.val[2];
|
||||
|
||||
if( sse <= 1e-10) // for small values return zero
|
||||
return 0;
|
||||
else
|
||||
{
|
||||
double mse = sse /(double)(gI1.channels() * I1.total());
|
||||
|
||||
// For very small SSE, add epsilon to approximate infinite PSNR (~361 dB)
|
||||
if( sse <= 1e-10) mse+= DBL_EPSILON;
|
||||
|
||||
double psnr = 10.0*log10((255*255)/mse);
|
||||
return psnr;
|
||||
}
|
||||
}
|
||||
//! [getpsnrcuda]
|
||||
|
||||
//! [getssim]
|
||||
|
|
|
|||
|
|
@ -144,8 +144,8 @@ double getPSNR(const Mat& I1, const Mat& I2)
|
|||
|
||||
double sse = s.val[0] + s.val[1] + s.val[2]; // sum channels
|
||||
|
||||
if( sse <= 1e-10) // for small values return zero
|
||||
return 0;
|
||||
if( sse <= 1e-10) // For very small values, return 360 to cap PSNR (theoretical value is infinity)
|
||||
return 360.0;
|
||||
else
|
||||
{
|
||||
double mse = sse / (double)(I1.channels() * I1.total());
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ def getPSNR(I1, I2):
|
|||
s1 = s1 * s1 # |I1 - I2|^2
|
||||
sse = s1.sum() # sum elements per channel
|
||||
if sse <= 1e-10: # sum channels
|
||||
return 0 # for small values return zero
|
||||
return 360 # For very small SSE, return 360 to cap PSNR (theoretical value is infinity)
|
||||
else:
|
||||
shape = I1.shape
|
||||
mse = 1.0 * sse / (shape[0] * shape[1] * shape[2])
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user