LSSTApplications  11.0-13-gbb96280,12.1+18,12.1+7,12.1-1-g14f38d3+72,12.1-1-g16c0db7+5,12.1-1-g5961e7a+84,12.1-1-ge22e12b+23,12.1-11-g06625e2+4,12.1-11-g0d7f63b+4,12.1-19-gd507bfc,12.1-2-g7dda0ab+38,12.1-2-gc0bc6ab+81,12.1-21-g6ffe579+2,12.1-21-gbdb6c2a+4,12.1-24-g941c398+5,12.1-3-g57f6835+7,12.1-3-gf0736f3,12.1-37-g3ddd237,12.1-4-gf46015e+5,12.1-5-g06c326c+20,12.1-5-g648ee80+3,12.1-5-gc2189d7+4,12.1-6-ga608fc0+1,12.1-7-g3349e2a+5,12.1-7-gfd75620+9,12.1-9-g577b946+5,12.1-9-gc4df26a+10
LSSTDataManagementBasePackage
ImageAlgorithm.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
29 #ifndef LSST_AFW_IMAGE_IMAGE_ALGORITHM_H
30 #define LSST_AFW_IMAGE_IMAGE_ALGORITHM_H
31 
32 #include <list>
33 #include <map>
34 #include <string>
35 #include <utility>
36 #include <functional>
37 
38 #include "boost/tr1/functional.hpp"
39 #include "boost/mpl/bool.hpp"
40 #include <memory>
41 
42 #include "lsst/afw/image/lsstGil.h"
44 #include "lsst/daf/base.h"
45 #include "lsst/daf/base/Citizen.h"
46 #include "lsst/pex/exceptions.h"
47 
48 namespace lsst { namespace afw { namespace image {
49 #if !defined(SWIG)
50 
53  template<typename ValT>
54  struct pixelOp0 : public std::tr1::function<ValT ()> {
55  virtual ~pixelOp0() {}
56  virtual ValT operator()() const = 0;
57  };
58 
62  template<typename ValT>
63  struct pixelOp1 : public std::tr1::function<ValT (ValT)> {
64  virtual ~pixelOp1() {}
65  virtual ValT operator()(ValT lhs) const = 0;
66  };
67 
71  template<typename ValT>
72  struct pixelOp1XY : public std::tr1::function<ValT (int, int, ValT)> {
73  virtual ~pixelOp1XY() {}
74  virtual ValT operator()(int x, int y, ValT lhs) const = 0;
75  };
76 
80  template<typename LhsT, typename RhsT>
81  struct pixelOp2 : public std::tr1::function<LhsT (LhsT, RhsT)>
82  {
83  virtual ~pixelOp2() {}
84  virtual LhsT operator()(LhsT lhs, RhsT rhs) const = 0;
85  };
86 
90  template<typename LhsT, typename RhsT>
91  struct pixelOp2XY : public std::tr1::function<LhsT (int, int, LhsT, RhsT)>
92  {
93  virtual ~pixelOp2XY() {}
94  virtual LhsT operator()(int x, int y, LhsT lhs, RhsT rhs) const = 0;
95  };
96 
97  /*******************************************************************************************************/
101  template<typename LhsT>
103  pixelOp0<LhsT> const& func
104  )
105  {
106  for (int y = 0; y != lhs.getHeight(); ++y) {
107  for (typename Image<LhsT>::x_iterator lhsPtr = lhs.row_begin(y), lhsEnd = lhs.row_end(y);
108  lhsPtr != lhsEnd; ++lhsPtr) {
109  *lhsPtr = func();
110  }
111  }
112  }
113 
117  template<typename LhsT>
119  pixelOp1<LhsT> const& func
120  )
121  {
122  for (int y = 0; y != lhs.getHeight(); ++y) {
123  for (typename Image<LhsT>::x_iterator lhsPtr = lhs.row_begin(y), lhsEnd = lhs.row_end(y);
124  lhsPtr != lhsEnd; ++lhsPtr) {
125  *lhsPtr = func(*lhsPtr);
126  }
127  }
128  }
129 
135  template<typename LhsT>
137  pixelOp1XY<LhsT> const& func
138  )
139  {
140  for (int y = 0; y != lhs.getHeight(); ++y) {
141  int x = lhs.getX0();
142  for (typename Image<LhsT>::x_iterator lhsPtr = lhs.row_begin(y), lhsEnd = lhs.row_end(y);
143  lhsPtr != lhsEnd; ++lhsPtr, ++x) {
144  *lhsPtr = func(x, y + lhs.getY0(), *lhsPtr);
145  }
146  }
147  }
148 
152  template<typename LhsT, typename RhsT>
154  Image<RhsT> const& rhs,
155  pixelOp1<RhsT> const& func
156  )
157  {
158  if (lhs.getDimensions() != rhs.getDimensions()) {
159  throw LSST_EXCEPT(lsst::pex::exceptions::LengthError,
160  (boost::format("Images are of different size, %dx%d v %dx%d") %
161  lhs.getWidth() % lhs.getHeight() % rhs.getWidth() % rhs.getHeight()).str());
162  }
163 
164  for (int y = 0; y != lhs.getHeight(); ++y) {
165  typename Image<RhsT>::const_x_iterator rhsPtr = rhs.row_begin(y);
166 
167  for (typename Image<LhsT>::x_iterator lhsPtr = lhs.row_begin(y), lhsEnd = lhs.row_end(y);
168  lhsPtr != lhsEnd; ++rhsPtr, ++lhsPtr) {
169  *lhsPtr = func(*rhsPtr);
170  }
171  }
172  }
173 
177  template<typename LhsT, typename RhsT>
179  Image<RhsT> const& rhs,
180  pixelOp2<LhsT, RhsT> const& func
181  )
182  {
183  if (lhs.getDimensions() != rhs.getDimensions()) {
184  throw LSST_EXCEPT(lsst::pex::exceptions::LengthError,
185  (boost::format("Images are of different size, %dx%d v %dx%d") %
186  lhs.getWidth() % lhs.getHeight() % rhs.getWidth() % rhs.getHeight()).str());
187  }
188 
189  for (int y = 0; y != lhs.getHeight(); ++y) {
190  typename Image<RhsT>::const_x_iterator rhsPtr = rhs.row_begin(y);
191 
192  for (typename Image<LhsT>::x_iterator lhsPtr = lhs.row_begin(y), lhsEnd = lhs.row_end(y);
193  lhsPtr != lhsEnd; ++rhsPtr, ++lhsPtr) {
194  *lhsPtr = func(*lhsPtr, *rhsPtr);
195  }
196  }
197  }
203  template<typename LhsT, typename RhsT>
205  Image<RhsT> const& rhs,
206  pixelOp2XY<LhsT, RhsT> const& func
207  )
208  {
209  if (lhs.getDimensions() != rhs.getDimensions()) {
210  throw LSST_EXCEPT(lsst::pex::exceptions::LengthError,
211  (boost::format("Images are of different size, %dx%d v %dx%d") %
212  lhs.getWidth() % lhs.getHeight() % rhs.getWidth() % rhs.getHeight()).str());
213  }
214 
215  for (int y = 0; y != lhs.getHeight(); ++y) {
216  typename Image<RhsT>::const_x_iterator rhsPtr = rhs.row_begin(y);
217  int x = lhs.getX0();
218  for (typename Image<LhsT>::x_iterator lhsPtr = lhs.row_begin(y), lhsEnd = lhs.row_end(y);
219  lhsPtr != lhsEnd; ++rhsPtr, ++lhsPtr, ++x) {
220  *lhsPtr = func(x, y + lhs.getY0(), *lhsPtr, *rhsPtr);
221  }
222  }
223  }
224 #endif
225 }}} // lsst::afw::image
226 
227 #endif
int y
A functor class equivalent to tr1::function&lt;LhsT (LhsT, RhsT)&gt;, but with a virtual operator() ...
A functor class equivalent to tr1::function&lt;ValT (int, int, ValT)&gt;, but with a virtual operator() ...
virtual LhsT operator()(int x, int y, LhsT lhs, RhsT rhs) const =0
Include files required for standard LSST Exception handling.
_const_view_t::x_iterator const_x_iterator
A const iterator for traversing the pixels in a row.
Definition: Image.h:157
_view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
Definition: Image.h:150
void for_each_pixel(Image< LhsT > &lhs, pixelOp0< LhsT > const &func)
Set each pixel in an Image&lt;LhsT&gt; to func()
int getX0() const
Return the image&#39;s column-origin.
Definition: Image.h:248
Image utility functions.
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
A functor class equivalent to tr1::function&lt;LhsT (int, int, LhsT, RhsT)&gt;, but with a virtual operator...
geom::Extent2I getDimensions() const
Return the image&#39;s size; useful for passing to constructors.
Definition: Image.h:299
x_iterator row_end(int y) const
Return an x_iterator to the end of the y&#39;th row.
Definition: Image.h:325
Types and classes to interface lsst::afw::image to boost::gil.
int getHeight() const
Return the number of rows in the image.
Definition: Image.h:240
double x
A functor class equivalent to tr1::function&lt;ValT ()&gt;, but with a virtual operator() ...
#define LSST_EXCEPT(type,...)
Create an exception with a given type and message and optionally other arguments (dependent on the ty...
Definition: Exception.h:46
A functor class equivalent to tr1::function&lt;ValT (ValT)&gt;, but with a virtual operator() ...
virtual ValT operator()(ValT lhs) const =0
x_iterator row_begin(int y) const
Return an x_iterator to the start of the y&#39;th row.
Definition: Image.h:320
virtual ValT operator()(int x, int y, ValT lhs) const =0
int getWidth() const
Return the number of columns in the image.
Definition: Image.h:238
virtual ValT operator()() const =0
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:416
virtual LhsT operator()(LhsT lhs, RhsT rhs) const =0
int getY0() const
Return the image&#39;s row-origin.
Definition: Image.h:256