| 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 | { |
no test coverage detected