iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImageOperatorsImpl.H
Go to the documentation of this file.
1 /*! @file
2  @author David J. Berg
3  @copyright GNU Public License (GPL v3)
4  @section License
5  @verbatim
6  // ////////////////////////////////////////////////////////////////////////
7  // The iLab Neuromorphic Robotics Toolkit (NRT) //
8  // Copyright 2010-2012 by the University of Southern California (USC) //
9  // and the iLab at USC. //
10  // //
11  // iLab - University of Southern California //
12  // Hedco Neurociences Building, Room HNB-10 //
13  // Los Angeles, Ca 90089-2520 - USA //
14  // //
15  // See http://ilab.usc.edu for information about this project. //
16  // ////////////////////////////////////////////////////////////////////////
17  // This file is part of The iLab Neuromorphic Robotics Toolkit. //
18  // //
19  // The iLab Neuromorphic Robotics Toolkit is free software: you can //
20  // redistribute it and/or modify it under the terms of the GNU General //
21  // Public License as published by the Free Software Foundation, either //
22  // version 3 of the License, or (at your option) any later version. //
23  // //
24  // The iLab Neuromorphic Robotics Toolkit is distributed in the hope //
25  // that it will be useful, but WITHOUT ANY WARRANTY; without even the //
26  // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
27  // PURPOSE. See the GNU General Public License for more details. //
28  // //
29  // You should have received a copy of the GNU General Public License //
30  // along with The iLab Neuromorphic Robotics Toolkit. If not, see //
31  // <http://www.gnu.org/licenses/>. //
32  // ////////////////////////////////////////////////////////////////////////
33  @endverbatim */
34 
35 
36 // ######################################################################
37 // plus
38 // ######################################################################
39 template <class PixType1, class PixType2> inline
40 typename std::enable_if<nrt::nrt_traits<PixType1, PixType2>::has_assign_arithmetic, nrt::Image<PixType1> >::type &
42 {
43  std::transform(lhs.const_begin(), lhs.const_end(), rhs.const_begin(), lhs.begin(),
44  [](PixType1 const & l, PixType2 const& r) { return l+r; });
45  return lhs;
46 }
47 
48 // ######################################################################
49 template <class PixType1, class T> inline
50 typename std::enable_if<nrt::nrt_traits<PixType1, T>::has_assign_arithmetic, nrt::Image<PixType1> >::type &
51 nrt::operator+=(nrt::Image<PixType1>& lhs, T const& rhs)
52 {
53  std::transform(lhs.const_begin(), lhs.const_end(), lhs.begin(),
54  [&rhs](PixType1 const & l) { return l+rhs; });
55  return lhs;
56 }
57 
58 // ######################################################################
59 template <class PixType1, class PixType2> inline
60 typename std::enable_if<nrt::nrt_traits<PixType1, PixType2>::has_arithmetic,
63 {
64  typedef typename nrt::nrt_traits<PixType1,PixType2>::promote_type PromoType;
65  nrt::Image<PromoType> ret(lhs.dims());
66  std::transform(lhs.const_begin(), lhs.const_end(), rhs.const_begin(), ret.begin(),
67  [](PixType1 const& l, PixType2 const& r)->PromoType { return l+r; });
68  return ret;
69 }
70 
71 // ######################################################################
72 template <class PixType1, class T> inline
73 typename std::enable_if<nrt::nrt_traits<PixType1, T>::has_arithmetic,
75 nrt::operator+(nrt::Image<PixType1> const& lhs, T const& rhs)
76 {
77  typedef typename nrt::nrt_traits<PixType1,T>::promote_type PromoType;
78  nrt::Image<PromoType> ret(lhs.dims());
79  std::transform(lhs.const_begin(), lhs.const_end(), ret.begin(),
80  [&rhs](PixType1 const& l)->PromoType { return l+rhs; });
81  return ret;
82 }
83 
84 // ######################################################################
85 template <class PixType1, class T> inline
86 typename std::enable_if<nrt::nrt_traits<PixType1, T>::has_arithmetic,
88 nrt::operator+(T const& lhs, nrt::Image<PixType1> const& rhs)
89 {
90  typedef typename nrt::nrt_traits<PixType1,T>::promote_type PromoType;
91  nrt::Image<PromoType> ret(rhs.dims());
92  std::transform(rhs.const_begin(), rhs.const_end(), ret.begin(),
93  [&lhs](PixType1 const& r)->PromoType { return lhs+r; });
94  return ret;
95 }
96 
97 // ######################################################################
98 // minus
99 // ######################################################################
100 template <class PixType1, class PixType2> inline
101 typename std::enable_if<nrt::nrt_traits<PixType1, PixType2>::has_assign_arithmetic, nrt::Image<PixType1> >::type &
103 {
104  std::transform(lhs.const_begin(), lhs.const_end(), rhs.const_begin(), lhs.begin(),
105  [](PixType1 const & l, PixType2 const& r) { return l-r; });
106  return lhs;
107 }
108 
109 // ######################################################################
110 template <class PixType1, class T> inline
111 typename std::enable_if<nrt::nrt_traits<PixType1, T>::has_assign_arithmetic, nrt::Image<PixType1> >::type &
112 nrt::operator-=(nrt::Image<PixType1>& lhs, T const& rhs)
113 {
114  std::transform(lhs.const_begin(), lhs.const_end(), lhs.begin(),
115  [&rhs](PixType1 const & l) { return l-rhs; });
116  return lhs;
117 }
118 
119 // ######################################################################
120 template <class PixType1, class PixType2> inline
121 typename std::enable_if<nrt::nrt_traits<PixType1, PixType2>::has_arithmetic,
124 {
125  typedef typename nrt::nrt_traits<PixType1,PixType2>::promote_type PromoType;
126  nrt::Image<PromoType> ret(lhs.dims());
127  std::transform(lhs.const_begin(), lhs.const_end(), rhs.const_begin(), ret.begin(),
128  [](PixType1 const& l, PixType2 const& r)->PromoType { return l-r; });
129  return ret;
130 }
131 
132 // ######################################################################
133 template <class PixType1, class T> inline
134 typename std::enable_if<nrt::nrt_traits<PixType1, T>::has_arithmetic,
136 nrt::operator-(nrt::Image<PixType1> const& lhs, T const& rhs)
137 {
138  typedef typename nrt::nrt_traits<PixType1,T>::promote_type PromoType;
139  nrt::Image<PromoType> ret(lhs.dims());
140  std::transform(lhs.const_begin(), lhs.const_end(), ret.begin(),
141  [&rhs](PixType1 const& l)->PromoType { return l-rhs; });
142  return ret;
143 }
144 
145 // ######################################################################
146 template <class PixType1, class T> inline
147 typename std::enable_if<nrt::nrt_traits<PixType1, T>::has_arithmetic,
149 nrt::operator-(T const& lhs, nrt::Image<PixType1> const& rhs)
150 {
151  typedef typename nrt::nrt_traits<PixType1,T>::promote_type PromoType;
152  nrt::Image<PromoType> ret(rhs.dims());
153  std::transform(rhs.const_begin(), rhs.const_end(), ret.begin(),
154  [&lhs](PixType1 const& r)->PromoType { return lhs-r; });
155  return ret;
156 }
157 
158 // ######################################################################
159 // multiplies
160 // ######################################################################
161 template <class PixType1, class PixType2> inline
162 typename std::enable_if<nrt::nrt_traits<PixType1, PixType2>::has_assign_arithmetic, nrt::Image<PixType1> >::type &
164 {
165  std::transform(lhs.const_begin(), lhs.const_end(), rhs.const_begin(), lhs.begin(),
166  [](PixType1 const & l, PixType2 const& r) { return l*r; });
167  return lhs;
168 }
169 
170 // ######################################################################
171 template <class PixType1, class T> inline
172 typename std::enable_if<nrt::nrt_traits<PixType1, T>::has_assign_arithmetic, nrt::Image<PixType1> >::type &
173 nrt::operator*=(nrt::Image<PixType1>& lhs, T const& rhs)
174 {
175  std::transform(lhs.const_begin(), lhs.const_end(), lhs.begin(),
176  [&rhs](PixType1 const & l) { return l*rhs; });
177  return lhs;
178 }
179 
180 // ######################################################################
181 template <class PixType1, class PixType2> inline
182 typename std::enable_if<nrt::nrt_traits<PixType1, PixType2>::has_arithmetic,
185 {
186  typedef typename nrt::nrt_traits<PixType1,PixType2>::promote_type PromoType;
187  nrt::Image<PromoType> ret(lhs.dims());
188  std::transform(lhs.const_begin(), lhs.const_end(), rhs.const_begin(), ret.begin(),
189  [](PixType1 const& l, PixType2 const& r)->PromoType { return l*r; });
190  return ret;
191 }
192 
193 // ######################################################################
194 template <class PixType1, class T> inline
195 typename std::enable_if<nrt::nrt_traits<PixType1, T>::has_arithmetic,
197 nrt::operator*(nrt::Image<PixType1> const& lhs, T const& rhs)
198 {
199  typedef typename nrt::nrt_traits<PixType1,T>::promote_type PromoType;
200  nrt::Image<PromoType> ret(lhs.dims());
201  std::transform(lhs.const_begin(), lhs.const_end(), ret.begin(),
202  [&rhs](PixType1 const& l)->PromoType { return l*rhs; });
203  return ret;
204 }
205 
206 // ######################################################################
207 template <class PixType1, class T> inline
208 typename std::enable_if<nrt::nrt_traits<PixType1, T>::has_arithmetic,
210 nrt::operator*(T const& lhs, nrt::Image<PixType1> const& rhs)
211 {
212  typedef typename nrt::nrt_traits<PixType1,T>::promote_type PromoType;
213  nrt::Image<PromoType> ret(rhs.dims());
214  std::transform(rhs.const_begin(), rhs.const_end(), ret.begin(),
215  [&lhs](PixType1 const& r)->PromoType { return lhs*r; });
216  return ret;
217 }
218 
219 // ######################################################################
220 // divides
221 // ######################################################################
222 template <class PixType1, class PixType2> inline
223 typename std::enable_if<nrt::nrt_traits<PixType1, PixType2>::has_assign_arithmetic, nrt::Image<PixType1> >::type &
225 {
226  std::transform(lhs.const_begin(), lhs.const_end(), rhs.const_begin(), lhs.begin(),
227  [](PixType1 const & l, PixType2 const& r) { return l/r; });
228  return lhs;
229 }
230 
231 // ######################################################################
232 template <class PixType1, class T> inline
233 typename std::enable_if<nrt::nrt_traits<PixType1, T>::has_assign_arithmetic, nrt::Image<PixType1> >::type &
234 nrt::operator/=(nrt::Image<PixType1>& lhs, T const& rhs)
235 {
236  std::transform(lhs.const_begin(), lhs.const_end(), lhs.begin(),
237  [&rhs](PixType1 const & l) { return l/rhs; });
238  return lhs;
239 }
240 
241 // ######################################################################
242 template <class PixType1, class PixType2> inline
243 typename std::enable_if<nrt::nrt_traits<PixType1, PixType2>::has_arithmetic,
246 {
247  typedef typename nrt::nrt_traits<PixType1,PixType2>::promote_type PromoType;
248  nrt::Image<PromoType> ret(lhs.dims());
249  std::transform(lhs.const_begin(), lhs.const_end(), rhs.const_begin(), ret.begin(),
250  [](PixType1 const& l, PixType2 const& r)->PromoType { return l/r; });
251  return ret;
252 }
253 
254 // ######################################################################
255 template <class PixType1, class T> inline
256 typename std::enable_if<nrt::nrt_traits<PixType1, T>::has_arithmetic,
258 nrt::operator/(nrt::Image<PixType1> const& lhs, T const& rhs)
259 {
260  typedef typename nrt::nrt_traits<PixType1,T>::promote_type PromoType;
261  nrt::Image<PromoType> ret(lhs.dims());
262  std::transform(lhs.const_begin(), lhs.const_end(), ret.begin(),
263  [&rhs](PixType1 const& l)->PromoType { return l/rhs; });
264  return ret;
265 }
266 
267 // ######################################################################
268 template <class PixType1, class T> inline
269 typename std::enable_if<nrt::nrt_traits<PixType1, T>::has_arithmetic,
271 nrt::operator/(T const& lhs, nrt::Image<PixType1> const& rhs)
272 {
273  typedef typename nrt::nrt_traits<PixType1,T>::promote_type PromoType;
274  nrt::Image<PromoType> ret(rhs.dims());
275  std::transform(rhs.const_begin(), rhs.const_end(), ret.begin(),
276  [&lhs](PixType1 const& r)->PromoType { return lhs/r; });
277  return ret;
278 }