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

Function get_gradient

dlib/image_transforms/fhog.h:24–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22 {
23 template <typename image_type, typename T>
24 inline typename dlib::enable_if_c<pixel_traits<typename image_type::pixel_type>::rgb>::type get_gradient (
25 const int r,
26 const int c,
27 const image_type& img,
28 matrix<T,2,1>& grad,
29 T& len
30 )
31 {
32 matrix<T, 2, 1> grad2, grad3;
33 // get the red gradient
34 grad(0) = (int)img[r][c+1].red-(int)img[r][c-1].red;
35 grad(1) = (int)img[r+1][c].red-(int)img[r-1][c].red;
36 len = length_squared(grad);
37
38 // get the green gradient
39 grad2(0) = (int)img[r][c+1].green-(int)img[r][c-1].green;
40 grad2(1) = (int)img[r+1][c].green-(int)img[r-1][c].green;
41 T v2 = length_squared(grad2);
42
43 // get the blue gradient
44 grad3(0) = (int)img[r][c+1].blue-(int)img[r][c-1].blue;
45 grad3(1) = (int)img[r+1][c].blue-(int)img[r-1][c].blue;
46 T v3 = length_squared(grad3);
47
48 // pick color with strongest gradient
49 if (v2 > len)
50 {
51 len = v2;
52 grad = grad2;
53 }
54 if (v3 > len)
55 {
56 len = v3;
57 grad = grad3;
58 }
59 }
60
61 template <typename image_type>
62 inline typename dlib::enable_if_c<pixel_traits<typename image_type::pixel_type>::rgb>::type get_gradient (

Calls 3

get_pixel_intensityFunction · 0.85
length_squaredFunction · 0.50
selectFunction · 0.50

Tested by

no test coverage detected