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

Function avg_pixel_delta

dlib/test/image.cpp:2485–2509  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2483
2484 template <typename pixel_type>
2485 double avg_pixel_delta(const matrix<pixel_type>& img1, const matrix<pixel_type>& img2)
2486 {
2487 DLIB_TEST(have_same_dimensions(img1, img2));
2488
2489 double delta = 0;
2490 double size = 0;
2491 for (long r = 0; r < img1.nr(); ++r)
2492 {
2493 for (long c = 0; c < img1.nc(); ++c)
2494 {
2495 const auto p1 = pixel_to_vector<double>(img1(r,c));
2496 const auto p2 = pixel_to_vector<double>(img2(r,c));
2497
2498 const bool has_alpha = p1.size() == 4;
2499 // We are using the default WebP settings, which means 'exact' is disabled.
2500 // RGB values in transparent areas will be modified to improve compression.
2501 // As a result, we skip matching transparent pixels.
2502 if (has_alpha && p1(3) == 0 && p2(3) == 0) continue;
2503
2504 delta += sum(abs(p1-p2));
2505 size += p1.size();
2506 }
2507 }
2508 return delta / size;
2509 }
2510
2511 void test_webp()
2512 {

Callers 1

test_webpFunction · 0.85

Calls 6

absFunction · 0.85
have_same_dimensionsFunction · 0.50
sumFunction · 0.50
nrMethod · 0.45
ncMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected