LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
rotateImage.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2008, 2009, 2010 LSST Corporation.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <http://www.lsstcorp.org/LegalNotices/>.
21  */
22 
29 
30 namespace afwImage = lsst::afw::image;
31 namespace afwGeom = lsst::afw::geom;
32 
33 namespace lsst {
34 namespace afw {
35 namespace math {
36 
40 template<typename ImageT>
41 typename ImageT::Ptr rotateImageBy90(ImageT const& inImage,
42  int nQuarter
43  ) {
44  typename ImageT::Ptr outImage; // output image
45 
46  while (nQuarter < 0) {
47  nQuarter += 4;
48  }
49 
50  switch (nQuarter%4) {
51  case 0:
52  outImage.reset(new ImageT(inImage, true)); // a deep copy of inImage
53  break;
54  case 1:
55  outImage.reset(new ImageT(afwGeom::Extent2I(inImage.getHeight(), inImage.getWidth())));
56 
57  for (int y = 0; y != inImage.getHeight(); ++y) {
58  typename ImageT::y_iterator optr = outImage->col_begin(inImage.getHeight() - y - 1);
59  for (typename ImageT::x_iterator iptr = inImage.row_begin(y), end = inImage.row_end(y);
60  iptr != end; ++iptr, ++optr) {
61  *optr = *iptr;
62  }
63  }
64 
65  break;
66  case 2:
67  outImage.reset(new ImageT(inImage.getDimensions()));
68 
69  for (int y = 0; y != inImage.getHeight(); ++y) {
70  typename ImageT::x_iterator optr = outImage->x_at(inImage.getWidth() - 1,
71  inImage.getHeight() - y - 1);
72  for (typename ImageT::x_iterator iptr = inImage.row_begin(y), end = inImage.row_end(y);
73  iptr != end; ++iptr, optr -= 1) {
74  *optr = *iptr;
75  }
76  }
77  break;
78  case 3:
79  outImage.reset(new ImageT(afwGeom::Extent2I(inImage.getHeight(), inImage.getWidth())));
80 
81  for (int y = 0; y != inImage.getHeight(); ++y) {
82  typename ImageT::y_iterator optr = outImage->y_at(y, inImage.getWidth() - 1);
83  for (typename ImageT::x_iterator iptr = inImage.row_begin(y), end = inImage.row_end(y);
84  iptr != end; ++iptr, optr -= 1) {
85  *optr = *iptr;
86  }
87  }
88 
89  break;
90  }
91 
92  return outImage;
93 }
94 
98 template<typename ImageT>
99 PTR(ImageT) flipImage(ImageT const& inImage,
100  bool flipLR,
101  bool flipTB
102  ) {
103  typename ImageT::Ptr outImage(new ImageT(inImage, true)); // Output image
104 
105  if (flipLR) {
106  if (flipTB) {
107  for (int y = 0; y != inImage.getHeight(); ++y) {
108  typename ImageT::x_iterator optr = outImage->x_at(inImage.getWidth() - 1,
109  inImage.getHeight() - y - 1);
110  for (typename ImageT::x_iterator iptr = inImage.row_begin(y), end = inImage.row_end(y);
111  iptr != end; ++iptr, optr -= 1) {
112  *optr = *iptr;
113  }
114  }
115  } else {
116  for (int y = 0; y != inImage.getHeight(); ++y) {
117  typename ImageT::x_iterator optr = outImage->x_at(inImage.getWidth() - 1, y);
118  for (typename ImageT::x_iterator iptr = inImage.row_begin(y), end = inImage.row_end(y);
119  iptr != end; ++iptr, optr -= 1) {
120  *optr = *iptr;
121  }
122  }
123  }
124  } else {
125  if (flipTB) {
126  for (int y = 0; y != inImage.getHeight(); ++y) {
127  typename ImageT::x_iterator optr = outImage->row_begin(inImage.getHeight() - y - 1);
128  for (typename ImageT::x_iterator iptr = inImage.row_begin(y), end = inImage.row_end(y);
129  iptr != end; ++iptr, ++optr) {
130  *optr = *iptr;
131  }
132  }
133  } else {
134  ; // nothing to do
135  }
136  }
137 
138  return outImage;
139 }
140 
141 /************************************************************************************************************/
142 //
143 // Explicit instantiations
144 //
146 #define INSTANTIATE(TYPE) \
147  template afwImage::Image<TYPE>::Ptr rotateImageBy90(afwImage::Image<TYPE> const&, int); \
148  template afwImage::MaskedImage<TYPE>::Ptr rotateImageBy90(afwImage::MaskedImage<TYPE> const&, int); \
149  template afwImage::Image<TYPE>::Ptr flipImage(afwImage::Image<TYPE> const&, bool flipLR, bool flipTB); \
150  template afwImage::MaskedImage<TYPE>::Ptr flipImage(afwImage::MaskedImage<TYPE> const&, bool flipLR, bool flipTB);
151 
152 
153 INSTANTIATE(boost::uint16_t)
154 INSTANTIATE(int)
155 INSTANTIATE(float)
156 INSTANTIATE(double)
157 template afwImage::Mask<boost::uint16_t>::Ptr rotateImageBy90(afwImage::Mask<boost::uint16_t> const&, int);
158 template afwImage::Mask<boost::uint16_t>::Ptr flipImage(afwImage::Mask<boost::uint16_t> const&, bool flipLR, bool flipTB);
160 
161 }}}
int y
boost::shared_ptr< ImageT > flipImage(ImageT const &inImage, bool flipLR, bool flipTB)
Definition: rotateImage.cc:99
#define INSTANTIATE(MATCH)
#define PTR(...)
Definition: base.h:41
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
ImageT::Ptr rotateImageBy90(ImageT const &image, int nQuarter)
Definition: rotateImage.cc:41