LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
isr.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 
42 #ifndef LSST_IP_ISR_ISR_H
43 #define LSST_IP_ISR_ISR_H
44 
45 #include <string>
46 #include <vector>
47 
48 #include <boost/shared_ptr.hpp>
49 
50 #include <lsst/afw/math.h>
52 #include <lsst/afw/image.h>
53 #include <lsst/utils/ieee.h>
55 
60 namespace lsst {
61 namespace ip {
62 namespace isr {
63 
71  std::string const& ISR_LIN = "ISR_LIN";
72  std::string const& ISR_OSCAN = "ISR_OSCAN";
73  std::string const& ISR_TRIM = "ISR_TRIM";
74  std::string const& ISR_BIAS = "ISR_BIAS";
75  std::string const& ISR_DFLAT = "ISR_DFLAT";
76  std::string const& ISR_ILLUM = "ISR_ILLUM";
77  std::string const& ISR_BADP = "ISR_BADP";
78  std::string const& ISR_SAT = "ISR_SAT";
79  std::string const& ISR_FRING = "ISR_FRING";
80  std::string const& ISR_DARK = "ISR_DARK";
81  std::string const& ISR_PUPIL = "ISR_PUPIL";
82  std::string const& ISR_CRREJ = "ISR_CRREJ";
83  std::string const& ISR_BACKSUB = "ISR_BACKSUB";
84 
85  enum StageId {
86  ISR_LINid = 0x1,
87  ISR_OSCANid = 0x2,
88  ISR_TRIMid = 0x4,
89  ISR_BIASid = 0x8,
90  ISR_DFLATid = 0x10,
91  ISR_ILLUMid = 0x20,
92  ISR_BADPid = 0x40,
93  ISR_SATid = 0x80,
94  ISR_FRINid = 0x100,
95  ISR_DARKid = 0x200,
96  ISR_PUPILid = 0x400,
97  ISR_CRREJid = 0x800,
98  ISR_BACKSUBid = 0x1000,
99  };
100 
105  template <typename ImageT>
107  public:
110 
111  LookupTableMultiplicative(std::vector<double> table) :
112  _table(table), _max(table.size()) {};
114 
116 
117  for (int y = 0; y != image.getHeight(); ++y) {
118  for (x_iterator ptr = image.row_begin(y), end = image.row_end(y); ptr != end; ++ptr) {
119  int ind = static_cast<int>(ptr.image() + 0.5); // Rounded pixel value
120  if (ind >= _max){
122  "Pixel value out of range in LookupTableMultiplicative::apply");
123  }
124  PixelT p = PixelT((*ptr).image() * _table[ind],
125  (*ptr).mask(),
126  (*ptr).variance() * _table[ind] * _table[ind]);
127  *ptr = p;
128  }
129  }
130  }
131 
132  // Return the lookup table
133  std::vector<double> getTable() const { return _table; }
134  private:
135  std::vector<double> _table;
136  int _max;
137  };
138 
143  template <typename ImageT>
145  public:
148 
149  LookupTableReplace(std::vector<double> table) :
150  _table(table), _max(table.size()) {};
151  virtual ~LookupTableReplace() {};
152 
153  void apply(lsst::afw::image::MaskedImage<ImageT> &image, float gain=1.0) const;
154 
155  // Return the lookup table
156  std::vector<double> getTable() const { return _table; }
157  private:
158  std::vector<double> _table;
159  int _max;
160  };
161 
162  template <typename ImageT, typename MaskT=lsst::afw::image::MaskPixel>
164  public:
167  _count(0) {} ;
168  virtual ~CountMaskedPixels() {};
169 
170  // Clear the accumulator
171  void reset() { _count = 0; }
172 
173  // Count pixels
175  MaskT bitmask) {
176  reset();
177  for (int y = 0; y != image.getHeight(); ++y) {
178  for (x_iterator ptr = image.row_begin(y); ptr != image.row_end(y); ++ptr) {
179  if ( ((*ptr).mask() & bitmask) == bitmask ) {
180  _count += 1;
181  }
182  }
183  }
184  }
185 
186  // Return the total counts
187  int getCount() const { return _count; }
188 
189  private:
190  int _count;
191  };
192 
199  template <typename PixelT>
200  size_t maskNans(
202  afw::image::MaskPixel maskVal,
203  afw::image::MaskPixel allow=0
204  );
205 
206 
207  template<typename ImagePixelT, typename FunctionT>
208  void fitOverscanImage(
209  boost::shared_ptr<lsst::afw::math::Function1<FunctionT> > &overscanFunction,
211  double ssize=1.,
212  int sigma=1
213  );
214 
215 
216 }}} // namespace lsst::ip::isr
217 
218 #endif // !defined(LSST_IP_ISR_ISR_H)
int y
An include file to include the public header files for lsst::afw::math.
Linearization.
Definition: isr.h:86
boost::uint16_t MaskPixel
std::vector< double > _table
Definition: isr.h:158
std::string const & ISR_BADP
Bad pixel mask.
Definition: isr.h:77
std::vector< double > getTable() const
Definition: isr.h:156
void fitOverscanImage(boost::shared_ptr< lsst::afw::math::Function1< FunctionT > > &overscanFunction, lsst::afw::image::MaskedImage< ImagePixelT > const &overscan, double ssize=1., int sigma=1)
std::string const & ISR_FRING
Fringe correction.
Definition: isr.h:79
lsst::afw::image::MaskedImage< ImageT >::x_iterator x_iterator
Definition: isr.h:108
void apply(lsst::afw::image::MaskedImage< ImageT > &image, float gain=1.0) const
Definition: Isr.cc:35
void apply(lsst::afw::image::MaskedImage< ImageT > const &image, MaskT bitmask)
Definition: isr.h:174
x_iterator row_end(int y) const
Return an x_iterator to the end of the image.
Definition: MaskedImage.cc:752
lsst::afw::image::MaskedImage< ImageT >::x_iterator x_iterator
Definition: isr.h:165
std::string const & ISR_PUPIL
Pupil correction.
Definition: isr.h:81
Cosmic ray rejection.
Definition: isr.h:97
afw::table::Key< double > sigma
Definition: GaussianPsf.cc:43
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
An iterator to the MaskedImage.
Definition: MaskedImage.h:109
An include file to include the header files for lsst::afw::image.
std::vector< double > getTable() const
Definition: isr.h:133
std::string const & ISR_ILLUM
Illumination correction.
Definition: isr.h:76
Saturated pixels.
Definition: isr.h:93
LookupTableMultiplicative(std::vector< double > table)
Definition: isr.h:111
std::string const & ISR_SAT
Saturated pixels.
Definition: isr.h:78
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:77
std::string const & ISR_OSCAN
Overscan.
Definition: isr.h:72
A Function taking one argument.
Definition: Function.h:229
Illumination correction.
Definition: isr.h:91
Dome flat.
Definition: isr.h:90
std::string const & ISR_TRIM
Trim.
Definition: isr.h:73
Bad pixel mask.
Definition: isr.h:92
std::string const & ISR_BIAS
Bias.
Definition: isr.h:74
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
A pixel of a MaskedImage.
Definition: Pixel.h:137
lsst::afw::image::MaskedImage< ImageT >::Pixel PixelT
Definition: isr.h:147
Cosmic ray rejection.
Definition: isr.h:98
std::vector< double > _table
Definition: isr.h:135
std::string const & ISR_LIN
Linearization.
Definition: isr.h:71
Fringe correction.
Definition: isr.h:94
Pupil correction.
Definition: isr.h:96
std::string const & ISR_DARK
Dark correction.
Definition: isr.h:80
Compute Image Statistics.
std::string const & ISR_CRREJ
Cosmic ray rejection.
Definition: isr.h:82
x_iterator row_begin(int y) const
Return an x_iterator to the start of the image.
Definition: MaskedImage.cc:742
lsst::afw::image::MaskedImage< ImageT >::x_iterator x_iterator
Definition: isr.h:146
size_t maskNans(afw::image::MaskedImage< PixelT > const &mi, afw::image::MaskPixel maskVal, afw::image::MaskPixel allow=0)
Definition: Isr.cc:61
void apply(lsst::afw::image::MaskedImage< ImageT > &image, float gain=1.0)
Definition: isr.h:115
lsst::afw::image::MaskedImage< ImageT >::Pixel PixelT
Definition: isr.h:109
LookupTableReplace(std::vector< double > table)
Definition: isr.h:149
int getHeight() const
Return the number of rows in the image.
Definition: MaskedImage.h:903
Dark correction.
Definition: isr.h:95
std::string const & ISR_BACKSUB
Background subtraction.
Definition: isr.h:83
std::string const & ISR_DFLAT
Dome flat.
Definition: isr.h:75