iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImageAlgorithms.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 #ifndef INCLUDE_NRT_CORE_IMAGE_IMAGEALGORITHMS_H
37 #define INCLUDE_NRT_CORE_IMAGE_IMAGEALGORITHMS_H
38 #include <nrt/Core/Image/Image.H>
39 namespace nrt
40 {
41  /*! \defgroup imagealgorithms Container-style Image algorithms resembling those of std::algorithm
42  These methods provide convenient wrappers to the std::algorithm library for working with Images. In general, it is
43  faster and cleaner to use these methods rather than explicitely looping through all of the pixels with a (pair of)
44  for loop(s) around Image::at() or Image::operator().
45 
46  \ingroup image
47  \see image */
48 
49  /*! @{ */ // **********************************************************************
50 
51 
52  // ######################################################################
53  // accumulate
54  // ######################################################################
55  //! Accumulate the values of all pixels in the Image.
56  /*! \param img The Image on which to perform the accumulation
57  \param init The initial value of the accumulation. The default is PixType(0).
58  \param op The binary operation to perform on the running accumulation tally and each new pixel in img.
59  The default is the plus operator, but you may supply whatever custom operator you wish. */
60  template <class PixType, class BinaryOperation=std::plus<PixType> >
61  PixType accumulate(nrt::Image<PixType> const & img, PixType init = PixType(0),
62  BinaryOperation op = std::plus<PixType>());
63 
64  // ######################################################################
65  // Transform in Place
66  // ######################################################################
67  //! Apply the given unary operator to each pixel in lhs, storing the returned value back into that pixel
68  /*! \param lhs The image on which to perform the transformation, as well as the destination for the results of op
69  \param op The unary operator which is applied to each pixel */
70  template <class PixType, class UnaryOperator>
71  void transformInPlace(nrt::Image<PixType>& lhs, UnaryOperator op);
72 
73  //! Apply the given binary operator to each pixel in lhs and rhs, and store the result in lhs's pixel
74  /*! \param lhs The left-hand-side image whose pixels are fed as the first parameter to op, as well as the destination
75  for the result of op.
76  \param rhs the right-hand-side image whose pixels are fed as the second parameter to op.
77  \param op The binary operator which is applied to each pair of pixels */
78  template <class PixType1, class PixType2, class BinaryOperator>
79  void transformInPlace(nrt::Image<PixType1> & lhs, nrt::Image<PixType2> const& rhs, BinaryOperator op);
80 
81  // ######################################################################
82  // Transform
83  // ######################################################################
84  //! Apply the given unary operator to each pixel in lhs, storing the result in a new Image.
85  /*! \param lhs The source of pixels to be fed into op
86  \param op The unary operator to apply to each pixel of lhs. The returned value is stored in the corresponding
87  location of a new Image. */
88  template <class PixType, class UnaryOperator>
89  nrt::Image<PixType> transform(nrt::Image<PixType> const& lhs, UnaryOperator op);
90 
91  //! Apply the given unary operator to each pixel in lhs, storing the result in a new Image of type PixelType.
92  /*! The only difference between this method and the one above is that the returned Image will be of type PromoteType,
93  rather than PixType.
94  \param lhs The image on which to perform the transformation.
95  \param op The unary operator which is applied to each pixel. The returned value is converted to PromoteType and
96  stored in the corresponding location of a new Image.
97  \tparam PromoteType The pixel type for the new Image */
98  template <class PromoteType, class PixType, class UnaryOperator>
99  nrt::Image<PromoteType> transform(nrt::Image<PixType> const& lhs, UnaryOperator op);
100 
101  //! Apply the given binary function to each pixel in lhs and rhs, storing the result in a new Image.
102  /*! \param lhs The left-hand-side image whose pixels are fed as the first parameter to op.
103  \param rhs The right-hand-side image whose pixels are fed as the second parameter to op.
104  \param op The binary operator which is applied to each pair of pixels. The returned value is converted to the
105  promoted value of PixType1 and PixType2, and stored in the corresponding location of a new Image. */
106  template <class PixType1, class PixType2, class BinaryOperator>
107  typename std::enable_if<nrt_traits<PixType1, PixType2>::has_arithmetic,
109  transform(nrt::Image<PixType1> const& lhs, nrt::Image<PixType2> const& rhs,
110  BinaryOperator op);
111 
112 
113  //! Apply the given unary operator to each channel of each pixel in lhs, storing the result in a new Image.
114  /*! \param lhs The source of pixels to be fed into op
115  \param op The unary operator (which takes in a single PixType::PODType) to apply to each channel of each pixel of
116  lhs. The returned value is stored in the corresponding location of a new Image. */
117  template <class PixType, class UnaryOperator>
118  nrt::Image<PixType> channel_transform(nrt::Image<PixType> const& lhs, UnaryOperator op);
119 
120  //! Apply given unary operator to each channel of each pixel in lhs, storing result in a new Image of type PixelType
121  /*! The only difference between this method and the one above is that the returned Image will be of type PromoteType,
122  rather than PixType.
123  \param lhs The image on which to perform the transformation.
124  \param op The unary operator (which takes in a single PixType::PODType) which is applied to each channel of each
125  pixel.
126 
127  The returned value is converted to PromoteType and stored in the corresponding location of a new Image. \tparam
128  PromoteType The pixel type for the new Image */
129  template <class PromoteType, class PixType, class UnaryOperator>
130  nrt::Image<PromoteType> channel_transform(nrt::Image<PixType> const& lhs, UnaryOperator op);
131 
132  //! Apply the given binary function to each channel of each pixel in lhs and rhs, storing the result in a new Image.
133  /*! \param lhs The left-hand-side image whose pixels are fed as the first parameter to op.
134  \param rhs The right-hand-side image whose pixels are fed as the second parameter to op.
135 
136  \param op The binary operator (which takes in a two PixType::PODType's) which is applied to each channel of each
137  pair of pixels.
138 
139  The returned value is converted to the promoted value of PixType1 and PixType2, and stored in the corresponding
140  location of a new Image. */
141  template <class PixType1, class PixType2, class BinaryOperator>
142  typename std::enable_if<nrt_traits<PixType1, PixType2>::has_arithmetic,
145  BinaryOperator op);
146 
147  // ######################################################################
148  // for each
149  // ######################################################################
150  //! Run the given unary function on each pixel in img.
151  /*! \param img The Image on which to apply the unary function.
152  \param op A unary function that is run with each pixel as a parameter. */
153  template <class PixType, class UnaryFunction>
154  void for_each(nrt::Image<PixType> const& img, UnaryFunction op);
155 
156  /*! @} */ // **********************************************************************
157 
158 }
160 #endif // INCLUDE_NRT_CORE_IMAGE_IMAGEALGORITHMS_H
161