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

Function avg_pixel_delta

dlib/test/image.cpp:2570–2594  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2568
2569 template <typename pixel_type>
2570 double avg_pixel_delta(const matrix<pixel_type>& img1, const matrix<pixel_type>& img2)
2571 {
2572 DLIB_TEST(have_same_dimensions(img1, img2));
2573
2574 double delta = 0;
2575 double size = 0;
2576 for (long r = 0; r < img1.nr(); ++r)
2577 {
2578 for (long c = 0; c < img1.nc(); ++c)
2579 {
2580 const auto p1 = pixel_to_vector<double>(img1(r,c));
2581 const auto p2 = pixel_to_vector<double>(img2(r,c));
2582
2583 const bool has_alpha = p1.size() == 4;
2584 // We are using the default WebP settings, which means 'exact' is disabled.
2585 // RGB values in transparent areas will be modified to improve compression.
2586 // As a result, we skip matching transparent pixels.
2587 if (has_alpha && p1(3) == 0 && p2(3) == 0) continue;
2588
2589 delta += sum(abs(p1-p2));
2590 size += p1.size();
2591 }
2592 }
2593 return delta / size;
2594 }
2595
2596 void test_webp()
2597 {

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