LSST Applications g0f08755f38+82efc23009,g12f32b3c4e+e7bdf1200e,g1653933729+a8ce1bb630,g1a0ca8cf93+50eff2b06f,g28da252d5a+52db39f6a5,g2bbee38e9b+37c5a29d61,g2bc492864f+37c5a29d61,g2cdde0e794+c05ff076ad,g3156d2b45e+41e33cbcdc,g347aa1857d+37c5a29d61,g35bb328faa+a8ce1bb630,g3a166c0a6a+37c5a29d61,g3e281a1b8c+fb992f5633,g414038480c+7f03dfc1b0,g41af890bb2+11b950c980,g5fbc88fb19+17cd334064,g6b1c1869cb+12dd639c9a,g781aacb6e4+a8ce1bb630,g80478fca09+72e9651da0,g82479be7b0+04c31367b4,g858d7b2824+82efc23009,g9125e01d80+a8ce1bb630,g9726552aa6+8047e3811d,ga5288a1d22+e532dc0a0b,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+37c5a29d61,gcf0d15dbbd+2acd6d4d48,gd7358e8bfb+778a810b6e,gda3e153d99+82efc23009,gda6a2b7d83+2acd6d4d48,gdaeeff99f8+1711a396fd,ge2409df99d+6b12de1076,ge79ae78c31+37c5a29d61,gf0baf85859+d0a5978c5a,gf3967379c6+4954f8c433,gfb92a5be7c+82efc23009,gfec2e1e490+2aaed99252,w.2024.46
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>
151 : _image(image != nullptr ? image : std::make_shared<Image>()),
152 _mask(mask), _variance(variance) {
153 conformSizes();
154}
155
156template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
158 : _image(rhs._image), _mask(rhs._mask), _variance(rhs._variance) {
159 if (deep) {
160 _image = std::shared_ptr<Image>(new Image(*rhs.getImage(), deep));
161 _mask = std::shared_ptr<Mask>(new Mask(*rhs.getMask(), deep));
162 _variance = std::shared_ptr<Variance>(new Variance(*rhs.getVariance(), deep));
163 }
164 conformSizes();
165}
166
167// Delegate to copy-constructor for backwards compatibility
168template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
171
172template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
174 const lsst::geom::Box2I& bbox,
175 ImageOrigin const origin, bool deep
176
177 )
178 : _image(new Image(*rhs.getImage(), bbox, origin, deep)),
179 _mask(rhs._mask ? new Mask(*rhs.getMask(), bbox, origin, deep) : static_cast<Mask*>(nullptr)),
180 _variance(rhs._variance ? new Variance(*rhs.getVariance(), bbox, origin, deep)
181 : static_cast<Variance*>(nullptr)) {
182 conformSizes();
183}
184
185template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
187operator=(MaskedImage const& rhs) = default;
188
189template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
191operator=(MaskedImage&& rhs) = default;
192
193template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
195 using std::swap; // See Meyers, Effective C++, Item 25
196
197 _image.swap(rhs._image);
198 _mask.swap(rhs._mask);
199 _variance.swap(rhs._variance);
200}
201
202// Operators
203template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
205operator=(MaskedImage::Pixel const& rhs) {
206 *_image = rhs.image();
207 *_mask = rhs.mask();
208 *_variance = rhs.variance();
209
210 return *this;
211}
212
213template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
216 *_image = rhs.image();
217 *_mask = rhs.mask();
218 *_variance = rhs.variance();
219
220 return *this;
221}
222
223template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
225 lsst::geom::Box2I const& bbox,
226 ImageOrigin origin) {
227 _image->assign(*rhs.getImage(), bbox, origin);
228 _mask->assign(*rhs.getMask(), bbox, origin);
229 _variance->assign(*rhs.getVariance(), bbox, origin);
230}
231
232template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
234operator+=(MaskedImage const& rhs) {
235 *_image += *rhs.getImage();
236 *_mask |= *rhs.getMask();
237 *_variance += *rhs.getVariance();
238 return *this;
239}
240
241template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
243 MaskedImage const& rhs) {
244 (*_image).scaledPlus(c, *rhs.getImage());
245 *_mask |= *rhs.getMask();
246 (*_variance).scaledPlus(c * c, *rhs.getVariance());
247}
248
249template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
255
256template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
258operator-=(MaskedImage const& rhs) {
259 *_image -= *rhs.getImage();
260 *_mask |= *rhs.getMask();
261 *_variance += *rhs.getVariance();
262 return *this;
263}
264
265template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
267 MaskedImage const& rhs) {
268 (*_image).scaledMinus(c, *rhs.getImage());
269 *_mask |= *rhs.getMask();
270 (*_variance).scaledPlus(c * c, *rhs.getVariance());
271}
272
273template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
279
280namespace {
282template <typename ImagePixelT, typename VariancePixelT>
283struct productVariance {
284 double operator()(ImagePixelT lhs, ImagePixelT rhs, VariancePixelT varLhs, VariancePixelT varRhs) {
285 return lhs * lhs * varRhs + rhs * rhs * varLhs;
286 }
287};
288
291template <typename ImagePixelT, typename VariancePixelT>
292struct scaledProductVariance {
293 double _c;
294 scaledProductVariance(double const c) : _c(c) {}
295 double operator()(ImagePixelT lhs, ImagePixelT rhs, VariancePixelT varLhs, VariancePixelT varRhs) {
296 return _c * _c * (lhs * lhs * varRhs + rhs * rhs * varLhs);
297 }
298};
299} // namespace
300
301template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
303operator*=(MaskedImage const& rhs) {
304 // Must do variance before we modify the image values
305 if (_image->getDimensions() != rhs._image->getDimensions()) {
307 boost::str(boost::format("Images are of different size, %dx%d v %dx%d") %
308 _image->getWidth() % _image->getHeight() % rhs._image->getWidth() % rhs._image->getHeight()));
309 }
310 transform_pixels(_image->_getRawView(), // lhs
311 rhs._image->_getRawView(), // rhs,
312 _variance->_getRawView(), // Var(lhs),
313 rhs._variance->_getRawView(), // Var(rhs)
314 _variance->_getRawView(), // result
315 productVariance<ImagePixelT, VariancePixelT>());
316
317 *_image *= *rhs.getImage();
318 *_mask |= *rhs.getMask();
319 return *this;
320}
321
322template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
324 MaskedImage const& rhs) {
325 // Must do variance before we modify the image values
326 if (_image->getDimensions() != rhs._image->getDimensions()) {
328 boost::str(boost::format("Images are of different size, %dx%d v %dx%d") %
329 _image->getWidth() % _image->getHeight() % rhs._image->getWidth() % rhs._image->getHeight()));
330 }
331 transform_pixels(_image->_getRawView(), // lhs
332 rhs._image->_getRawView(), // rhs,
333 _variance->_getRawView(), // Var(lhs),
334 rhs._variance->_getRawView(), // Var(rhs)
335 _variance->_getRawView(), // result
336 scaledProductVariance<ImagePixelT, VariancePixelT>(c));
337
338 (*_image).scaledMultiplies(c, *rhs.getImage());
339 *_mask |= *rhs.getMask();
340}
341
342template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
344operator*=(ImagePixelT const rhs) {
345 *_image *= rhs;
346 *_variance *= rhs * rhs;
347 return *this;
348}
349
350namespace {
352template <typename ImagePixelT, typename VariancePixelT>
353struct quotientVariance {
354 double operator()(ImagePixelT lhs, ImagePixelT rhs, VariancePixelT varLhs, VariancePixelT varRhs) {
355 ImagePixelT const rhs2 = rhs * rhs;
356 return (lhs * lhs * varRhs + rhs2 * varLhs) / (rhs2 * rhs2);
357 }
358};
361template <typename ImagePixelT, typename VariancePixelT>
362struct scaledQuotientVariance {
363 double _c;
364 scaledQuotientVariance(double c) : _c(c) {}
365 double operator()(ImagePixelT lhs, ImagePixelT rhs, VariancePixelT varLhs, VariancePixelT varRhs) {
366 ImagePixelT const rhs2 = rhs * rhs;
367 return (lhs * lhs * varRhs + rhs2 * varLhs) / (_c * _c * rhs2 * rhs2);
368 }
369};
370} // namespace
371
372template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
374operator/=(MaskedImage const& rhs) {
375 // Must do variance before we modify the image values
376 if (_image->getDimensions() != rhs._image->getDimensions()) {
378 boost::str(boost::format("Images are of different size, %dx%d v %dx%d") %
379 _image->getWidth() % _image->getHeight() % rhs._image->getWidth() % rhs._image->getHeight()));
380 }
381 transform_pixels(_image->_getRawView(), // lhs
382 rhs._image->_getRawView(), // rhs,
383 _variance->_getRawView(), // Var(lhs),
384 rhs._variance->_getRawView(), // Var(rhs)
385 _variance->_getRawView(), // result
386 quotientVariance<ImagePixelT, VariancePixelT>());
387
388 *_image /= *rhs.getImage();
389 *_mask |= *rhs.getMask();
390 return *this;
391}
392
393template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
395 MaskedImage const& rhs) {
396 // Must do variance before we modify the image values
397 if (_image->getDimensions() != rhs._image->getDimensions()) {
399 str(boost::format("Images are of different size, %dx%d v %dx%d") %
400 _image->getWidth() % _image->getHeight() % rhs._image->getWidth() % rhs._image->getHeight()));
401 }
402 transform_pixels(_image->_getRawView(), // lhs
403 rhs._image->_getRawView(), // rhs,
404 _variance->_getRawView(), // Var(lhs),
405 rhs._variance->_getRawView(), // Var(rhs)
406 _variance->_getRawView(), // result
407 scaledQuotientVariance<ImagePixelT, VariancePixelT>(c));
408
409 (*_image).scaledDivides(c, *rhs.getImage());
410 *_mask |= *rhs._mask;
411}
412
413template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
415operator/=(ImagePixelT const rhs) {
416 *_image /= rhs;
417 *_variance /= rhs * rhs;
418 return *this;
419}
420
421template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
426 std::shared_ptr<daf::base::PropertySet const> varianceMetadata) const {
428 writeFits(fitsfile, metadata, imageMetadata, maskMetadata, varianceMetadata);
429}
430
431template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
436 std::shared_ptr<daf::base::PropertySet const> varianceMetadata) const {
438 writeFits(fitsfile, metadata, imageMetadata, maskMetadata, varianceMetadata);
439}
440
441namespace {
442
443void processPlaneMetadata(daf::base::PropertySet const * metadata,
444 std::shared_ptr<daf::base::PropertySet>& hdr, char const* exttype) {
445 if (metadata) {
446 hdr = metadata->deepCopy();
447 } else {
449 }
450 hdr->set("INHERIT", true);
451 hdr->set("EXTTYPE", exttype);
452 hdr->set("EXTNAME", exttype);
453}
454
455} // namespace
456
457template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
462 std::shared_ptr<daf::base::PropertySet const> varianceMetadata) const {
463 writeFits(fitsfile, fits::ImageWriteOptions(*_image), fits::ImageWriteOptions(*_mask),
464 fits::ImageWriteOptions(*_variance), metadata, imageMetadata, maskMetadata, varianceMetadata);
465}
466
467template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
469 std::string const& fileName, fits::ImageWriteOptions const& imageOptions,
470 fits::ImageWriteOptions const& maskOptions, fits::ImageWriteOptions const& varianceOptions,
474 std::shared_ptr<daf::base::PropertySet const> varianceMetadata) const {
476 writeFits(fitsfile, imageOptions, maskOptions, varianceOptions, metadata, imageMetadata, maskMetadata,
477 varianceMetadata);
478}
479
480template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
482 fits::MemFileManager& manager, fits::ImageWriteOptions const& imageOptions,
483 fits::ImageWriteOptions const& maskOptions, fits::ImageWriteOptions const& varianceOptions,
487 std::shared_ptr<daf::base::PropertySet const> varianceMetadata) const {
489 writeFits(fitsfile, imageOptions, maskOptions, varianceOptions, metadata, imageMetadata, maskMetadata,
490 varianceMetadata);
491}
492
493template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
495 fits::Fits& fitsfile, fits::ImageWriteOptions const& imageOptions,
496 fits::ImageWriteOptions const& maskOptions, fits::ImageWriteOptions const& varianceOptions,
500 std::shared_ptr<daf::base::PropertySet const> varianceMetadata) const {
502 if (metadata) {
503 header = metadata->deepCopy();
504 } else {
505 header = std::make_shared<daf::base::PropertyList>();
506 }
507
508 if (fitsfile.countHdus() != 0) {
510 "MaskedImage::writeFits can only write to an empty file");
511 }
512 if (fitsfile.getHdu() < 1) {
513 // Don't ever write images to primary; instead we make an empty primary.
514 fitsfile.createEmpty();
515 } else {
516 fitsfile.setHdu(0);
517 }
518 fitsfile.writeMetadata(*header);
519
520 processPlaneMetadata(imageMetadata.get(), header, "IMAGE");
521 _image->writeFits(fitsfile, imageOptions, header.get(), _mask.get());
522
523 processPlaneMetadata(maskMetadata.get(), header, "MASK");
524 _mask->writeFits(fitsfile, maskOptions, header.get());
525
526 processPlaneMetadata(varianceMetadata.get(), header, "VARIANCE");
527 _variance->writeFits(fitsfile, varianceOptions, header.get(), _mask.get());
528}
529
530// private function conformSizes() ensures that the Mask and Variance have the same dimensions
531// as Image. If Mask and/or Variance have non-zero dimensions that conflict with the size of Image,
532// a lsst::pex::exceptions::LengthError is thrown.
533
534template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
536 if (!_mask || _mask->getWidth() == 0 || _mask->getHeight() == 0) {
537 _mask = MaskPtr(new Mask(_image->getBBox()));
538 *_mask = 0;
539 } else {
540 if (_mask->getDimensions() != _image->getDimensions()) {
541 throw LSST_EXCEPT(
543 (boost::format("Dimension mismatch: Image %dx%d v. Mask %dx%d") % _image->getWidth() %
544 _image->getHeight() % _mask->getWidth() % _mask->getHeight())
545 .str());
546 }
547 }
548
549 if (!_variance || _variance->getWidth() == 0 || _variance->getHeight() == 0) {
550 _variance = VariancePtr(new Variance(_image->getBBox()));
551 *_variance = 0;
552 } else {
553 if (_variance->getDimensions() != _image->getDimensions()) {
554 throw LSST_EXCEPT(
555 pex::exceptions::LengthError,
556 (boost::format("Dimension mismatch: Image %dx%d v. Variance %dx%d") % _image->getWidth() %
557 _image->getHeight() % _variance->getWidth() % _variance->getHeight())
558 .str());
559 }
560 }
561}
562
563//
564// Iterators and locators
565//
566template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
569#if 0 // this doesn't compile; why?
570 return iterator(_image->begin(), _mask->begin(), _variance->begin());
571#else
572 typename Image::iterator imageBegin = _image->begin();
573 typename Mask::iterator maskBegin = _mask->begin();
574 typename Variance::iterator varianceBegin = _variance->begin();
575
576 return iterator(imageBegin, maskBegin, varianceBegin);
577#endif
578}
580template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
583 typename Image::iterator imageEnd = getImage()->end();
584 typename Mask::iterator maskEnd = getMask()->end();
585 typename Variance::iterator varianceEnd = getVariance()->end();
586
587 return iterator(imageEnd, maskEnd, varianceEnd);
588}
590template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
593 typename Image::iterator imageEnd = getImage()->at(x, y);
594 typename Mask::iterator maskEnd = getMask()->at(x, y);
595 typename Variance::iterator varianceEnd = getVariance()->at(x, y);
596
597 return iterator(imageEnd, maskEnd, varianceEnd);
598}
599
600template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
603 typename Image::reverse_iterator imageBegin = _image->rbegin();
604 typename Mask::reverse_iterator maskBegin = _mask->rbegin();
605 typename Variance::reverse_iterator varianceBegin = _variance->rbegin();
606
607 return reverse_iterator(imageBegin, maskBegin, varianceBegin);
608}
609
610template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
613 typename Image::reverse_iterator imageEnd = getImage()->rend();
614 typename Mask::reverse_iterator maskEnd = getMask()->rend();
615 typename Variance::reverse_iterator varianceEnd = getVariance()->rend();
616
617 return reverse_iterator(imageEnd, maskEnd, varianceEnd);
618}
619
620template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
623 typename Image::x_iterator imageBegin = _image->row_begin(y);
624 typename Mask::x_iterator maskBegin = _mask->row_begin(y);
625 typename Variance::x_iterator varianceBegin = _variance->row_begin(y);
626
627 return x_iterator(imageBegin, maskBegin, varianceBegin);
628}
629
630template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
633 typename Image::x_iterator imageEnd = getImage()->row_end(y);
634 typename Mask::x_iterator maskEnd = getMask()->row_end(y);
635 typename Variance::x_iterator varianceEnd = getVariance()->row_end(y);
636
637 return x_iterator(imageEnd, maskEnd, varianceEnd);
638}
639
640template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
643 typename Image::y_iterator imageBegin = _image->col_begin(x);
644 typename Mask::y_iterator maskBegin = _mask->col_begin(x);
645 typename Variance::y_iterator varianceBegin = _variance->col_begin(x);
646
647 return y_iterator(imageBegin, maskBegin, varianceBegin);
649
650template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
653 typename Image::y_iterator imageEnd = getImage()->col_end(x);
654 typename Mask::y_iterator maskEnd = getMask()->col_end(x);
655 typename Variance::y_iterator varianceEnd = getVariance()->col_end(x);
656
657 return y_iterator(imageEnd, maskEnd, varianceEnd);
658}
659
660template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
663 typename Image::fast_iterator imageBegin = _image->begin(contiguous);
664 typename Mask::fast_iterator maskBegin = _mask->begin(contiguous);
665 typename Variance::fast_iterator varianceBegin = _variance->begin(contiguous);
666
667 return fast_iterator(imageBegin, maskBegin, varianceBegin);
668}
669
670template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
673 typename Image::fast_iterator imageEnd = getImage()->end(contiguous);
674 typename Mask::fast_iterator maskEnd = getMask()->end(contiguous);
675 typename Variance::fast_iterator varianceEnd = getVariance()->end(contiguous);
677 return fast_iterator(imageEnd, maskEnd, varianceEnd);
678}
679
680template <typename ImagePixelT1, typename ImagePixelT2>
683 return imagesOverlap(*image1.getImage(), *image2.getImage()) ||
684 imagesOverlap(*image1.getVariance(), *image2.getVariance()) ||
685 imagesOverlap(*image1.getMask(), *image2.getMask());
686}
687
688//
689// Explicit instantiations
690//
691#define INSTANTIATE2(ImagePixelT1, ImagePixelT2) \
692 template bool imagesOverlap<ImagePixelT1, ImagePixelT2>(MaskedImage<ImagePixelT1> const&, \
693 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:1266
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:1121
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:81
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::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:141
MaskPixelT mask() const
Return the mask part of a Pixel.
Definition Pixel.h:207
ImagePixelT image() const
Return the image part of a Pixel.
Definition Pixel.h:205
VariancePixelT variance() const
Return the variance part of a Pixel.
Definition Pixel.h:209
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
STL namespace.
T reset(T... args)
Options for writing an image to FITS.
Definition fits.h:223
T swap(T... args)
g2d::python::Image< bool > Mask
Definition test_image.cc:16