LSST Applications g1653933729+34a971ddd9,g1a997c3884+34a971ddd9,g2160c40384+da0d0eec6b,g28da252d5a+cb6ff358b6,g2bbee38e9b+e5a1bc5b38,g2bc492864f+e5a1bc5b38,g2ca4be77d2+2af33ed832,g2cdde0e794+704103fe75,g3156d2b45e+6e87dc994a,g347aa1857d+e5a1bc5b38,g35bb328faa+34a971ddd9,g3a166c0a6a+e5a1bc5b38,g3e281a1b8c+8ec26ec694,g4005a62e65+ba0306790b,g414038480c+9f5be647b3,g41af890bb2+f34483f65b,g5065538af8+53fd6e9482,g5a0bb5165c+1b31a0decc,g717e5f8c0f+19a1ad098c,g80478fca09+1acdc24a0d,g8204df1d8d+19a1ad098c,g82479be7b0+44a04e1d61,g858d7b2824+19a1ad098c,g9125e01d80+34a971ddd9,ga5288a1d22+ad6d5da1a4,gae0086650b+34a971ddd9,gb58c049af0+ace264a4f2,gbd397ab92a+d5fd0218dc,gc28159a63d+e5a1bc5b38,gcf0d15dbbd+618cb38075,gd6b7c0dfd1+3388d854ad,gda6a2b7d83+618cb38075,gdaeeff99f8+7774323b41,ge2409df99d+8082276ac0,ge33fd446bb+19a1ad098c,ge79ae78c31+e5a1bc5b38,gf0baf85859+890af219f9,gf5289d68f6+701f7b396a,w.2024.37
LSST Data Management Base Package
Loading...
Searching...
No Matches
Image.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 ImageBase and Image
27 */
28#include <cstdint>
29#include <functional>
30#include "boost/format.hpp"
31#include "boost/gil.hpp"
32
33#include "lsst/pex/exceptions.h"
37#include "lsst/afw/fits.h"
39
40namespace lsst {
41namespace afw {
42namespace image {
43
44template <typename PixelT>
45typename ImageBase<PixelT>::_view_t ImageBase<PixelT>::_allocateView(lsst::geom::Extent2I const& dimensions,
46 Manager::Ptr& manager) {
47 if (dimensions.getX() < 0 || dimensions.getY() < 0) {
49 str(boost::format("Both width and height must be non-negative: %d, %d") %
50 dimensions.getX() % dimensions.getY()));
51 }
52 if (dimensions.getX() != 0 && dimensions.getY() > std::numeric_limits<int>::max() / dimensions.getX()) {
54 str(boost::format("Image dimensions (%d x %d) too large; int overflow detected.") %
55 dimensions.getX() % dimensions.getY()));
56 }
58 ndarray::SimpleManager<PixelT>::allocate(dimensions.getX() * dimensions.getY());
59 manager = r.first;
60 return boost::gil::interleaved_view(dimensions.getX(), dimensions.getY(),
61 (typename _view_t::value_type*)r.second,
62 dimensions.getX() * sizeof(PixelT));
63}
64template <typename PixelT>
65typename ImageBase<PixelT>::_view_t ImageBase<PixelT>::_makeSubView(lsst::geom::Extent2I const& dimensions,
66 lsst::geom::Extent2I const& offset,
67 const _view_t& view) {
68 if (offset.getX() < 0 || offset.getY() < 0 || offset.getX() + dimensions.getX() > view.width() ||
69 offset.getY() + dimensions.getY() > view.height()) {
70 throw LSST_EXCEPT(
72 (boost::format(
73 "Box2I(Point2I(%d,%d),lsst::geom::Extent2I(%d,%d)) doesn't fit in image %dx%d") %
74 offset.getX() % offset.getY() % dimensions.getX() % dimensions.getY() % view.width() %
75 view.height())
76 .str());
77 }
78 if (dimensions.getX() == 0 && dimensions.getY() == 0
79 && view.width() == 0 && view.height() == 0) {
80 // Getting a zero-extent subview of a zero-extent view returns itself
81 return view;
82 } else {
83 return boost::gil::subimage_view(view, offset.getX(), offset.getY(), dimensions.getX(),
84 dimensions.getY());
85 }
86}
88template <typename PixelT>
90 : _origin(0, 0), _manager(), _gilView(_allocateView(dimensions, _manager)) {}
91
92template <typename PixelT>
94 : _origin(bbox.getMin()), _manager(), _gilView(_allocateView(bbox.getDimensions(), _manager)) {}
95
96template <typename PixelT>
98
99 )
100 : _origin(rhs._origin), _manager(rhs._manager), _gilView(rhs._gilView) {
101 if (deep) {
102 ImageBase tmp(getBBox());
103 tmp.assign(*this); // now copy the pixels
104 swap(tmp);
105 }
106}
107// Delegate to copy-constructor for backwards compatibility
108template <typename PixelT>
110
111template <typename PixelT>
113 bool const deep
114
115 )
116 : _origin((origin == PARENT) ? bbox.getMin() : rhs._origin + lsst::geom::Extent2I(bbox.getMin())),
117 _manager(rhs._manager), // reference counted pointer, don't copy pixels
118 _gilView(_makeSubView(bbox.getDimensions(), _origin - rhs._origin, rhs._gilView)) {
119 if (deep) {
121 tmp.assign(*this); // now copy the pixels
122 swap(tmp);
123 }
124}
125
126template <typename PixelT>
128 : _origin(xy0),
129 _manager(array.getManager()),
130 _gilView(boost::gil::interleaved_view(array.template getSize<1>(), array.template getSize<0>(),
131 (typename _view_t::value_type*)array.getData(),
132 array.template getStride<0>() * sizeof(PixelT))) {
133 if (deep) {
134 ImageBase tmp(*this, true);
135 swap(tmp);
136 }
137}
138
139template <typename PixelT>
141 ImageBase tmp(rhs);
142 swap(tmp); // See Meyers, Effective C++, Item 11
143
144 return *this;
145}
146// Delegate to copy-assignment for backwards compatibility
147template <typename PixelT>
149 return *this = rhs;
150}
151
152template <typename PixelT>
154 auto lhsDim = bbox.isEmpty() ? getDimensions() : bbox.getDimensions();
155 if (lhsDim != rhs.getDimensions()) {
157 (boost::format("Dimension mismatch: %dx%d v. %dx%d") % lhsDim.getX() %
158 lhsDim.getY() % rhs.getWidth() % rhs.getHeight())
159 .str());
160 }
161 if (bbox.isEmpty()) {
162 copy_pixels(rhs._gilView, _gilView);
163 } else {
164 auto lhsOff = (origin == PARENT) ? bbox.getMin() - _origin : lsst::geom::Extent2I(bbox.getMin());
165 auto lhsGilView = _makeSubView(lhsDim, lhsOff, _gilView);
166 copy_pixels(rhs._gilView, lhsGilView);
167 }
168}
169
170template <typename PixelT>
172 return const_cast<typename ImageBase<PixelT>::PixelReference>(
173 static_cast<typename ImageBase<PixelT>::PixelConstReference>(_gilView(x, y)[0]));
174}
176template <typename PixelT>
178 CheckIndices const& check) {
179 if (check && (x < 0 || x >= getWidth() || y < 0 || y >= getHeight())) {
181 (boost::format("Index (%d, %d) is out of range [0--%d], [0--%d]") % x % y %
182 (getWidth() - 1) % (getHeight() - 1))
183 .str());
184 }
185
186 return const_cast<typename ImageBase<PixelT>::PixelReference>(
187 static_cast<typename ImageBase<PixelT>::PixelConstReference>(_gilView(x, y)[0]));
188}
189
190template <typename PixelT>
192 return _gilView(x, y)[0];
194
195template <typename PixelT>
197 int x, int y, CheckIndices const& check) const {
198 if (check && (x < 0 || x >= getWidth() || y < 0 || y >= getHeight())) {
200 (boost::format("Index (%d, %d) is out of range [0--%d], [0--%d]") % x % y %
201 (this->getWidth() - 1) % (this->getHeight() - 1))
202 .str());
205 return _gilView(x, y)[0];
206}
207
208template <typename PixelT>
210 ImageOrigin origin) {
211 int x = index.getX();
212 int y = index.getY();
213 if (origin == PARENT) {
214 x -= getX0();
215 y -= getY0();
216 }
217 return _gilView(x, y)[0];
218}
219
220template <typename PixelT>
222 ImageOrigin origin) const {
223 int x = index.getX();
224 int y = index.getY();
225 if (origin == PARENT) {
226 x -= getX0();
227 y -= getY0();
228 }
229 return _gilView(x, y)[0];
230}
231
232template <typename PixelT>
234 using std::swap; // See Meyers, Effective C++, Item 25
235
236 swap(_manager, rhs._manager); // just swapping the pointers
237 swap(_gilView, rhs._gilView);
238 swap(_origin, rhs._origin);
240
241template <typename PixelT>
243 a.swap(b);
244}
245
246//
247// Iterators
248//
249template <typename PixelT>
251 return _gilView.begin();
253
254template <typename PixelT>
256 return _gilView.end();
257}
258
259template <typename PixelT>
261 return _gilView.rbegin();
262}
263
264template <typename PixelT>
266 return _gilView.rend();
268
269template <typename PixelT>
271 return _gilView.at(x, y);
272}
274template <typename PixelT>
276 if (!contiguous) {
277 throw LSST_EXCEPT(pex::exceptions::RuntimeError, "Only contiguous == true makes sense");
278 }
279 if (!this->isContiguous()) {
280 throw LSST_EXCEPT(pex::exceptions::RuntimeError, "Image's pixels are not contiguous");
281 }
283 return row_begin(0);
284}
286template <typename PixelT>
288 if (!contiguous) {
289 throw LSST_EXCEPT(pex::exceptions::RuntimeError, "Only contiguous == true makes sense");
290 }
291 if (!this->isContiguous()) {
292 throw LSST_EXCEPT(pex::exceptions::RuntimeError, "Image's pixels are not contiguous");
293 }
294
295 return row_end(getHeight() - 1);
296}
297
298template <typename PixelT>
300 fill_pixels(_gilView, rhs);
301
302 return *this;
303}
304
305//
306// On to Image itself. ctors, cctors, and operator=
307//
308template <typename PixelT>
309Image<PixelT>::Image(unsigned int width, unsigned int height, PixelT initialValue)
310 : ImageBase<PixelT>(lsst::geom::ExtentI(width, height)) {
311 *this = initialValue;
312}
313
314template <typename PixelT>
316 : ImageBase<PixelT>(dimensions) {
317 *this = initialValue;
318}
319
320template <typename PixelT>
324
325template <typename PixelT>
326Image<PixelT>::Image(Image const& rhs, bool const deep) : ImageBase<PixelT>(rhs, deep) {}
327// Delegate to copy-constructor for backwards compatibility
328template <typename PixelT>
330
331template <typename PixelT>
333 bool const deep)
334 : ImageBase<PixelT>(rhs, bbox, origin, deep) {}
335
336template <typename PixelT>
340 return *this;
342
343template <typename PixelT>
346
347 return *this;
348}
349// Delegate to copy-assignment for backwards compatibility
350template <typename PixelT>
352 return *this = rhs;
354
355#ifndef DOXYGEN // doc for this section has been moved to header
356
357template <typename PixelT>
361 *this = reader.read<PixelT>(bbox, origin, allowUnsafe);
362 if (metadata) {
363 metadata->combine(*reader.readMetadata());
364 }
366
367template <typename PixelT>
368Image<PixelT>::Image(fits::MemFileManager& manager, int const hdu,
370 ImageOrigin const origin, bool allowUnsafe) {
371 ImageFitsReader reader(manager, hdu);
372 *this = reader.read<PixelT>(bbox, origin, allowUnsafe);
373 if (metadata) {
374 metadata->combine(*reader.readMetadata());
378template <typename PixelT>
380 lsst::geom::Box2I const& bbox, ImageOrigin const origin, bool allowUnsafe) {
382 *this = reader.read<PixelT>(bbox, origin, allowUnsafe);
383 if (metadata) {
384 metadata->combine(*reader.readMetadata());
385 }
386}
388template <typename PixelT>
391 std::string const& mode) const {
393 writeFits(fitsfile, metadata_i);
394}
396template <typename PixelT>
399 std::string const& mode) const {
401 writeFits(fitsfile, metadata_i);
402}
403
404
405template <typename PixelT>
407 daf::base::PropertySet const * metadata) const {
408 fitsfile.writeImage(*this, fits::ImageWriteOptions(*this), metadata);
409}
410
411template <typename PixelT>
413 std::string const& mode, daf::base::PropertySet const * header,
414 Mask<MaskPixel> const * mask) const {
415 fits::Fits fitsfile(filename, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
416 writeFits(fitsfile, options, header, mask);
417}
418
419template <typename PixelT>
420void Image<PixelT>::writeFits(fits::MemFileManager& manager, fits::ImageWriteOptions const& options,
421 std::string const& mode, daf::base::PropertySet const * header,
422 Mask<MaskPixel> const * mask) const {
423 fits::Fits fitsfile(manager, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
424 writeFits(fitsfile, options, header, mask);
425}
426
427template <typename PixelT>
428void Image<PixelT>::writeFits(fits::Fits& fitsfile, fits::ImageWriteOptions const& options,
429 daf::base::PropertySet const * header,
430 Mask<MaskPixel> const * mask) const {
431 fitsfile.writeImage(*this, options, header, mask);
432}
433
434#endif // !DOXYGEN
435
436template <typename PixelT>
438 using std::swap; // See Meyers, Effective C++, Item 25
440}
441
442template <typename PixelT>
444 a.swap(b);
445}
446
447// In-place, per-pixel, sqrt().
448template <typename PixelT>
450 transform_pixels(_getRawView(), _getRawView(),
451 [](PixelT const& l) -> PixelT { return static_cast<PixelT>(std::sqrt(l)); });
452}
453
454template <typename PixelT>
456 transform_pixels(_getRawView(), _getRawView(), [&rhs](PixelT const& l) -> PixelT { return l + rhs; });
457 return *this;
458}
459
460template <typename PixelT>
462 if (this->getDimensions() != rhs.getDimensions()) {
464 (boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
465 this->getHeight() % rhs.getWidth() % rhs.getHeight())
466 .str());
467 }
468 transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(),
469 [](PixelT const& l, PixelT const& r) -> PixelT { return l + r; });
470 return *this;
471}
472
473template <typename PixelT>
475 for (int y = 0; y != this->getHeight(); ++y) {
476 double const yPos = this->indexToPosition(y, Y);
477 double xPos = this->indexToPosition(0, X);
478 for (typename Image<PixelT>::x_iterator ptr = this->row_begin(y), end = this->row_end(y); ptr != end;
479 ++ptr, ++xPos) {
480 *ptr += function(xPos, yPos);
481 }
482 }
483 return *this;
484}
485
486template <typename PixelT>
487void Image<PixelT>::scaledPlus(PixelT const c, Image<PixelT> const& rhs) {
488 if (this->getDimensions() != rhs.getDimensions()) {
490 (boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
491 this->getHeight() % rhs.getWidth() % rhs.getHeight())
492 .str());
493 }
495 _getRawView(), rhs._getRawView(), _getRawView(),
496 [&c](PixelT const& l, PixelT const& r) -> PixelT { return l + (c * r); });
497}
498
499template <typename PixelT>
501 transform_pixels(_getRawView(), _getRawView(), [&rhs](PixelT const& l) -> PixelT { return l - rhs; });
502 return *this;
503}
504
505template <typename PixelT>
507 if (this->getDimensions() != rhs.getDimensions()) {
509 (boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
510 this->getHeight() % rhs.getWidth() % rhs.getHeight())
511 .str());
512 }
513 transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(),
514 [](PixelT const& l, PixelT const& r) -> PixelT { return l - r; });
515 return *this;
516}
517
518template <typename PixelT>
519void Image<PixelT>::scaledMinus(PixelT const c, Image<PixelT> const& rhs) {
520 if (this->getDimensions() != rhs.getDimensions()) {
522 (boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
523 this->getHeight() % rhs.getWidth() % rhs.getHeight())
524 .str());
525 }
527 _getRawView(), rhs._getRawView(), _getRawView(),
528 [&c](PixelT const& l, PixelT const& r) -> PixelT { return l - (c * r); });
529}
530
531template <typename PixelT>
533 for (int y = 0; y != this->getHeight(); ++y) {
534 double const yPos = this->indexToPosition(y, Y);
535 double xPos = this->indexToPosition(0, X);
536 for (typename Image<PixelT>::x_iterator ptr = this->row_begin(y), end = this->row_end(y); ptr != end;
537 ++ptr, ++xPos) {
538 *ptr -= function(xPos, yPos);
539 }
540 }
541 return *this;
542}
543
544template <typename PixelT>
546 transform_pixels(_getRawView(), _getRawView(), [&rhs](PixelT const& l) -> PixelT { return l * rhs; });
547 return *this;
548}
549
550template <typename PixelT>
552 if (this->getDimensions() != rhs.getDimensions()) {
554 (boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
555 this->getHeight() % rhs.getWidth() % rhs.getHeight())
556 .str());
557 }
558 transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(),
559 [](PixelT const& l, PixelT const& r) -> PixelT { return l * r; });
560 return *this;
561}
562
563template <typename PixelT>
565 if (this->getDimensions() != rhs.getDimensions()) {
567 (boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
568 this->getHeight() % rhs.getWidth() % rhs.getHeight())
569 .str());
570 }
572 _getRawView(), rhs._getRawView(), _getRawView(),
573 [&c](PixelT const& l, PixelT const& r) -> PixelT { return l * (c * r); });
574}
575
576template <typename PixelT>
578 transform_pixels(_getRawView(), _getRawView(), [&rhs](PixelT const& l) -> PixelT { return l / rhs; });
579 return *this;
580}
581//
582// Specialize float and double for efficiency
583//
584template <>
586 double const irhs = 1 / rhs;
587 *this *= irhs;
588 return *this;
589}
590
591template <>
593 float const irhs = 1 / rhs;
594 *this *= irhs;
595 return *this;
596}
597
598template <typename PixelT>
600 if (this->getDimensions() != rhs.getDimensions()) {
602 (boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
603 this->getHeight() % rhs.getWidth() % rhs.getHeight())
604 .str());
605 }
606 transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(),
607 [](PixelT const& l, PixelT const& r) -> PixelT { return l / r; });
608 return *this;
609}
610
611template <typename PixelT>
613 if (this->getDimensions() != rhs.getDimensions()) {
615 (boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
616 this->getHeight() % rhs.getWidth() % rhs.getHeight())
617 .str());
618 }
620 _getRawView(), rhs._getRawView(), _getRawView(),
621 [&c](PixelT const& l, PixelT const& r) -> PixelT { return l / (c * r); });
622}
623
624namespace {
625/*
626 * Worker routine for manipulating images;
627 */
628template <typename LhsPixelT, typename RhsPixelT>
629struct plusEq : public pixelOp2<LhsPixelT, RhsPixelT> {
630 LhsPixelT operator()(LhsPixelT lhs, RhsPixelT rhs) const override {
631 return static_cast<LhsPixelT>(lhs + rhs);
632 }
633};
634
635template <typename LhsPixelT, typename RhsPixelT>
636struct minusEq : public pixelOp2<LhsPixelT, RhsPixelT> {
637 LhsPixelT operator()(LhsPixelT lhs, RhsPixelT rhs) const override {
638 return static_cast<LhsPixelT>(lhs - rhs);
639 }
640};
641
642template <typename LhsPixelT, typename RhsPixelT>
643struct timesEq : public pixelOp2<LhsPixelT, RhsPixelT> {
644 LhsPixelT operator()(LhsPixelT lhs, RhsPixelT rhs) const override {
645 return static_cast<LhsPixelT>(lhs * rhs);
646 }
647};
648
649template <typename LhsPixelT, typename RhsPixelT>
650struct divideEq : public pixelOp2<LhsPixelT, RhsPixelT> {
651 LhsPixelT operator()(LhsPixelT lhs, RhsPixelT rhs) const override {
652 return static_cast<LhsPixelT>(lhs / rhs);
653 }
654};
655} // namespace
656
657template <typename LhsPixelT, typename RhsPixelT>
659 for_each_pixel(lhs, rhs, plusEq<LhsPixelT, RhsPixelT>());
660 return lhs;
661}
662
663template <typename LhsPixelT, typename RhsPixelT>
665 for_each_pixel(lhs, rhs, minusEq<LhsPixelT, RhsPixelT>());
666 return lhs;
667}
668
669template <typename LhsPixelT, typename RhsPixelT>
671 for_each_pixel(lhs, rhs, timesEq<LhsPixelT, RhsPixelT>());
672 return lhs;
673}
674
675template <typename LhsPixelT, typename RhsPixelT>
677 for_each_pixel(lhs, rhs, divideEq<LhsPixelT, RhsPixelT>());
678 return lhs;
679}
680
683 if (metadata.exists("ZNAXIS1") && metadata.exists("ZNAXIS2")) {
684 dims = lsst::geom::Extent2I(metadata.getAsInt("ZNAXIS1"), metadata.getAsInt("ZNAXIS2"));
685 } else {
686 dims = lsst::geom::Extent2I(metadata.getAsInt("NAXIS1"), metadata.getAsInt("NAXIS2"));
687 }
688 lsst::geom::Point2I xy0 = geom::getImageXY0FromMetadata(metadata, detail::wcsNameForXY0);
689 return lsst::geom::Box2I(xy0, dims);
690}
691
692template <typename T1, typename T2>
693bool imagesOverlap(ImageBase<T1> const& image1, ImageBase<T2> const& image2) {
694
695 if (image1.getArea() == 0 || image2.getArea() == 0) {
696 // zero-area images cannot overlap.
697 return false;
698 }
699
700 auto arr1 = image1.getArray();
701 // get the address of the first and one-past-the-last element of arr1 using ndarray iterators;
702 // this works because the iterators for contiguous 1-d ndarray Arrays are just pointers
703 auto beg1Addr = arr1.front().begin();
704 auto end1Addr = arr1.back().end();
705
706 auto arr2 = image2.getArray();
707 auto beg2Addr = arr2.front().begin();
708 auto end2Addr = arr2.back().end();
709
710 auto ptrLess = std::less<void const* const>();
711 return ptrLess(beg1Addr, end2Addr) && ptrLess(beg2Addr, end1Addr);
712}
713
714//
715// Explicit instantiations
716//
718#define INSTANTIATE_OPERATOR(OP_EQ, T) \
719 template Image<T>& operator OP_EQ(Image<T>& lhs, Image<std::uint16_t> const& rhs); \
720 template Image<T>& operator OP_EQ(Image<T>& lhs, Image<int> const& rhs); \
721 template Image<T>& operator OP_EQ(Image<T>& lhs, Image<float> const& rhs); \
722 template Image<T>& operator OP_EQ(Image<T>& lhs, Image<double> const& rhs); \
723 template Image<T>& operator OP_EQ(Image<T>& lhs, Image<std::uint64_t> const& rhs);
724
725#define INSTANTIATE(T) \
726 template class ImageBase<T>; \
727 template class Image<T>; \
728 INSTANTIATE_OPERATOR(+=, T); \
729 INSTANTIATE_OPERATOR(-=, T); \
730 INSTANTIATE_OPERATOR(*=, T); \
731 INSTANTIATE_OPERATOR(/=, T)
732
733#define INSTANTIATE2(T1, T2) template bool imagesOverlap<T1, T2>(ImageBase<T1> const&, ImageBase<T2> const&);
734
736INSTANTIATE(int);
737INSTANTIATE(float);
738INSTANTIATE(double);
740
746
748INSTANTIATE2(int, int);
749INSTANTIATE2(int, float);
750INSTANTIATE2(int, double);
752
754INSTANTIATE2(float, int);
755INSTANTIATE2(float, float);
756INSTANTIATE2(float, double);
758
760INSTANTIATE2(double, int);
761INSTANTIATE2(double, float);
762INSTANTIATE2(double, double);
764
770
772} // namespace image
773} // namespace afw
774} // namespace lsst
AmpInfoBoxKey bbox
Definition Amplifier.cc:117
int end
#define INSTANTIATE(FROMSYS, TOSYS)
Definition Detector.cc:509
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48
afw::table::Key< afw::table::Array< MaskPixelT > > mask
#define INSTANTIATE2(ImagePixelT1, ImagePixelT2)
std::uint64_t * ptr
Definition RangeSet.cc:95
int y
Definition SpanSet.cc:48
table::Key< int > b
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition fits.h:308
void writeImage(ndarray::Array< T const, N, C > const &array)
Write an ndarray::Array to a FITS image HDU.
Definition fits.h:498
Lifetime-management for memory that goes into FITS memory files.
Definition fits.h:125
A class used to request that array accesses be checked.
Definition ImageBase.h:74
The base class for all image classed (Image, Mask, MaskedImage, ...)
Definition ImageBase.h:102
iterator end() const
Return an STL compliant iterator to the end of the image.
Definition Image.cc:255
iterator begin() const
Return an STL compliant iterator to the start of the image.
Definition Image.cc:250
static _view_t _allocateView(lsst::geom::Extent2I const &dimensions, Manager::Ptr &manager)
Definition Image.cc:45
typename Reference< PixelT >::type PixelReference
A Reference to a PixelT.
Definition ImageBase.h:117
typename _view_t::iterator iterator
An STL compliant iterator.
Definition ImageBase.h:125
PixelReference operator()(int x, int y)
Return a reference to the pixel (x, y) in LOCAL coordinates.
Definition Image.cc:171
static _view_t _makeSubView(lsst::geom::Extent2I const &dimensions, lsst::geom::Extent2I const &offset, const _view_t &view)
Definition Image.cc:65
int getWidth() const
Return the number of columns in the image.
Definition ImageBase.h:294
lsst::geom::Box2I getBBox(ImageOrigin origin=PARENT) const
Definition ImageBase.h:445
int getArea() const
Return the area of the image.
Definition ImageBase.h:298
lsst::geom::Extent2I getDimensions() const
Return the image's size; useful for passing to constructors.
Definition ImageBase.h:356
typename ndarray::Array< PixelT, 2, 1 > Array
A mutable ndarray representation of the image.
Definition ImageBase.h:149
void assign(ImageBase const &rhs, lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT)
Copy pixels from another image to a specified subregion of this image.
Definition Image.cc:153
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
ImageBase & operator=(const ImageBase &rhs)
Shallow assignment operator.
Definition Image.cc:140
iterator at(int x, int y) const
Return an STL compliant iterator at the point (x, y)
Definition Image.cc:270
reverse_iterator rbegin() const
Return an STL compliant reverse iterator to the start of the image.
Definition Image.cc:260
_view_t _getRawView() const
Definition ImageBase.h:465
PixelReference get(lsst::geom::Point2I const &index, ImageOrigin origin)
Return a reference to a single pixel (with no bounds check).
Definition Image.cc:209
void swap(ImageBase &rhs)
Definition Image.cc:233
typename ConstReference< PixelT >::type PixelConstReference
A ConstReference to a PixelT.
Definition ImageBase.h:119
reverse_iterator rend() const
Return an STL compliant reverse iterator to the end of the image.
Definition Image.cc:265
A FITS reader class for regular Images.
A class to represent a 2-dimensional array of pixels.
Definition Image.h:51
A Function taking two arguments.
Definition Function.h:259
Class for storing generic metadata.
Definition PropertySet.h:66
int getAsInt(std::string const &name) const
Get the last value for a bool/char/short/int property name (possibly hierarchical).
bool exists(std::string const &name) const
Determine if a name (possibly hierarchical) exists.
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 that are due to events beyond the control of the program.
Definition Runtime.h:104
std::string const wcsNameForXY0
Definition ImageBase.h:70
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:658
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:664
void for_each_pixel(Image< LhsT > &lhs, pixelOp0< LhsT > const &func)
Set each pixel in an Image<LhsT> to func()
lsst::geom::Box2I bboxFromMetadata(daf::base::PropertySet &metadata)
Determine the image bounding box from its metadata (FITS header)
Definition Image.cc:681
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:676
double indexToPosition(double ind)
Convert image index to image position.
Definition ImageUtils.h:55
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:670
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
void swap(Image< PixelT > &a, Image< PixelT > &b)
Definition Image.cc:443
Extent< int, 2 > Extent2I
Definition Extent.h:397
T sqrt(T... args)
Options for writing an image to FITS.
Definition fits.h:223
A functor class equivalent to std::function<LhsT (LhsT, RhsT)>, but with a virtual operator()
T swap(T... args)
g2d::python::Image< double > Image
Definition test_image.cc:14
g2d::python::Image< bool > Mask
Definition test_image.cc:16