libcvd
integral_image.h
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 {
19 
20 template <class S, class D>
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>
53  {
54  };
55 
56  template <class 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>
76 {
78 }
79 #else
80 template <class S, class D>
99 
100 #endif
101 
102 }
103 
104 #endif
Input images have incompatible dimensions.
Definition: vision_exceptions.h:26
All classes and functions are within the CVD namespace.
Definition: argb.h:6
ImageRef size() const
What is the size of this image?
Definition: image.h:557
void integral_image(const BasicImage< S > &in, BasicImage< D > &out)
Compute an integral image.
Definition: integral_image.h:21
Definition: pixel_operations.h:19
void resize(const ImageRef &size)
Resize the image (destroying the data).
Definition: image.h:731
int x
The x co-ordinate.
Definition: image_ref.h:172
Definition: image.h:62
A generic image class to manage a block of arbitrarily padded data as an image.
Definition: image.h:273
Definition: integral_image.h:52
int y
The y co-ordinate.
Definition: image_ref.h:173
A full image which manages its own data.
Definition: image.h:623