1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
// Copyright (C) 2009 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#undef DLIB_INTEGRAL_IMAGe_ABSTRACT_
#ifdef DLIB_INTEGRAL_IMAGe_ABSTRACT_
#include "../geometry/rectangle_abstract.h"
#include "../array2d/array2d_kernel_abstract.h"
#include "../pixel.h"
#include "../noncopyable.h"
namespace dlib
{
// ----------------------------------------------------------------------------------------
template <
typename T
>
class integral_image_generic : noncopyable
{
/*!
REQUIREMENTS ON T
T should be a built in scalar type. Moreover, it should
be capable of storing sums of whatever kind of pixel
you will be dealing with.
INITIAL VALUE
- nr() == 0
- nc() == 0
WHAT THIS OBJECT REPRESENTS
This object is an alternate way of representing image data
that allows for very fast computations of sums of pixels in
rectangular regions. To use this object you load it with a
normal image and then you can use the get_sum_of_area()
function to compute sums of pixels in a given area in
constant time.
!*/
public:
typedef T value_type;
const long nr(
) const;
/*!
ensures
- returns the number of rows in this integral image object
!*/
const long nc(
) const;
/*!
ensures
- returns the number of columns in this integral image object
!*/
template <typename image_type>
void load (
const image_type& img
);
/*!
requires
- image_type == a type that implements the array2d/array2d_kernel_abstract.h interface
- pixel_traits<typename image_type::type>::has_alpha == false
ensures
- #nr() == img.nr()
- #nc() == img.nc()
- #*this will now contain an "integral image" representation of the
given input image.
!*/
value_type get_sum_of_area (
const rectangle& rect
) const;
/*!
requires
- rect.is_empty() == false
- get_rect(*this).contains(rect) == true
(i.e. rect must not be outside the integral image)
ensures
- Let O denote the image this integral image was generated from.
Then this function returns sum(subm(array_to_matrix(O),rect)).
That is, this function returns the sum of the pixels in O that
are contained within the given rectangle.
!*/
};
// ----------------------------------------------------------------------------------------
typedef integral_image_generic<long> integral_image;
// ----------------------------------------------------------------------------------------
template <typename integral_image_type>
typename integral_image_type::value_type haar_x (
const integral_image_type& img,
const point& p,
long width
)
/*!
requires
- get_rect(img).contains(centered_rect(p,width,width)) == true
- integral_image_type == a type that implements the integral_image_generic
interface defined above
ensures
- returns the response of a Haar wavelet centered at the point p
with the given width. The wavelet is oriented along the X axis
and has the following shape:
----++++
----++++
----++++
----++++
That is, the wavelet is square and computes the sum of pixels on the
right minus the sum of pixels on the left.
!*/
// ----------------------------------------------------------------------------------------
template <typename integral_image_type>
typename integral_image_type::value_type haar_y (
const integral_image_type& img,
const point& p,
long width
)
/*!
requires
- get_rect(img).contains(centered_rect(p,width,width)) == true
- integral_image_type == a type that implements the integral_image_generic
interface defined above
ensures
- returns the response of a Haar wavelet centered at the point p
with the given width in the given image. The wavelet is oriented
along the Y axis and has the following shape:
--------
--------
++++++++
++++++++
That is, the wavelet is square and computes the sum of pixels on the
bottom minus the sum of pixels on the top.
!*/
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_INTEGRAL_IMAGe_ABSTRACT_
|