Debian Codegraph @

cvd/integral_image.h

raw symbols SCIP
1
2 #ifndef CVD_INC_INTEGRAL_IMAGE_H
3 #define CVD_INC_INTEGRAL_IMAGE_H
4
5 #include <cvd/image.h>
6 #include <cvd/internal/pixel_operations.h>
7 #include <cvd/vision.h>
8
9 namespace CVD
10 {
11 ///Compute an integral image. In an integral image, pixel (x,y) is equal to the sum of all the pixels
12 ///in the rectangle from (0,0) to (x,y) in the original image.
13 /// and reallocation is not performed if <code>b</code> is unique and of the correct size.
14 /// @param D The destination image pixel type
15 /// @param S The source image pixel type
16 /// @param in The source image.
17 /// @param out The source image.
18 /// @ingroup gVision
19
20 template <class S, class D>
21 void integral_image(const BasicImage<S>& in, BasicImage<D>& out)
22 {
23 if(in.size() != out.size())
24 throw Exceptions::Vision::IncompatibleImageSizes("integral_image");
25
26 Pixel::operations<D>::assign(out[0][0], in[0][0]);
27 //Do the first row.
28 for(int x = 1; x < in.size().x; x++)
29 out[0][x] = out[0][x - 1] + in[0][x];
30
31 //Do the first column.
32 for(int y = 1; y < in.size().y; y++)
33 out[y][0] = out[y - 1][0] + in[y][0];
34
35 //Do the remainder of the image
36 for(int y = 1; y < in.size().y; y++)
37 {
38 D sum;
39 Pixel::operations<D>::assign(sum, in[y][0]);
40
41 for(int x = 1; x < in.size().x; x++)
42 {
43 sum += in[y][x];
44 Pixel::operations<D>::assign(out[y][x], sum + out[y - 1][x]);
45 }
46 }
47 }
48 #ifndef DOXYGEN_IGNORE_INTERNAL
49 namespace Internal
50 {
51 template <class C>
52 class IntegralImage
53 {
54 };
55
56 template <class C>
57 struct ImagePromise<IntegralImage<C>>
58 {
59 ImagePromise(const BasicImage<C>& im)
60 : i(im)
61 {
62 }
63
64 const BasicImage<C>& i;
65 template <class D>
66 void execute(Image<D>& j)
67 {
68 j.resize(i.size());
69 integral_image<C, D>(i, j);
70 }
71 };
72 };
73
74 template <class C>
75 Internal::ImagePromise<Internal::IntegralImage<C>> integral_image(const BasicImage<C>& c)
76 {
77 return Internal::ImagePromise<Internal::IntegralImage<C>>(c);
78 }
79 #else
80 ///Compute an integral image. In an integral image, pixel (x,y) is equal to the sum of all the pixels
81 ///in the rectangle from (0,0) to (x,y) in the original image.
82 ///Type deduction is automatic, and D can not be specified. The following usage will work:
83 ///
84 /// \code
85 /// Image<byte> a;
86 /// Image<int> b;
87 /// ...
88 /// b = integral_image(a);
89 /// \endcode
90 /// Note that this is performed using lazy evaluation, so convertion happens on evaluation of assignment,
91 /// and reallocation is not performed if <code>b</code> is unique and of the correct size.
92 /// @param D The destination image pixel type
93 /// @param S The source image pixel type
94 /// @param from The source image.
95 /// @return The integral image
96 /// @ingroup gVision
97 template <class S, class D>
98 Image<D> integral_image(const BasicImage<S>& from);
99
100 #endif
101
102 }
103
104 #endif