14 #ifndef GIL_NUMERIC_ALGORITHM_HPP 15 #define GIL_NUMERIC_ALGORITHM_HPP 29 #include "../../gil_config.hpp" 30 #include "../../pixel_iterator.hpp" 31 #include "../../metafunctions.hpp" 33 namespace boost {
namespace gil {
39 struct pixel_proxy :
public remove_reference<typename T::reference> {};
42 template <
typename Iterator1,
typename Iterator2,
typename BinaryFunction>
43 BinaryFunction
for_each(Iterator1 first1,Iterator1 last1,Iterator2 first2,BinaryFunction f) {
45 f(*first1++,*first2++);
49 template <
typename SrcIterator,
typename DstIterator>
50 inline DstIterator assign_pixels(SrcIterator src,SrcIterator src_end,DstIterator dst) {
52 typename pixel_proxy<
typename std::iterator_traits<DstIterator>::value_type>::type>());
53 return dst+(src_end-src);
57 template <std::
size_t Size>
58 struct inner_product_k_t {
59 template <
class _InputIterator1,
class _InputIterator2,
class _Tp,
60 class _BinaryOperation1,
class _BinaryOperation2>
61 static _Tp apply(_InputIterator1 __first1,
62 _InputIterator2 __first2, _Tp __init,
63 _BinaryOperation1 __binary_op1,
64 _BinaryOperation2 __binary_op2) {
65 __init = __binary_op1(__init, __binary_op2(*__first1, *__first2));
66 return inner_product_k_t<Size-1>::template apply(__first1+1,__first2+1,__init,
67 __binary_op1, __binary_op2);
72 struct inner_product_k_t<0> {
73 template <
class _InputIterator1,
class _InputIterator2,
class _Tp,
74 class _BinaryOperation1,
class _BinaryOperation2>
75 static _Tp apply(_InputIterator1 __first1,
76 _InputIterator2 __first2, _Tp __init,
77 _BinaryOperation1 __binary_op1,
78 _BinaryOperation2 __binary_op2) {
85 template <std::size_t Size,
86 class _InputIterator1,
class _InputIterator2,
class _Tp,
87 class _BinaryOperation1,
class _BinaryOperation2>
90 _InputIterator2 __first2,
92 _BinaryOperation1 __binary_op1,
93 _BinaryOperation2 __binary_op2) {
94 return detail::inner_product_k_t<Size>::template apply(__first1,__first2,__init,
95 __binary_op1, __binary_op2);
99 template <
typename PixelAccum,
typename SrcIterator,
typename KernelIterator,
typename Integer,
typename DstIterator>
101 KernelIterator ker_begin,Integer ker_size,
102 DstIterator dst_begin) {
105 typedef typename std::iterator_traits<KernelIterator>::value_type kernel_type;
107 while(src_begin!=src_end) {
109 std::inner_product(src_begin,src_begin+ker_size,ker_begin,acc_zero,
113 ++src_begin; ++dst_begin;
119 template <std::
size_t Size,
typename PixelAccum,
typename SrcIterator,
typename KernelIterator,
typename DstIterator>
121 KernelIterator ker_begin,
122 DstIterator dst_begin) {
125 typedef typename std::iterator_traits<KernelIterator>::value_type kernel_type;
127 while(src_begin!=src_end) {
129 inner_product_k<Size>(src_begin,ker_begin,acc_zero,
133 ++src_begin; ++dst_begin;
139 template <
typename PixelAccum,
typename SrcView,
typename Scalar,
typename DstView>
141 assert(src.dimensions()==dst.dimensions());
144 int height=src.height();
145 for(
int rr=0;rr<height;++rr) {
146 typename SrcView::x_iterator it_src=src.row_begin(rr);
147 typename DstView::x_iterator it_dst=dst.row_begin(rr);
148 typename SrcView::x_iterator it_src_end=src.row_end(rr);
149 while(it_src!=it_src_end) {
_Tp inner_product_k(_InputIterator1 __first1, _InputIterator2 __first2, _Tp __init, _BinaryOperation1 __binary_op1, _BinaryOperation2 __binary_op2)
static version of std::inner_product
BinaryFunction for_each(Iterator1 first1, Iterator1 last1, Iterator2 first2, BinaryFunction f)
std::for_each for a pair of iterators
construct for adding two pixels
DstIterator correlate_pixels_n(SrcIterator src_begin, SrcIterator src_end, KernelIterator ker_begin, Integer ker_size, DstIterator dst_begin)
1D un-guarded correlation with a variable-size kernel
Returns the reference proxy associated with a type that has a "reference" member typedef.
construct for setting a pixel to zero (for whatever zero means)
DstIterator correlate_pixels_k(SrcIterator src_begin, SrcIterator src_end, KernelIterator ker_begin, DstIterator dst_begin)
1D un-guarded correlation with a fixed-size kernel
void view_multiplies_scalar(const SrcView &src, const Scalar &scalar, const DstView &dst)
destination is set to be product of the source and a scalar
construct for multiplying scalar to a pixel