MCPcopy Create free account
hub / github.com/davisking/dlib / psnr

Function psnr

dlib/test/ffmpeg.cpp:120–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

118
119 template <typename pixel_type>
120 static double psnr(const matrix<pixel_type>& img1, const matrix<pixel_type>& img2)
121 {
122 DLIB_TEST(have_same_dimensions(img1, img2));
123 const long nk = width_step(img1) / img1.nc();
124 const long data_size = img1.size() * nk;
125 auto* data1 = reinterpret_cast<const uint8_t*>(image_data(img1));
126 auto* data2 = reinterpret_cast<const uint8_t*>(image_data(img2));
127
128 double mse = 0;
129 for (long i = 0; i < data_size; i += nk)
130 {
131 for (long k = 0; k < nk; ++k)
132 mse += std::pow(static_cast<double>(data1[i + k]) - static_cast<double>(data2[i + k]), 2);
133 }
134 mse /= data_size;
135 return 20 * std::log10(pixel_traits<pixel_type>::max()) - 10 * std::log10(mse);
136 }
137
138 void test_load_frame(const std::string& filename)
139 {

Callers 2

test_load_frameFunction · 0.85
test_load_save_frameFunction · 0.85

Calls 7

log10Function · 0.85
have_same_dimensionsFunction · 0.50
width_stepFunction · 0.50
image_dataFunction · 0.50
maxFunction · 0.50
ncMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected