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
ImageSlice.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 
25 #if !defined(LSST_AFW_IMAGE_SLICE_H)
26 #define LSST_AFW_IMAGE_SLICE_H
27 
39 #include "lsst/afw/image/Image.h"
40 
41 namespace lsst {
42 namespace afw {
43 namespace image {
44 
45 
46 
53 template<typename PixelT>
54 class ImageSlice : public Image<PixelT> {
55 public:
57 
58  explicit ImageSlice(Image<PixelT> const &img);
61 
62 private:
64 };
65 
66 
67 
68 namespace details {
69 
70 /*
71  * These structs allow the operate() function to be templated over operation.
72  * The operate() function handles the loop over pixels and the chosen operator will be used.
73  * The templates allow the compiler to do this efficiently.
74  *
75  */
76 
77 template<typename PixelT>
78 struct Plus { PixelT operator()(PixelT const imgPix, PixelT const slcPix) { return imgPix + slcPix; } };
79 template<typename PixelT>
80 struct Minus { PixelT operator()(PixelT const imgPix, PixelT const slcPix) { return imgPix - slcPix; } };
81 template<typename PixelT>
82 struct Mult { PixelT operator()(PixelT const imgPix, PixelT const slcPix) { return imgPix * slcPix; } };
83 template<typename PixelT>
84 struct Div { PixelT operator()(PixelT const imgPix, PixelT const slcPix) { return imgPix / slcPix; } };
85 
86 
91 template<typename OperatorT, typename PixelT>
93  typename ImageSlice<PixelT>::ImageSliceType sliceType) {
94 
95  OperatorT op;
96 
97  if (sliceType == ImageSlice<PixelT>::ROW) {
98  for (int y = 0; y < img.getHeight(); ++y) {
99  typename ImageSlice<PixelT>::x_iterator pSlc = slc.row_begin(0);
100  for (typename Image<PixelT>::x_iterator pImg = img.row_begin(y), end = img.row_end(y);
101  pImg != end; ++pImg, ++pSlc) {
102  *pImg = op(*pImg, *pSlc);
103  }
104  }
105  } else if (sliceType == ImageSlice<PixelT>::COLUMN) {
106 
107  typename ImageSlice<PixelT>::y_iterator pSlc = slc.col_begin(0);
108  for (int y = 0; y < img.getHeight(); ++y, ++pSlc) {
109  for (typename Image<PixelT>::x_iterator pImg = img.row_begin(y), end = img.row_end(y);
110  pImg != end; ++pImg) {
111  *pImg = op(*pImg, *pSlc);
112  }
113  }
114  }
115 
116 }
117 }
118 
119 
120 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
121 // overload +
122 template<typename PixelT>
123 typename Image<PixelT>::Ptr operator+(Image<PixelT> const &img, ImageSlice<PixelT> const &slc);
124 
125 template<typename PixelT>
126 typename Image<PixelT>::Ptr operator+(ImageSlice<PixelT> const &slc, Image<PixelT> const &img);
127 
128 template<typename PixelT>
129 void operator+=(Image<PixelT> &img, ImageSlice<PixelT> const &slc);
130 
131 
132 // -----------------------------------------------------------------
133 // overload -
134 template<typename PixelT>
135 typename Image<PixelT>::Ptr operator-(Image<PixelT> const &img, ImageSlice<PixelT> const &slc);
136 
137 template<typename PixelT>
138 void operator-=(Image<PixelT> &img, ImageSlice<PixelT> const &slc);
139 
140 
141 // ******************************************************************
142 // overload *
143 template<typename PixelT>
144 typename Image<PixelT>::Ptr operator*(Image<PixelT> const &img, ImageSlice<PixelT> const &slc);
145 
146 template<typename PixelT>
147 typename Image<PixelT>::Ptr operator*(ImageSlice<PixelT> const &slc, Image<PixelT> const &img);
148 
149 template<typename PixelT>
150 void operator*=(Image<PixelT> &img, ImageSlice<PixelT> const &slc);
151 
152 
153 // ///////////////////////////////////////////////////////////////////
154 // overload /
155 template<typename PixelT>
156 typename Image<PixelT>::Ptr operator/(Image<PixelT> const &img, ImageSlice<PixelT> const &slc);
157 
158 template<typename PixelT>
159 void operator/=(Image<PixelT> &img, ImageSlice<PixelT> const &slc);
160 
161 
162 }}}
163 
164 #endif
int y
ImageSlice(Image< PixelT > const &img)
Constructor for ImageSlice.
Definition: ImageSlice.cc:46
_view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
Definition: Image.h:151
ImageSliceType getImageSliceType() const
Definition: ImageSlice.h:60
void operator*=(Image< LhsPixelT > &lhs, Image< RhsPixelT > const &rhs)
Definition: Image.cc:861
PixelT operator()(PixelT const imgPix, PixelT const slcPix)
Definition: ImageSlice.h:82
ImageSliceType _sliceType
Definition: ImageSlice.h:63
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
x_iterator row_end(int y) const
Return an x_iterator to the end of the y&#39;th row.
Definition: Image.h:324
void operate(Image< PixelT > &img, ImageSlice< PixelT > const &slc, typename ImageSlice< PixelT >::ImageSliceType sliceType)
A function to loop over pixels and perform the requested operation.
Definition: ImageSlice.h:92
_view_t::y_iterator y_iterator
An iterator for traversing the pixels in a column.
Definition: Image.h:160
Image< PixelT >::Ptr operator/(Image< PixelT > const &img, ImageSlice< PixelT > const &slc)
Support for 2-D images.
int getHeight() const
Return the number of rows in the image.
Definition: Image.h:239
PixelT operator()(PixelT const imgPix, PixelT const slcPix)
Definition: ImageSlice.h:78
Image< PixelT >::Ptr operator-(Image< PixelT > const &img, ImageSlice< PixelT > const &slc)
y_iterator col_begin(int x) const
Definition: Image.h:334
PixelT operator()(PixelT const imgPix, PixelT const slcPix)
Definition: ImageSlice.h:80
void operator/=(Image< LhsPixelT > &lhs, Image< RhsPixelT > const &rhs)
Definition: Image.cc:868
void operator-=(Image< LhsPixelT > &lhs, Image< RhsPixelT > const &rhs)
Definition: Image.cc:854
x_iterator row_begin(int y) const
Definition: Image.h:319
Image< PixelT >::Ptr operator+(Image< PixelT > const &img, ImageSlice< PixelT > const &slc)
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:415
PixelT operator()(PixelT const imgPix, PixelT const slcPix)
Definition: ImageSlice.h:84
Image< PixelT >::Ptr operator*(Image< PixelT > const &img, ImageSlice< PixelT > const &slc)
A class to specify a slice of an image.
Definition: ImageSlice.h:54
void operator+=(Image< LhsPixelT > &lhs, Image< RhsPixelT > const &rhs)
Definition: Image.cc:847