LSSTApplications  18.0.0+106,18.0.0+50,19.0.0,19.0.0+1,19.0.0+10,19.0.0+11,19.0.0+13,19.0.0+17,19.0.0+2,19.0.0-1-g20d9b18+6,19.0.0-1-g425ff20,19.0.0-1-g5549ca4,19.0.0-1-g580fafe+6,19.0.0-1-g6fe20d0+1,19.0.0-1-g7011481+9,19.0.0-1-g8c57eb9+6,19.0.0-1-gb5175dc+11,19.0.0-1-gdc0e4a7+9,19.0.0-1-ge272bc4+6,19.0.0-1-ge3aa853,19.0.0-10-g448f008b,19.0.0-12-g6990b2c,19.0.0-2-g0d9f9cd+11,19.0.0-2-g3d9e4fb2+11,19.0.0-2-g5037de4,19.0.0-2-gb96a1c4+3,19.0.0-2-gd955cfd+15,19.0.0-3-g2d13df8,19.0.0-3-g6f3c7dc,19.0.0-4-g725f80e+11,19.0.0-4-ga671dab3b+1,19.0.0-4-gad373c5+3,19.0.0-5-ga2acb9c+2,19.0.0-5-gfe96e6c+2,w.2020.01
LSSTDataManagementBasePackage
MaskedImage.cc
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008-2016 AURA/LSST.
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 /*
26  * Implementation for MaskedImage
27  */
28 #include <cstdint>
29 #include <typeinfo>
30 #include <sys/stat.h>
31 #pragma clang diagnostic push
32 #pragma clang diagnostic ignored "-Wunused-variable"
33 #pragma clang diagnostic pop
34 #include "boost/regex.hpp"
35 #include "boost/filesystem/path.hpp"
36 #include "lsst/log/Log.h"
37 #include "lsst/pex/exceptions.h"
38 
40 #include "lsst/afw/fits.h"
42 
43 namespace lsst {
44 namespace afw {
45 namespace image {
46 
47 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
49  MaskPlaneDict const& planeDict)
50  : _image(new Image(width, height)),
51  _mask(new Mask(width, height, planeDict)),
52  _variance(new Variance(width, height)) {
53  *_image = 0;
54  *_mask = 0x0;
55  *_variance = 0;
56 }
57 
58 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
60  MaskPlaneDict const& planeDict)
61  : _image(new Image(dimensions)),
62  _mask(new Mask(dimensions, planeDict)),
63  _variance(new Variance(dimensions)) {
64  *_image = 0;
65  *_mask = 0x0;
66  *_variance = 0;
67 }
68 
69 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
71  MaskPlaneDict const& planeDict)
72  : _image(new Image(bbox)), _mask(new Mask(bbox, planeDict)), _variance(new Variance(bbox)) {
73  *_image = 0;
74  *_mask = 0x0;
75  *_variance = 0;
76 }
77 
78 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
80  std::string const& fileName, std::shared_ptr<daf::base::PropertySet> metadata,
81  lsst::geom::Box2I const& bbox, ImageOrigin origin, bool conformMasks, bool needAllHdus,
84  std::shared_ptr<daf::base::PropertySet> varianceMetadata, bool allowUnsafe)
85  : _image(), _mask(), _variance() {
86  MaskedImageFitsReader reader(fileName);
87  *this = reader.read<ImagePixelT, MaskPixelT, VariancePixelT>(bbox, origin, conformMasks, needAllHdus,
88  allowUnsafe);
89  if (metadata) {
90  metadata->combine(reader.readPrimaryMetadata());
91  }
92  if (imageMetadata) {
93  imageMetadata->combine(reader.readImageMetadata());
94  }
95  if (maskMetadata) {
96  maskMetadata->combine(reader.readMaskMetadata());
97  }
98  if (varianceMetadata) {
99  varianceMetadata->combine(reader.readVarianceMetadata());
100  }
101 }
102 
103 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
106  lsst::geom::Box2I const& bbox, ImageOrigin origin, bool conformMasks, bool needAllHdus,
109  std::shared_ptr<daf::base::PropertySet> varianceMetadata, bool allowUnsafe)
110  : _image(), _mask(), _variance() {
111  MaskedImageFitsReader reader(manager);
112  *this = reader.read<ImagePixelT, MaskPixelT, VariancePixelT>(bbox, origin, conformMasks, needAllHdus,
113  allowUnsafe);
114  if (metadata) {
115  metadata->combine(reader.readPrimaryMetadata());
116  }
117  if (imageMetadata) {
118  imageMetadata->combine(reader.readImageMetadata());
119  }
120  if (maskMetadata) {
121  maskMetadata->combine(reader.readMaskMetadata());
122  }
123  if (varianceMetadata) {
124  varianceMetadata->combine(reader.readVarianceMetadata());
125  }
126 }
127 
128 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
131  ImageOrigin origin, bool conformMasks, bool needAllHdus,
134  std::shared_ptr<daf::base::PropertySet> varianceMetadata, bool allowUnsafe)
135  : _image(), _mask(), _variance() {
136  MaskedImageFitsReader reader(&fitsFile);
137  *this = reader.read<ImagePixelT, MaskPixelT, VariancePixelT>(bbox, origin, conformMasks, needAllHdus,
138  allowUnsafe);
139  if (metadata) {
140  metadata->combine(reader.readPrimaryMetadata());
141  }
142  if (imageMetadata) {
143  imageMetadata->combine(reader.readImageMetadata());
144  }
145  if (maskMetadata) {
146  maskMetadata->combine(reader.readMaskMetadata());
147  }
148  if (varianceMetadata) {
149  varianceMetadata->combine(reader.readVarianceMetadata());
150  }
151 }
152 
153 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
156  : _image(image), _mask(mask), _variance(variance) {
157  conformSizes();
158 }
159 
160 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
162  : _image(rhs._image), _mask(rhs._mask), _variance(rhs._variance) {
163  if (deep) {
164  _image = std::shared_ptr<Image>(new Image(*rhs.getImage(), deep));
165  _mask = std::shared_ptr<Mask>(new Mask(*rhs.getMask(), deep));
166  _variance = std::shared_ptr<Variance>(new Variance(*rhs.getVariance(), deep));
167  }
168  conformSizes();
169 }
170 
171 // Delegate to copy-constructor for backwards compatibility
172 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
174  : MaskedImage(rhs, false) {}
175 
176 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
178  const lsst::geom::Box2I& bbox,
179  ImageOrigin const origin, bool deep
180 
181  )
182  : _image(new Image(*rhs.getImage(), bbox, origin, deep)),
183  _mask(rhs._mask ? new Mask(*rhs.getMask(), bbox, origin, deep) : static_cast<Mask*>(NULL)),
184  _variance(rhs._variance ? new Variance(*rhs.getVariance(), bbox, origin, deep)
185  : static_cast<Variance*>(NULL)) {
186  conformSizes();
187 }
188 
189 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
191 operator=(MaskedImage const& rhs) = default;
192 
193 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
195 operator=(MaskedImage&& rhs) = default;
196 
197 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
199  using std::swap; // See Meyers, Effective C++, Item 25
200 
201  _image.swap(rhs._image);
202  _mask.swap(rhs._mask);
203  _variance.swap(rhs._variance);
204 }
205 
206 // Operators
207 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
210  *_image = rhs.image();
211  *_mask = rhs.mask();
212  *_variance = rhs.variance();
213 
214  return *this;
215 }
216 
217 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
220  *_image = rhs.image();
221  *_mask = rhs.mask();
222  *_variance = rhs.variance();
223 
224  return *this;
225 }
226 
227 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
230  assign(rhs);
231  return *this;
232 }
233 
234 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
236  lsst::geom::Box2I const& bbox,
237  ImageOrigin origin) {
238  _image->assign(*rhs.getImage(), bbox, origin);
239  _mask->assign(*rhs.getMask(), bbox, origin);
240  _variance->assign(*rhs.getVariance(), bbox, origin);
241 }
242 
243 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
245 operator+=(MaskedImage const& rhs) {
246  *_image += *rhs.getImage();
247  *_mask |= *rhs.getMask();
248  *_variance += *rhs.getVariance();
249  return *this;
250 }
251 
252 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
254  MaskedImage const& rhs) {
255  (*_image).scaledPlus(c, *rhs.getImage());
256  *_mask |= *rhs.getMask();
257  (*_variance).scaledPlus(c * c, *rhs.getVariance());
258 }
259 
260 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
262 operator+=(ImagePixelT const rhs) {
263  *_image += rhs;
264  return *this;
265 }
266 
267 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
269 operator-=(MaskedImage const& rhs) {
270  *_image -= *rhs.getImage();
271  *_mask |= *rhs.getMask();
272  *_variance += *rhs.getVariance();
273  return *this;
274 }
275 
276 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
278  MaskedImage const& rhs) {
279  (*_image).scaledMinus(c, *rhs.getImage());
280  *_mask |= *rhs.getMask();
281  (*_variance).scaledPlus(c * c, *rhs.getVariance());
282 }
283 
284 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
286 operator-=(ImagePixelT const rhs) {
287  *_image -= rhs;
288  return *this;
289 }
290 
291 namespace {
293 template <typename ImagePixelT, typename VariancePixelT>
294 struct productVariance {
295  double operator()(ImagePixelT lhs, ImagePixelT rhs, VariancePixelT varLhs, VariancePixelT varRhs) {
296  return lhs * lhs * varRhs + rhs * rhs * varLhs;
297  }
298 };
299 
302 template <typename ImagePixelT, typename VariancePixelT>
303 struct scaledProductVariance {
304  double _c;
305  scaledProductVariance(double const c) : _c(c) {}
306  double operator()(ImagePixelT lhs, ImagePixelT rhs, VariancePixelT varLhs, VariancePixelT varRhs) {
307  return _c * _c * (lhs * lhs * varRhs + rhs * rhs * varLhs);
308  }
309 };
310 } // namespace
311 
312 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
313 MaskedImage<ImagePixelT, MaskPixelT, VariancePixelT>& MaskedImage<ImagePixelT, MaskPixelT, VariancePixelT>::
314 operator*=(MaskedImage const& rhs) {
315  // Must do variance before we modify the image values
316  transform_pixels(_image->_getRawView(), // lhs
317  rhs._image->_getRawView(), // rhs,
318  _variance->_getRawView(), // Var(lhs),
319  rhs._variance->_getRawView(), // Var(rhs)
320  _variance->_getRawView(), // result
321  productVariance<ImagePixelT, VariancePixelT>());
322 
323  *_image *= *rhs.getImage();
324  *_mask |= *rhs.getMask();
325  return *this;
326 }
327 
328 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
330  MaskedImage const& rhs) {
331  // Must do variance before we modify the image values
332  transform_pixels(_image->_getRawView(), // lhs
333  rhs._image->_getRawView(), // rhs,
334  _variance->_getRawView(), // Var(lhs),
335  rhs._variance->_getRawView(), // Var(rhs)
336  _variance->_getRawView(), // result
337  scaledProductVariance<ImagePixelT, VariancePixelT>(c));
338 
339  (*_image).scaledMultiplies(c, *rhs.getImage());
340  *_mask |= *rhs.getMask();
341 }
342 
343 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
345 operator*=(ImagePixelT const rhs) {
346  *_image *= rhs;
347  *_variance *= rhs * rhs;
348  return *this;
349 }
350 
351 namespace {
353 template <typename ImagePixelT, typename VariancePixelT>
354 struct quotientVariance {
355  double operator()(ImagePixelT lhs, ImagePixelT rhs, VariancePixelT varLhs, VariancePixelT varRhs) {
356  ImagePixelT const rhs2 = rhs * rhs;
357  return (lhs * lhs * varRhs + rhs2 * varLhs) / (rhs2 * rhs2);
358  }
359 };
362 template <typename ImagePixelT, typename VariancePixelT>
363 struct scaledQuotientVariance {
364  double _c;
365  scaledQuotientVariance(double c) : _c(c) {}
366  double operator()(ImagePixelT lhs, ImagePixelT rhs, VariancePixelT varLhs, VariancePixelT varRhs) {
367  ImagePixelT const rhs2 = rhs * rhs;
368  return (lhs * lhs * varRhs + rhs2 * varLhs) / (_c * _c * rhs2 * rhs2);
369  }
370 };
371 } // namespace
372 
373 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
375 operator/=(MaskedImage const& rhs) {
376  // Must do variance before we modify the image values
377  transform_pixels(_image->_getRawView(), // lhs
378  rhs._image->_getRawView(), // rhs,
379  _variance->_getRawView(), // Var(lhs),
380  rhs._variance->_getRawView(), // Var(rhs)
381  _variance->_getRawView(), // result
382  quotientVariance<ImagePixelT, VariancePixelT>());
383 
384  *_image /= *rhs.getImage();
385  *_mask |= *rhs.getMask();
386  return *this;
387 }
388 
389 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
391  MaskedImage const& rhs) {
392  // Must do variance before we modify the image values
393  transform_pixels(_image->_getRawView(), // lhs
394  rhs._image->_getRawView(), // rhs,
395  _variance->_getRawView(), // Var(lhs),
396  rhs._variance->_getRawView(), // Var(rhs)
397  _variance->_getRawView(), // result
398  scaledQuotientVariance<ImagePixelT, VariancePixelT>(c));
399 
400  (*_image).scaledDivides(c, *rhs.getImage());
401  *_mask |= *rhs._mask;
402 }
403 
404 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
406 operator/=(ImagePixelT const rhs) {
407  *_image /= rhs;
408  *_variance /= rhs * rhs;
409  return *this;
410 }
411 
412 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
417  std::shared_ptr<daf::base::PropertySet const> varianceMetadata) const {
418  fits::Fits fitsfile(fileName, "w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
419  writeFits(fitsfile, metadata, imageMetadata, maskMetadata, varianceMetadata);
420 }
421 
422 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
427  std::shared_ptr<daf::base::PropertySet const> varianceMetadata) const {
428  fits::Fits fitsfile(manager, "w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
429  writeFits(fitsfile, metadata, imageMetadata, maskMetadata, varianceMetadata);
430 }
431 
432 namespace {
433 
434 void processPlaneMetadata(std::shared_ptr<daf::base::PropertySet const> metadata,
435  std::shared_ptr<daf::base::PropertySet>& hdr, char const* exttype) {
436  if (metadata) {
437  hdr = metadata->deepCopy();
438  } else {
439  hdr.reset(new daf::base::PropertyList());
440  }
441  hdr->set("INHERIT", true);
442  hdr->set("EXTTYPE", exttype);
443 }
444 
445 } // namespace
446 
447 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
452  std::shared_ptr<daf::base::PropertySet const> varianceMetadata) const {
453  writeFits(fitsfile, fits::ImageWriteOptions(*_image), fits::ImageWriteOptions(*_mask),
454  fits::ImageWriteOptions(*_variance), metadata, imageMetadata, maskMetadata, varianceMetadata);
455 }
456 
457 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
459  std::string const& fileName, fits::ImageWriteOptions const& imageOptions,
460  fits::ImageWriteOptions const& maskOptions, fits::ImageWriteOptions const& varianceOptions,
464  std::shared_ptr<daf::base::PropertySet const> varianceMetadata) const {
465  fits::Fits fitsfile(fileName, "w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
466  writeFits(fitsfile, imageOptions, maskOptions, varianceOptions, metadata, imageMetadata, maskMetadata,
467  varianceMetadata);
468 }
469 
470 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
472  fits::MemFileManager& manager, fits::ImageWriteOptions const& imageOptions,
473  fits::ImageWriteOptions const& maskOptions, fits::ImageWriteOptions const& varianceOptions,
477  std::shared_ptr<daf::base::PropertySet const> varianceMetadata) const {
478  fits::Fits fitsfile(manager, "w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
479  writeFits(fitsfile, imageOptions, maskOptions, varianceOptions, metadata, imageMetadata, maskMetadata,
480  varianceMetadata);
481 }
482 
483 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
485  fits::Fits& fitsfile, fits::ImageWriteOptions const& imageOptions,
486  fits::ImageWriteOptions const& maskOptions, fits::ImageWriteOptions const& varianceOptions,
490  std::shared_ptr<daf::base::PropertySet const> varianceMetadata) const {
492  if (metadata) {
493  header = metadata->deepCopy();
494  } else {
495  header = std::make_shared<daf::base::PropertyList>();
496  }
497 
498  if (fitsfile.countHdus() != 0) {
500  "MaskedImage::writeFits can only write to an empty file");
501  }
502  if (fitsfile.getHdu() < 1) {
503  // Don't ever write images to primary; instead we make an empty primary.
504  fitsfile.createEmpty();
505  } else {
506  fitsfile.setHdu(0);
507  }
508  fitsfile.writeMetadata(*header);
509 
510  processPlaneMetadata(imageMetadata, header, "IMAGE");
511  _image->writeFits(fitsfile, imageOptions, header, _mask);
512 
513  processPlaneMetadata(maskMetadata, header, "MASK");
514  _mask->writeFits(fitsfile, maskOptions, header);
515 
516  processPlaneMetadata(varianceMetadata, header, "VARIANCE");
517  _variance->writeFits(fitsfile, varianceOptions, header, _mask);
518 }
519 
520 // private function conformSizes() ensures that the Mask and Variance have the same dimensions
521 // as Image. If Mask and/or Variance have non-zero dimensions that conflict with the size of Image,
522 // a lsst::pex::exceptions::LengthError is thrown.
523 
524 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
526  if (!_mask || _mask->getWidth() == 0 || _mask->getHeight() == 0) {
527  _mask = MaskPtr(new Mask(_image->getBBox()));
528  *_mask = 0;
529  } else {
530  if (_mask->getDimensions() != _image->getDimensions()) {
531  throw LSST_EXCEPT(
533  (boost::format("Dimension mismatch: Image %dx%d v. Mask %dx%d") % _image->getWidth() %
534  _image->getHeight() % _mask->getWidth() % _mask->getHeight())
535  .str());
536  }
537  }
538 
539  if (!_variance || _variance->getWidth() == 0 || _variance->getHeight() == 0) {
540  _variance = VariancePtr(new Variance(_image->getBBox()));
541  *_variance = 0;
542  } else {
543  if (_variance->getDimensions() != _image->getDimensions()) {
544  throw LSST_EXCEPT(
546  (boost::format("Dimension mismatch: Image %dx%d v. Variance %dx%d") % _image->getWidth() %
547  _image->getHeight() % _variance->getWidth() % _variance->getHeight())
548  .str());
549  }
550  }
551 }
552 
553 //
554 // Iterators and locators
555 //
556 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
559 #if 0 // this doesn't compile; why?
560  return iterator(_image->begin(), _mask->begin(), _variance->begin());
561 #else
562  typename Image::iterator imageBegin = _image->begin();
563  typename Mask::iterator maskBegin = _mask->begin();
564  typename Variance::iterator varianceBegin = _variance->begin();
565 
566  return iterator(imageBegin, maskBegin, varianceBegin);
567 #endif
568 }
569 
570 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
573  typename Image::iterator imageEnd = getImage()->end();
574  typename Mask::iterator maskEnd = getMask()->end();
575  typename Variance::iterator varianceEnd = getVariance()->end();
576 
577  return iterator(imageEnd, maskEnd, varianceEnd);
578 }
579 
580 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
583  typename Image::iterator imageEnd = getImage()->at(x, y);
584  typename Mask::iterator maskEnd = getMask()->at(x, y);
585  typename Variance::iterator varianceEnd = getVariance()->at(x, y);
586 
587  return iterator(imageEnd, maskEnd, varianceEnd);
588 }
589 
590 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
593  typename Image::reverse_iterator imageBegin = _image->rbegin();
594  typename Mask::reverse_iterator maskBegin = _mask->rbegin();
595  typename Variance::reverse_iterator varianceBegin = _variance->rbegin();
596 
597  return reverse_iterator(imageBegin, maskBegin, varianceBegin);
598 }
599 
600 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
603  typename Image::reverse_iterator imageEnd = getImage()->rend();
604  typename Mask::reverse_iterator maskEnd = getMask()->rend();
605  typename Variance::reverse_iterator varianceEnd = getVariance()->rend();
606 
607  return reverse_iterator(imageEnd, maskEnd, varianceEnd);
608 }
609 
610 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
613  typename Image::x_iterator imageBegin = _image->row_begin(y);
614  typename Mask::x_iterator maskBegin = _mask->row_begin(y);
615  typename Variance::x_iterator varianceBegin = _variance->row_begin(y);
616 
617  return x_iterator(imageBegin, maskBegin, varianceBegin);
618 }
619 
620 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
623  typename Image::x_iterator imageEnd = getImage()->row_end(y);
624  typename Mask::x_iterator maskEnd = getMask()->row_end(y);
625  typename Variance::x_iterator varianceEnd = getVariance()->row_end(y);
626 
627  return x_iterator(imageEnd, maskEnd, varianceEnd);
628 }
629 
630 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
633  typename Image::y_iterator imageBegin = _image->col_begin(x);
634  typename Mask::y_iterator maskBegin = _mask->col_begin(x);
635  typename Variance::y_iterator varianceBegin = _variance->col_begin(x);
636 
637  return y_iterator(imageBegin, maskBegin, varianceBegin);
638 }
639 
640 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
643  typename Image::y_iterator imageEnd = getImage()->col_end(x);
644  typename Mask::y_iterator maskEnd = getMask()->col_end(x);
645  typename Variance::y_iterator varianceEnd = getVariance()->col_end(x);
646 
647  return y_iterator(imageEnd, maskEnd, varianceEnd);
648 }
649 
650 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
653  typename Image::fast_iterator imageBegin = _image->begin(contiguous);
654  typename Mask::fast_iterator maskBegin = _mask->begin(contiguous);
655  typename Variance::fast_iterator varianceBegin = _variance->begin(contiguous);
656 
657  return fast_iterator(imageBegin, maskBegin, varianceBegin);
658 }
659 
660 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
663  typename Image::fast_iterator imageEnd = getImage()->end(contiguous);
664  typename Mask::fast_iterator maskEnd = getMask()->end(contiguous);
665  typename Variance::fast_iterator varianceEnd = getVariance()->end(contiguous);
666 
667  return fast_iterator(imageEnd, maskEnd, varianceEnd);
668 }
669 
670 template <typename ImagePixelT1, typename ImagePixelT2>
673  return imagesOverlap(*image1.getImage(), *image2.getImage()) ||
674  imagesOverlap(*image1.getVariance(), *image2.getVariance()) ||
675  imagesOverlap(*image1.getMask(), *image2.getMask());
676 }
677 
678 //
679 // Explicit instantiations
680 //
681 #define INSTANTIATE2(ImagePixelT1, ImagePixelT2) \
682  template bool imagesOverlap<ImagePixelT1, ImagePixelT2>(MaskedImage<ImagePixelT1> const&, \
683  MaskedImage<ImagePixelT2> const&);
684 
685 template class MaskedImage<std::uint16_t>;
686 template class MaskedImage<int>;
687 template class MaskedImage<float>;
688 template class MaskedImage<double>;
689 template class MaskedImage<std::uint64_t>;
690 
694 INSTANTIATE2(std::uint16_t, double);
696 
698 INSTANTIATE2(int, int);
699 INSTANTIATE2(int, float);
700 INSTANTIATE2(int, double);
702 
704 INSTANTIATE2(float, int);
705 INSTANTIATE2(float, float);
706 INSTANTIATE2(float, double);
708 
709 INSTANTIATE2(double, std::uint16_t);
710 INSTANTIATE2(double, int);
711 INSTANTIATE2(double, float);
712 INSTANTIATE2(double, double);
713 INSTANTIATE2(double, std::uint64_t);
714 
718 INSTANTIATE2(std::uint64_t, double);
720 
721 } // namespace image
722 } // namespace afw
723 } // namespace lsst
AmpInfoBoxKey bbox
Definition: Amplifier.cc:117
VariancePtr getVariance() const
Return a (shared_ptr to) the MaskedImage&#39;s variance.
Definition: MaskedImage.h:1090
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174
std::shared_ptr< daf::base::PropertyList > readVarianceMetadata()
Read the FITS header of one of the HDUs.
void scaledPlus(OutImageT &outImage, double c1, InImageT const &inImage1, double c2, InImageT const &inImage2)
Compute the scaled sum of two images.
VariancePixelT variance() const
Return the variance part of a Pixel.
Definition: Pixel.h:221
afw::table::Key< afw::table::Array< VariancePixelT > > variance
x_iterator fast_iterator
A fast STL compliant iterator for contiguous images N.b.
Definition: ImageBase.h:137
_view_t::reverse_iterator reverse_iterator
An STL compliant reverse iterator.
Definition: ImageBase.h:129
Image< LhsPixelT > & operator+=(Image< LhsPixelT > &lhs, Image< RhsPixelT > const &rhs)
Add lhs to Image rhs (i.e. pixel-by-pixel addition) where types are different.
Definition: Image.cc:671
void writeMetadata(daf::base::PropertySet const &metadata)
Read a FITS header into a PropertySet or PropertyList.
Definition: fits.cc:1078
afw::table::Key< afw::table::Array< MaskPixelT > > mask
x_iterator fast_iterator
A fast STL compliant iterator for contiguous images N.b.
Definition: MaskedImage.h:564
T swap(T... args)
Class for storing ordered metadata with comments.
Definition: PropertyList.h:68
iterator at(int const x, int const y) const
Return an iterator at the point (x, y)
Definition: MaskedImage.cc:582
VariancePixelT variance() const
Definition: Pixel.h:96
Reports attempts to exceed implementation-defined length limits for some classes. ...
Definition: Runtime.h:76
Options for writing an image to FITS.
Definition: fits.h:219
_view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
Definition: ImageBase.h:133
int y
Definition: SpanSet.cc:49
std::shared_ptr< daf::base::PropertyList > readMaskMetadata()
Read the FITS header of one of the HDUs.
MaskedImageIterator< typename Image::x_iterator, typename Mask::x_iterator, typename Variance::x_iterator > x_iterator
An iterator to a row of a MaskedImage.
Definition: MaskedImage.h:556
MaskPixelT mask() const
Definition: Pixel.h:95
A single pixel of the same type as a MaskedImage.
Definition: Pixel.h:73
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:297
MaskedImage(unsigned int width, unsigned int height, MaskPlaneDict const &planeDict=MaskPlaneDict())
Construct from a supplied dimensions.
Definition: MaskedImage.cc:48
void createEmpty()
Create an empty image HDU with NAXIS=0 at the end of the file.
Definition: fits.cc:1223
MaskedImageIterator< typename Image::iterator, typename Mask::iterator, typename Variance::iterator > iterator
Definition: MaskedImage.h:539
ImagePtr getImage() const
Return a (shared_ptr to) the MaskedImage&#39;s image.
Definition: MaskedImage.h:1057
STL class.
LSST DM logging module built on log4cxx.
An iterator to the MaskedImage.
Definition: MaskedImage.h:99
_view_t::iterator iterator
An STL compliant iterator.
Definition: ImageBase.h:125
reverse_iterator rend() const
Return a reverse_iterator to the end of the image.
Definition: MaskedImage.cc:602
afw::table::PointKey< int > dimensions
Definition: GaussianPsf.cc:49
ImagePixelT image() const
Definition: Pixel.h:94
A base class for image defects.
Represent a 2-dimensional array of bitmask pixels.
Definition: Mask.h:77
MaskedImageIterator< typename Image::y_iterator, typename Mask::y_iterator, typename Variance::y_iterator > y_iterator
An iterator to a column of a MaskedImage.
Definition: MaskedImage.h:568
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:121
MaskPixelT mask() const
Return the mask part of a Pixel.
Definition: Pixel.h:219
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:73
_view_t::y_iterator y_iterator
An iterator for traversing the pixels in a column.
Definition: ImageBase.h:143
ImagePixelT image() const
Return the image part of a Pixel.
Definition: Pixel.h:217
std::shared_ptr< daf::base::PropertyList > readPrimaryMetadata()
Read the FITS header of one of the HDUs.
MaskedImageIterator< typename Image::reverse_iterator, typename Mask::reverse_iterator, typename Variance::reverse_iterator > reverse_iterator
Definition: MaskedImage.h:547
bool imagesOverlap(ImageBase< T1 > const &image1, ImageBase< T2 > const &image2)
Return true if the pixels for two images or masks overlap in memory.
Definition: Image.cc:706
T reset(T... args)
Reports errors in the logical structure of the program.
Definition: Runtime.h:46
double x
void setHdu(int hdu, bool relative=false)
Set the current HDU.
Definition: fits.cc:512
x_iterator row_end(int y) const
Return an x_iterator to the end of the image.
Definition: MaskedImage.cc:622
MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > read(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool conformMasks=false, bool needAllHdus=false, bool allowUnsafe=false)
Read the full MaskedImage.
MaskPtr getMask() const
Return a (shared_ptr to) the MaskedImage&#39;s mask.
Definition: MaskedImage.h:1069
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
A pixel of a MaskedImage.
Definition: Pixel.h:148
Image< LhsPixelT > & operator*=(Image< LhsPixelT > &lhs, Image< RhsPixelT > const &rhs)
Multiply lhs by Image rhs (i.e. pixel-by-pixel multiplication) where types are different.
Definition: Image.cc:683
Image< LhsPixelT > & operator-=(Image< LhsPixelT > &lhs, Image< RhsPixelT > const &rhs)
Subtract lhs from Image rhs (i.e. pixel-by-pixel subtraction) where types are different.
Definition: Image.cc:677
y_iterator col_end(int x) const
Return an y_iterator to the end of the image.
Definition: MaskedImage.cc:642
double _c
Definition: MaskedImage.cc:304
A FITS reader class for MaskedImages and their components.
void swap(CameraSys &a, CameraSys &b)
Definition: CameraSys.h:157
Image< LhsPixelT > & operator/=(Image< LhsPixelT > &lhs, Image< RhsPixelT > const &rhs)
Divide lhs by Image rhs (i.e. pixel-by-pixel division) where types are different. ...
Definition: Image.cc:689
std::shared_ptr< daf::base::PropertyList > readImageMetadata()
Read the FITS header of one of the HDUs.
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...
int getHdu()
Return the current HDU (0-indexed; 0 is the Primary HDU).
Definition: fits.cc:506
An integer coordinate rectangle.
Definition: Box.h:55
#define INSTANTIATE2(ImagePixelT1, ImagePixelT2)
Definition: MaskedImage.cc:681
int end
void scaledMinus(double const c, MaskedImage const &rhs)
Subtract a scaled MaskedImage c*rhs from a MaskedImage.
Definition: MaskedImage.cc:277
int countHdus()
Return the number of HDUs in the file.
Definition: fits.cc:533