LSST Applications 27.0.0,g0265f82a02+469cd937ee,g02d81e74bb+21ad69e7e1,g1470d8bcf6+cbe83ee85a,g2079a07aa2+e67c6346a6,g212a7c68fe+04a9158687,g2305ad1205+94392ce272,g295015adf3+81dd352a9d,g2bbee38e9b+469cd937ee,g337abbeb29+469cd937ee,g3939d97d7f+72a9f7b576,g487adcacf7+71499e7cba,g50ff169b8f+5929b3527e,g52b1c1532d+a6fc98d2e7,g591dd9f2cf+df404f777f,g5a732f18d5+be83d3ecdb,g64a986408d+21ad69e7e1,g858d7b2824+21ad69e7e1,g8a8a8dda67+a6fc98d2e7,g99cad8db69+f62e5b0af5,g9ddcbc5298+d4bad12328,ga1e77700b3+9c366c4306,ga8c6da7877+71e4819109,gb0e22166c9+25ba2f69a1,gb6a65358fc+469cd937ee,gbb8dafda3b+69d3c0e320,gc07e1c2157+a98bf949bb,gc120e1dc64+615ec43309,gc28159a63d+469cd937ee,gcf0d15dbbd+72a9f7b576,gdaeeff99f8+a38ce5ea23,ge6526c86ff+3a7c1ac5f1,ge79ae78c31+469cd937ee,gee10cc3b42+a6fc98d2e7,gf1cff7945b+21ad69e7e1,gfbcc870c63+9a11dc8c8f
LSST Data Management Base Package
Loading...
Searching...
No Matches
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
30#include "boost/format.hpp"
31#include "lsst/log/Log.h"
32#include "lsst/pex/exceptions.h"
33
35#include "lsst/afw/fits.h"
37
38namespace lsst {
39namespace afw {
40namespace image {
41
42template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
44 MaskPlaneDict const& planeDict)
45 : _image(new Image(width, height)),
46 _mask(new Mask(width, height, planeDict)),
47 _variance(new Variance(width, height)) {
48 *_image = 0;
49 *_mask = 0x0;
50 *_variance = 0;
51}
52
53template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
55 MaskPlaneDict const& planeDict)
56 : _image(new Image(dimensions)),
57 _mask(new Mask(dimensions, planeDict)),
58 _variance(new Variance(dimensions)) {
59 *_image = 0;
60 *_mask = 0x0;
61 *_variance = 0;
62}
63
64template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
66 MaskPlaneDict const& planeDict)
67 : _image(new Image(bbox)), _mask(new Mask(bbox, planeDict)), _variance(new Variance(bbox)) {
68 *_image = 0;
69 *_mask = 0x0;
70 *_variance = 0;
71}
72
73template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
76 lsst::geom::Box2I const& bbox, ImageOrigin origin, bool conformMasks, bool needAllHdus,
79 std::shared_ptr<daf::base::PropertySet> varianceMetadata, bool allowUnsafe)
80 : _image(), _mask(), _variance() {
81 MaskedImageFitsReader reader(fileName);
82 *this = reader.read<ImagePixelT, MaskPixelT, VariancePixelT>(bbox, origin, conformMasks, needAllHdus,
83 allowUnsafe);
84 if (metadata) {
85 metadata->combine(*reader.readPrimaryMetadata());
86 }
87 if (imageMetadata) {
88 imageMetadata->combine(*reader.readImageMetadata());
89 }
90 if (maskMetadata) {
91 maskMetadata->combine(*reader.readMaskMetadata());
92 }
93 if (varianceMetadata) {
94 varianceMetadata->combine(*reader.readVarianceMetadata());
95 }
96}
97
98template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
101 lsst::geom::Box2I const& bbox, ImageOrigin origin, bool conformMasks, bool needAllHdus,
104 std::shared_ptr<daf::base::PropertySet> varianceMetadata, bool allowUnsafe)
105 : _image(), _mask(), _variance() {
106 MaskedImageFitsReader reader(manager);
107 *this = reader.read<ImagePixelT, MaskPixelT, VariancePixelT>(bbox, origin, conformMasks, needAllHdus,
108 allowUnsafe);
109 if (metadata) {
110 metadata->combine(*reader.readPrimaryMetadata());
111 }
112 if (imageMetadata) {
113 imageMetadata->combine(*reader.readImageMetadata());
114 }
115 if (maskMetadata) {
116 maskMetadata->combine(*reader.readMaskMetadata());
117 }
118 if (varianceMetadata) {
119 varianceMetadata->combine(*reader.readVarianceMetadata());
120 }
121}
122
123template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
126 ImageOrigin origin, bool conformMasks, bool needAllHdus,
129 std::shared_ptr<daf::base::PropertySet> varianceMetadata, bool allowUnsafe)
130 : _image(), _mask(), _variance() {
131 MaskedImageFitsReader reader(&fitsFile);
132 *this = reader.read<ImagePixelT, MaskPixelT, VariancePixelT>(bbox, origin, conformMasks, needAllHdus,
133 allowUnsafe);
134 if (metadata) {
135 metadata->combine(*reader.readPrimaryMetadata());
136 }
137 if (imageMetadata) {
138 imageMetadata->combine(*reader.readImageMetadata());
139 }
140 if (maskMetadata) {
141 maskMetadata->combine(*reader.readMaskMetadata());
142 }
143 if (varianceMetadata) {
144 varianceMetadata->combine(*reader.readVarianceMetadata());
145 }
146}
147
148template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
154
155template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
157 : _image(rhs._image), _mask(rhs._mask), _variance(rhs._variance) {
158 if (deep) {
159 _image = std::shared_ptr<Image>(new Image(*rhs.getImage(), deep));
160 _mask = std::shared_ptr<Mask>(new Mask(*rhs.getMask(), deep));
161 _variance = std::shared_ptr<Variance>(new Variance(*rhs.getVariance(), deep));
162 }
163 conformSizes();
164}
165
166// Delegate to copy-constructor for backwards compatibility
167template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
170
171template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
173 const lsst::geom::Box2I& bbox,
174 ImageOrigin const origin, bool deep
175
176 )
177 : _image(new Image(*rhs.getImage(), bbox, origin, deep)),
178 _mask(rhs._mask ? new Mask(*rhs.getMask(), bbox, origin, deep) : static_cast<Mask*>(nullptr)),
179 _variance(rhs._variance ? new Variance(*rhs.getVariance(), bbox, origin, deep)
180 : static_cast<Variance*>(nullptr)) {
181 conformSizes();
182}
183
184template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
186operator=(MaskedImage const& rhs) = default;
187
188template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
190operator=(MaskedImage&& rhs) = default;
191
192template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
194 using std::swap; // See Meyers, Effective C++, Item 25
195
196 _image.swap(rhs._image);
197 _mask.swap(rhs._mask);
198 _variance.swap(rhs._variance);
199}
200
201// Operators
202template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
204operator=(MaskedImage::Pixel const& rhs) {
205 *_image = rhs.image();
206 *_mask = rhs.mask();
207 *_variance = rhs.variance();
208
209 return *this;
210}
211
212template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
215 *_image = rhs.image();
216 *_mask = rhs.mask();
217 *_variance = rhs.variance();
218
219 return *this;
220}
221
222template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
224 lsst::geom::Box2I const& bbox,
225 ImageOrigin origin) {
226 _image->assign(*rhs.getImage(), bbox, origin);
227 _mask->assign(*rhs.getMask(), bbox, origin);
228 _variance->assign(*rhs.getVariance(), bbox, origin);
229}
230
231template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
233operator+=(MaskedImage const& rhs) {
234 *_image += *rhs.getImage();
235 *_mask |= *rhs.getMask();
236 *_variance += *rhs.getVariance();
237 return *this;
238}
239
240template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
242 MaskedImage const& rhs) {
243 (*_image).scaledPlus(c, *rhs.getImage());
244 *_mask |= *rhs.getMask();
245 (*_variance).scaledPlus(c * c, *rhs.getVariance());
246}
247
248template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
254
255template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
257operator-=(MaskedImage const& rhs) {
258 *_image -= *rhs.getImage();
259 *_mask |= *rhs.getMask();
260 *_variance += *rhs.getVariance();
261 return *this;
262}
263
264template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
266 MaskedImage const& rhs) {
267 (*_image).scaledMinus(c, *rhs.getImage());
268 *_mask |= *rhs.getMask();
269 (*_variance).scaledPlus(c * c, *rhs.getVariance());
270}
271
272template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
278
279namespace {
281template <typename ImagePixelT, typename VariancePixelT>
282struct productVariance {
283 double operator()(ImagePixelT lhs, ImagePixelT rhs, VariancePixelT varLhs, VariancePixelT varRhs) {
284 return lhs * lhs * varRhs + rhs * rhs * varLhs;
285 }
286};
287
290template <typename ImagePixelT, typename VariancePixelT>
291struct scaledProductVariance {
292 double _c;
293 scaledProductVariance(double const c) : _c(c) {}
294 double operator()(ImagePixelT lhs, ImagePixelT rhs, VariancePixelT varLhs, VariancePixelT varRhs) {
295 return _c * _c * (lhs * lhs * varRhs + rhs * rhs * varLhs);
296 }
297};
298} // namespace
299
300template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
302operator*=(MaskedImage const& rhs) {
303 // Must do variance before we modify the image values
304 if (_image->getDimensions() != rhs._image->getDimensions()) {
306 boost::str(boost::format("Images are of different size, %dx%d v %dx%d") %
307 _image->getWidth() % _image->getHeight() % rhs._image->getWidth() % rhs._image->getHeight()));
308 }
309 transform_pixels(_image->_getRawView(), // lhs
310 rhs._image->_getRawView(), // rhs,
311 _variance->_getRawView(), // Var(lhs),
312 rhs._variance->_getRawView(), // Var(rhs)
313 _variance->_getRawView(), // result
314 productVariance<ImagePixelT, VariancePixelT>());
315
316 *_image *= *rhs.getImage();
317 *_mask |= *rhs.getMask();
318 return *this;
319}
320
321template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
323 MaskedImage const& rhs) {
324 // Must do variance before we modify the image values
325 if (_image->getDimensions() != rhs._image->getDimensions()) {
327 boost::str(boost::format("Images are of different size, %dx%d v %dx%d") %
328 _image->getWidth() % _image->getHeight() % rhs._image->getWidth() % rhs._image->getHeight()));
329 }
330 transform_pixels(_image->_getRawView(), // lhs
331 rhs._image->_getRawView(), // rhs,
332 _variance->_getRawView(), // Var(lhs),
333 rhs._variance->_getRawView(), // Var(rhs)
334 _variance->_getRawView(), // result
335 scaledProductVariance<ImagePixelT, VariancePixelT>(c));
336
337 (*_image).scaledMultiplies(c, *rhs.getImage());
338 *_mask |= *rhs.getMask();
339}
340
341template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
343operator*=(ImagePixelT const rhs) {
344 *_image *= rhs;
345 *_variance *= rhs * rhs;
346 return *this;
347}
348
349namespace {
351template <typename ImagePixelT, typename VariancePixelT>
352struct quotientVariance {
353 double operator()(ImagePixelT lhs, ImagePixelT rhs, VariancePixelT varLhs, VariancePixelT varRhs) {
354 ImagePixelT const rhs2 = rhs * rhs;
355 return (lhs * lhs * varRhs + rhs2 * varLhs) / (rhs2 * rhs2);
356 }
357};
360template <typename ImagePixelT, typename VariancePixelT>
361struct scaledQuotientVariance {
362 double _c;
363 scaledQuotientVariance(double c) : _c(c) {}
364 double operator()(ImagePixelT lhs, ImagePixelT rhs, VariancePixelT varLhs, VariancePixelT varRhs) {
365 ImagePixelT const rhs2 = rhs * rhs;
366 return (lhs * lhs * varRhs + rhs2 * varLhs) / (_c * _c * rhs2 * rhs2);
367 }
368};
369} // namespace
370
371template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
373operator/=(MaskedImage const& rhs) {
374 // Must do variance before we modify the image values
375 if (_image->getDimensions() != rhs._image->getDimensions()) {
377 boost::str(boost::format("Images are of different size, %dx%d v %dx%d") %
378 _image->getWidth() % _image->getHeight() % rhs._image->getWidth() % rhs._image->getHeight()));
379 }
380 transform_pixels(_image->_getRawView(), // lhs
381 rhs._image->_getRawView(), // rhs,
382 _variance->_getRawView(), // Var(lhs),
383 rhs._variance->_getRawView(), // Var(rhs)
384 _variance->_getRawView(), // result
385 quotientVariance<ImagePixelT, VariancePixelT>());
386
387 *_image /= *rhs.getImage();
388 *_mask |= *rhs.getMask();
389 return *this;
390}
391
392template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
394 MaskedImage const& rhs) {
395 // Must do variance before we modify the image values
396 if (_image->getDimensions() != rhs._image->getDimensions()) {
398 str(boost::format("Images are of different size, %dx%d v %dx%d") %
399 _image->getWidth() % _image->getHeight() % rhs._image->getWidth() % rhs._image->getHeight()));
400 }
401 transform_pixels(_image->_getRawView(), // lhs
402 rhs._image->_getRawView(), // rhs,
403 _variance->_getRawView(), // Var(lhs),
404 rhs._variance->_getRawView(), // Var(rhs)
405 _variance->_getRawView(), // result
406 scaledQuotientVariance<ImagePixelT, VariancePixelT>(c));
407
408 (*_image).scaledDivides(c, *rhs.getImage());
409 *_mask |= *rhs._mask;
410}
411
412template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
414operator/=(ImagePixelT const rhs) {
415 *_image /= rhs;
416 *_variance /= rhs * rhs;
417 return *this;
418}
419
420template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
425 std::shared_ptr<daf::base::PropertySet const> varianceMetadata) const {
427 writeFits(fitsfile, metadata, imageMetadata, maskMetadata, varianceMetadata);
428}
429
430template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
435 std::shared_ptr<daf::base::PropertySet const> varianceMetadata) const {
437 writeFits(fitsfile, metadata, imageMetadata, maskMetadata, varianceMetadata);
438}
439
440namespace {
441
442void processPlaneMetadata(daf::base::PropertySet const * metadata,
443 std::shared_ptr<daf::base::PropertySet>& hdr, char const* exttype) {
444 if (metadata) {
445 hdr = metadata->deepCopy();
446 } else {
448 }
449 hdr->set("INHERIT", true);
450 hdr->set("EXTTYPE", exttype);
451 hdr->set("EXTNAME", exttype);
452}
453
454} // namespace
455
456template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
461 std::shared_ptr<daf::base::PropertySet const> varianceMetadata) const {
462 writeFits(fitsfile, fits::ImageWriteOptions(*_image), fits::ImageWriteOptions(*_mask),
463 fits::ImageWriteOptions(*_variance), metadata, imageMetadata, maskMetadata, varianceMetadata);
464}
465
466template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
468 std::string const& fileName, fits::ImageWriteOptions const& imageOptions,
469 fits::ImageWriteOptions const& maskOptions, fits::ImageWriteOptions const& varianceOptions,
473 std::shared_ptr<daf::base::PropertySet const> varianceMetadata) const {
475 writeFits(fitsfile, imageOptions, maskOptions, varianceOptions, metadata, imageMetadata, maskMetadata,
476 varianceMetadata);
477}
478
479template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
481 fits::MemFileManager& manager, fits::ImageWriteOptions const& imageOptions,
482 fits::ImageWriteOptions const& maskOptions, fits::ImageWriteOptions const& varianceOptions,
486 std::shared_ptr<daf::base::PropertySet const> varianceMetadata) const {
488 writeFits(fitsfile, imageOptions, maskOptions, varianceOptions, metadata, imageMetadata, maskMetadata,
489 varianceMetadata);
490}
491
492template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
494 fits::Fits& fitsfile, fits::ImageWriteOptions const& imageOptions,
495 fits::ImageWriteOptions const& maskOptions, fits::ImageWriteOptions const& varianceOptions,
499 std::shared_ptr<daf::base::PropertySet const> varianceMetadata) const {
501 if (metadata) {
502 header = metadata->deepCopy();
503 } else {
504 header = std::make_shared<daf::base::PropertyList>();
505 }
506
507 if (fitsfile.countHdus() != 0) {
509 "MaskedImage::writeFits can only write to an empty file");
510 }
511 if (fitsfile.getHdu() < 1) {
512 // Don't ever write images to primary; instead we make an empty primary.
513 fitsfile.createEmpty();
514 } else {
515 fitsfile.setHdu(0);
516 }
517 fitsfile.writeMetadata(*header);
518
519 processPlaneMetadata(imageMetadata.get(), header, "IMAGE");
520 _image->writeFits(fitsfile, imageOptions, header.get(), _mask.get());
521
522 processPlaneMetadata(maskMetadata.get(), header, "MASK");
523 _mask->writeFits(fitsfile, maskOptions, header.get());
524
525 processPlaneMetadata(varianceMetadata.get(), header, "VARIANCE");
526 _variance->writeFits(fitsfile, varianceOptions, header.get(), _mask.get());
527}
528
529// private function conformSizes() ensures that the Mask and Variance have the same dimensions
530// as Image. If Mask and/or Variance have non-zero dimensions that conflict with the size of Image,
531// a lsst::pex::exceptions::LengthError is thrown.
532
533template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
535 if (!_mask || _mask->getWidth() == 0 || _mask->getHeight() == 0) {
536 _mask = MaskPtr(new Mask(_image->getBBox()));
537 *_mask = 0;
538 } else {
539 if (_mask->getDimensions() != _image->getDimensions()) {
540 throw LSST_EXCEPT(
542 (boost::format("Dimension mismatch: Image %dx%d v. Mask %dx%d") % _image->getWidth() %
543 _image->getHeight() % _mask->getWidth() % _mask->getHeight())
544 .str());
545 }
546 }
547
548 if (!_variance || _variance->getWidth() == 0 || _variance->getHeight() == 0) {
549 _variance = VariancePtr(new Variance(_image->getBBox()));
550 *_variance = 0;
551 } else {
552 if (_variance->getDimensions() != _image->getDimensions()) {
553 throw LSST_EXCEPT(
554 pex::exceptions::LengthError,
555 (boost::format("Dimension mismatch: Image %dx%d v. Variance %dx%d") % _image->getWidth() %
556 _image->getHeight() % _variance->getWidth() % _variance->getHeight())
557 .str());
558 }
559 }
560}
561
562//
563// Iterators and locators
564//
565template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
568#if 0 // this doesn't compile; why?
569 return iterator(_image->begin(), _mask->begin(), _variance->begin());
570#else
571 typename Image::iterator imageBegin = _image->begin();
572 typename Mask::iterator maskBegin = _mask->begin();
573 typename Variance::iterator varianceBegin = _variance->begin();
574
575 return iterator(imageBegin, maskBegin, varianceBegin);
576#endif
577}
578
579template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
582 typename Image::iterator imageEnd = getImage()->end();
583 typename Mask::iterator maskEnd = getMask()->end();
584 typename Variance::iterator varianceEnd = getVariance()->end();
585
586 return iterator(imageEnd, maskEnd, varianceEnd);
587}
588
589template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
592 typename Image::iterator imageEnd = getImage()->at(x, y);
593 typename Mask::iterator maskEnd = getMask()->at(x, y);
594 typename Variance::iterator varianceEnd = getVariance()->at(x, y);
595
596 return iterator(imageEnd, maskEnd, varianceEnd);
597}
598
599template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
602 typename Image::reverse_iterator imageBegin = _image->rbegin();
603 typename Mask::reverse_iterator maskBegin = _mask->rbegin();
604 typename Variance::reverse_iterator varianceBegin = _variance->rbegin();
605
606 return reverse_iterator(imageBegin, maskBegin, varianceBegin);
607}
608
609template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
612 typename Image::reverse_iterator imageEnd = getImage()->rend();
613 typename Mask::reverse_iterator maskEnd = getMask()->rend();
614 typename Variance::reverse_iterator varianceEnd = getVariance()->rend();
615
616 return reverse_iterator(imageEnd, maskEnd, varianceEnd);
617}
618
619template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
622 typename Image::x_iterator imageBegin = _image->row_begin(y);
623 typename Mask::x_iterator maskBegin = _mask->row_begin(y);
624 typename Variance::x_iterator varianceBegin = _variance->row_begin(y);
625
626 return x_iterator(imageBegin, maskBegin, varianceBegin);
627}
628
629template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
632 typename Image::x_iterator imageEnd = getImage()->row_end(y);
633 typename Mask::x_iterator maskEnd = getMask()->row_end(y);
634 typename Variance::x_iterator varianceEnd = getVariance()->row_end(y);
635
636 return x_iterator(imageEnd, maskEnd, varianceEnd);
637}
638
639template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
642 typename Image::y_iterator imageBegin = _image->col_begin(x);
643 typename Mask::y_iterator maskBegin = _mask->col_begin(x);
644 typename Variance::y_iterator varianceBegin = _variance->col_begin(x);
645
646 return y_iterator(imageBegin, maskBegin, varianceBegin);
647}
649template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
652 typename Image::y_iterator imageEnd = getImage()->col_end(x);
653 typename Mask::y_iterator maskEnd = getMask()->col_end(x);
654 typename Variance::y_iterator varianceEnd = getVariance()->col_end(x);
655
656 return y_iterator(imageEnd, maskEnd, varianceEnd);
657}
658
659template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
662 typename Image::fast_iterator imageBegin = _image->begin(contiguous);
663 typename Mask::fast_iterator maskBegin = _mask->begin(contiguous);
664 typename Variance::fast_iterator varianceBegin = _variance->begin(contiguous);
665
666 return fast_iterator(imageBegin, maskBegin, varianceBegin);
667}
668
669template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
672 typename Image::fast_iterator imageEnd = getImage()->end(contiguous);
673 typename Mask::fast_iterator maskEnd = getMask()->end(contiguous);
674 typename Variance::fast_iterator varianceEnd = getVariance()->end(contiguous);
675
676 return fast_iterator(imageEnd, maskEnd, varianceEnd);
677}
678
679template <typename ImagePixelT1, typename ImagePixelT2>
682 return imagesOverlap(*image1.getImage(), *image2.getImage()) ||
683 imagesOverlap(*image1.getVariance(), *image2.getVariance()) ||
684 imagesOverlap(*image1.getMask(), *image2.getMask());
685}
686
687//
688// Explicit instantiations
689//
690#define INSTANTIATE2(ImagePixelT1, ImagePixelT2) \
691 template bool imagesOverlap<ImagePixelT1, ImagePixelT2>(MaskedImage<ImagePixelT1> const&, \
692 MaskedImage<ImagePixelT2> const&);
AmpInfoBoxKey bbox
Definition Amplifier.cc:117
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48
afw::table::Key< afw::table::Array< MaskPixelT > > mask
afw::table::Key< afw::table::Array< VariancePixelT > > variance
LSST DM logging module built on log4cxx.
double _c
#define INSTANTIATE2(ImagePixelT1, ImagePixelT2)
int y
Definition SpanSet.cc:48
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition fits.h:308
void createEmpty()
Create an empty image HDU with NAXIS=0 at the end of the file.
Definition fits.cc:1259
void setHdu(int hdu, bool relative=false)
Set the current HDU.
Definition fits.cc:524
int countHdus()
Return the number of HDUs in the file.
Definition fits.cc:553
int getHdu()
Return the current HDU (0-indexed; 0 is the Primary HDU).
Definition fits.cc:518
void writeMetadata(daf::base::PropertySet const &metadata)
Read a FITS header into a PropertySet or PropertyList.
Definition fits.cc:1114
Lifetime-management for memory that goes into FITS memory files.
Definition fits.h:125
typename _view_t::iterator iterator
An STL compliant iterator.
Definition ImageBase.h:125
int getWidth() const
Return the number of columns in the image.
Definition ImageBase.h:294
lsst::geom::Extent2I getDimensions() const
Return the image's size; useful for passing to constructors.
Definition ImageBase.h:356
x_iterator fast_iterator
A fast STL compliant iterator for contiguous images N.b.
Definition ImageBase.h:137
typename _view_t::reverse_iterator reverse_iterator
An STL compliant reverse iterator.
Definition ImageBase.h:129
int getHeight() const
Return the number of rows in the image.
Definition ImageBase.h:296
typename _view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
Definition ImageBase.h:133
_view_t _getRawView() const
Definition ImageBase.h:465
typename _view_t::y_iterator y_iterator
An iterator for traversing the pixels in a column.
Definition ImageBase.h:143
Represent a 2-dimensional array of bitmask pixels.
Definition Mask.h:77
A FITS reader class for MaskedImages and their components.
std::shared_ptr< daf::base::PropertyList > readImageMetadata()
Read the FITS header of one of the HDUs.
std::shared_ptr< daf::base::PropertyList > readPrimaryMetadata()
Read the FITS header of one of the HDUs.
std::shared_ptr< daf::base::PropertyList > readMaskMetadata()
Read the FITS header of one of the HDUs.
std::shared_ptr< daf::base::PropertyList > readVarianceMetadata()
Read the FITS header of one of the HDUs.
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.
A class to manipulate images, masks, and variance as a single object.
Definition MaskedImage.h:74
void scaledPlus(double const c, MaskedImage const &rhs)
Add a scaled MaskedImage c*rhs to a MaskedImage.
lsst::afw::image::Image< VariancePixelT > Variance
Definition MaskedImage.h:85
void writeFits(std::string const &fileName, std::shared_ptr< daf::base::PropertySet const > metadata=std::shared_ptr< daf::base::PropertySet const >(), std::shared_ptr< daf::base::PropertySet const > imageMetadata=std::shared_ptr< daf::base::PropertySet const >(), std::shared_ptr< daf::base::PropertySet const > maskMetadata=std::shared_ptr< daf::base::PropertySet const >(), std::shared_ptr< daf::base::PropertySet const > varianceMetadata=std::shared_ptr< daf::base::PropertySet const >()) const
Write a MaskedImage to a regular FITS file.
MaskedImage(unsigned int width, unsigned int height, MaskPlaneDict const &planeDict=MaskPlaneDict())
Construct from a supplied dimensions.
void scaledDivides(double const c, MaskedImage const &rhs)
typename Mask< MaskPixelT >::MaskPlaneDict MaskPlaneDict
The Mask's MaskPlaneDict.
Definition MaskedImage.h:83
iterator begin() const
Return an iterator to the start of the image.
reverse_iterator rbegin() const
Return a reverse_iterator to the start of the image.
lsst::afw::image::Mask< MaskPixelT > Mask
Definition MaskedImage.h:87
y_iterator col_end(int x) const
Return an y_iterator to the end of the image.
void scaledMinus(double const c, MaskedImage const &rhs)
Subtract a scaled MaskedImage c*rhs from a MaskedImage.
x_iterator fast_iterator
A fast STL compliant iterator for contiguous images N.b.
MaskedImageIterator< typename Image::reverse_iterator, typename Mask::reverse_iterator, typename Variance::reverse_iterator > reverse_iterator
MaskedImageIterator< typename Image::iterator, typename Mask::iterator, typename Variance::iterator > iterator
MaskedImage & operator-=(ImagePixelT const rhs)
Subtract a scalar rhs from a MaskedImage.
x_iterator row_end(int y) const
Return an x_iterator to the end of the image.
void scaledMultiplies(double const c, MaskedImage const &rhs)
iterator end() const
Return an iterator to the end of the image.
void assign(MaskedImage const &rhs, lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT)
Copy pixels from another masked image to a specified subregion of this masked image.
VariancePtr getVariance() const
Return a (shared_ptr to) the MaskedImage's variance.
MaskedImage & operator=(MaskedImage const &rhs)
Make the lhs use the rhs's pixels.
lsst::afw::image::Image< ImagePixelT > Image
Definition MaskedImage.h:86
x_iterator row_begin(int y) const
Return an x_iterator to the start of the image.
void swap(MaskedImage &rhs)
y_iterator col_begin(int x) const
Return an y_iterator to the start of the image.
reverse_iterator rend() const
Return a reverse_iterator to the end of the image.
MaskedImage & operator+=(ImagePixelT const rhs)
Add a scalar rhs to a MaskedImage.
MaskedImage & operator*=(ImagePixelT const rhs)
iterator at(int const x, int const y) const
Return an iterator at the point (x, y)
MaskedImage & operator/=(ImagePixelT const rhs)
MaskPtr getMask() const
Return a (shared_ptr to) the MaskedImage's mask.
ImagePtr getImage() const
Return a (shared_ptr to) the MaskedImage's image.
A pixel of a MaskedImage.
Definition Pixel.h:148
MaskPixelT mask() const
Return the mask part of a Pixel.
Definition Pixel.h:219
ImagePixelT image() const
Return the image part of a Pixel.
Definition Pixel.h:217
VariancePixelT variance() const
Return the variance part of a Pixel.
Definition Pixel.h:221
A single pixel of the same type as a MaskedImage.
Definition Pixel.h:73
VariancePixelT variance() const
Definition Pixel.h:96
ImagePixelT image() const
Definition Pixel.h:94
Class for storing ordered metadata with comments.
Class for storing generic metadata.
Definition PropertySet.h:66
virtual std::shared_ptr< PropertySet > deepCopy() const
Make a deep copy of the PropertySet and all of its contents.
An integer coordinate rectangle.
Definition Box.h:55
Reports attempts to exceed implementation-defined length limits for some classes.
Definition Runtime.h:76
Reports errors in the logical structure of the program.
Definition Runtime.h:46
T get(T... args)
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:693
T reset(T... args)
Options for writing an image to FITS.
Definition fits.h:223
T swap(T... args)