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,14 +181,13 @@ double getPSNR(const Mat& I1, const Mat& I2)
|
||||||
|
|
||||||
double sse = s.val[0] + s.val[1] + s.val[2]; // sum channels
|
double sse = s.val[0] + s.val[1] + s.val[2]; // sum channels
|
||||||
|
|
||||||
if( sse <= 1e-10) // for small values return zero
|
double mse = sse /(double)(I1.channels() * I1.total());
|
||||||
return 0;
|
|
||||||
else
|
// For very small SSE, add epsilon to approximate infinite PSNR (~361 dB)
|
||||||
{
|
if( sse <= 1e-10) mse+= DBL_EPSILON;
|
||||||
double mse =sse /(double)(I1.channels() * I1.total());
|
|
||||||
double psnr = 10.0*log10((255*255)/mse);
|
double psnr = 10.0*log10((255*255)/mse);
|
||||||
return psnr;
|
return psnr;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//! [getpsnr]
|
//! [getpsnr]
|
||||||
|
|
||||||
|
|
@ -206,14 +205,13 @@ double getPSNR_CUDA_optimized(const Mat& I1, const Mat& I2, BufferPSNR& b)
|
||||||
|
|
||||||
double sse = cuda::sum(b.gs, b.buf)[0];
|
double sse = cuda::sum(b.gs, b.buf)[0];
|
||||||
|
|
||||||
if( sse <= 1e-10) // for small values return zero
|
double mse = sse /(double)(I1.channels() * I1.total());
|
||||||
return 0;
|
|
||||||
else
|
// For very small SSE, add epsilon to approximate infinite PSNR (~361 dB)
|
||||||
{
|
if (sse <= 1e-10) mse += DBL_EPSILON;
|
||||||
double mse = sse /(double)(I1.channels() * I1.total());
|
|
||||||
double psnr = 10.0*log10((255*255)/mse);
|
double psnr = 10.0*log10((255*255)/mse);
|
||||||
return psnr;
|
return psnr;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//! [getpsnropt]
|
//! [getpsnropt]
|
||||||
|
|
||||||
|
|
@ -234,14 +232,13 @@ double getPSNR_CUDA(const Mat& I1, const Mat& I2)
|
||||||
Scalar s = cuda::sum(gs);
|
Scalar s = cuda::sum(gs);
|
||||||
double sse = s.val[0] + s.val[1] + s.val[2];
|
double sse = s.val[0] + s.val[1] + s.val[2];
|
||||||
|
|
||||||
if( sse <= 1e-10) // for small values return zero
|
double mse = sse /(double)(gI1.channels() * I1.total());
|
||||||
return 0;
|
|
||||||
else
|
// For very small SSE, add epsilon to approximate infinite PSNR (~361 dB)
|
||||||
{
|
if( sse <= 1e-10) mse+= DBL_EPSILON;
|
||||||
double mse =sse /(double)(gI1.channels() * I1.total());
|
|
||||||
double psnr = 10.0*log10((255*255)/mse);
|
double psnr = 10.0*log10((255*255)/mse);
|
||||||
return psnr;
|
return psnr;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//! [getpsnrcuda]
|
//! [getpsnrcuda]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
double sse = s.val[0] + s.val[1] + s.val[2]; // sum channels
|
||||||
|
|
||||||
if( sse <= 1e-10) // for small values return zero
|
if( sse <= 1e-10) // For very small values, return 360 to cap PSNR (theoretical value is infinity)
|
||||||
return 0;
|
return 360.0;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
double mse = sse / (double)(I1.channels() * I1.total());
|
double mse = sse / (double)(I1.channels() * I1.total());
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ def getPSNR(I1, I2):
|
||||||
s1 = s1 * s1 # |I1 - I2|^2
|
s1 = s1 * s1 # |I1 - I2|^2
|
||||||
sse = s1.sum() # sum elements per channel
|
sse = s1.sum() # sum elements per channel
|
||||||
if sse <= 1e-10: # sum channels
|
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:
|
else:
|
||||||
shape = I1.shape
|
shape = I1.shape
|
||||||
mse = 1.0 * sse / (shape[0] * shape[1] * shape[2])
|
mse = 1.0 * sse / (shape[0] * shape[1] * shape[2])
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user