lsst.afw  16.0-10-gd1b3a1c94
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 <iostream>
30 #include <functional>
31 #include <type_traits>
32 #include "boost/mpl/vector.hpp"
33 #pragma clang diagnostic push
34 #pragma clang diagnostic ignored "-Wunused-variable"
35 #pragma clang diagnostic pop
36 #include "boost/format.hpp"
37 #include "boost/filesystem/path.hpp"
38 #include "boost/gil/gil_all.hpp"
39 
40 #include "lsst/pex/exceptions.h"
41 #include "lsst/afw/geom/wcsUtils.h"
42 #include "lsst/afw/image/Image.h"
44 #include "lsst/afw/fits.h"
47 
48 namespace lsst {
49 namespace afw {
50 namespace image {
51 
52 template <typename PixelT>
53 typename ImageBase<PixelT>::_view_t ImageBase<PixelT>::_allocateView(lsst::geom::Extent2I const& dimensions,
54  Manager::Ptr& manager) {
55  if (dimensions.getX() < 0 || dimensions.getY() < 0) {
57  str(boost::format("Both width and height must be non-negative: %d, %d") %
58  dimensions.getX() % dimensions.getY()));
59  }
60  if (dimensions.getX() != 0 && dimensions.getY() > std::numeric_limits<int>::max() / dimensions.getX()) {
62  str(boost::format("Image dimensions (%d x %d) too large; int overflow detected.") %
63  dimensions.getX() % dimensions.getY()));
64  }
66  ndarray::SimpleManager<PixelT>::allocate(dimensions.getX() * dimensions.getY());
67  manager = r.first;
68  return boost::gil::interleaved_view(dimensions.getX(), dimensions.getY(),
69  (typename _view_t::value_type*)r.second,
70  dimensions.getX() * sizeof(PixelT));
71 }
72 template <typename PixelT>
73 typename ImageBase<PixelT>::_view_t ImageBase<PixelT>::_makeSubView(lsst::geom::Extent2I const& dimensions,
74  lsst::geom::Extent2I const& offset,
75  const _view_t& view) {
76  if (offset.getX() < 0 || offset.getY() < 0 || offset.getX() + dimensions.getX() > view.width() ||
77  offset.getY() + dimensions.getY() > view.height()) {
78  throw LSST_EXCEPT(
80  (boost::format(
81  "Box2I(Point2I(%d,%d),lsst::geom::Extent2I(%d,%d)) doesn't fit in image %dx%d") %
82  offset.getX() % offset.getY() % dimensions.getX() % dimensions.getY() % view.width() %
83  view.height())
84  .str());
85  }
86  return boost::gil::subimage_view(view, offset.getX(), offset.getY(), dimensions.getX(),
87  dimensions.getY());
88 }
89 
90 template <typename PixelT>
92  : daf::base::Citizen(typeid(this)),
93  _origin(0, 0),
94  _manager(),
95  _gilView(_allocateView(dimensions, _manager)) {}
96 
97 template <typename PixelT>
99  : daf::base::Citizen(typeid(this)),
100  _origin(bbox.getMin()),
101  _manager(),
102  _gilView(_allocateView(bbox.getDimensions(), _manager)) {}
103 
104 template <typename PixelT>
105 ImageBase<PixelT>::ImageBase(ImageBase const& rhs, bool const deep
106 
107  )
108  : daf::base::Citizen(typeid(this)),
109  _origin(rhs._origin),
110  _manager(rhs._manager),
111  _gilView(rhs._gilView) {
112  if (deep) {
113  ImageBase tmp(getBBox());
114  tmp.assign(*this); // now copy the pixels
115  swap(tmp);
116  }
117 }
118 // Delegate to copy-constructor for backwards compatibility
119 template <typename PixelT>
121 
122 template <typename PixelT>
124  bool const deep
125 
126  )
127  : daf::base::Citizen(typeid(this)),
128  _origin((origin == PARENT) ? bbox.getMin() : rhs._origin + lsst::geom::Extent2I(bbox.getMin())),
129  _manager(rhs._manager), // reference counted pointer, don't copy pixels
130  _gilView(_makeSubView(bbox.getDimensions(), _origin - rhs._origin, rhs._gilView)) {
131  if (deep) {
132  ImageBase tmp(getBBox());
133  tmp.assign(*this); // now copy the pixels
134  swap(tmp);
135  }
136 }
137 
138 template <typename PixelT>
139 ImageBase<PixelT>::ImageBase(Array const& array, bool deep, lsst::geom::Point2I const& xy0)
140  : daf::base::Citizen(typeid(this)),
141  _origin(xy0),
142  _manager(array.getManager()),
143  _gilView(boost::gil::interleaved_view(array.template getSize<1>(), array.template getSize<0>(),
144  (typename _view_t::value_type*)array.getData(),
145  array.template getStride<0>() * sizeof(PixelT))) {
146  if (deep) {
147  ImageBase tmp(*this, true);
148  swap(tmp);
149  }
150 }
151 
152 template <typename PixelT>
154  ImageBase tmp(rhs);
155  swap(tmp); // See Meyers, Effective C++, Item 11
156 
157  return *this;
158 }
159 // Delegate to copy-assignment for backwards compatibility
160 template <typename PixelT>
162  return *this = rhs;
163 }
164 
165 template <typename PixelT>
167  assign(rhs);
168  return *this;
169 }
170 
171 template <typename PixelT>
173  auto lhsDim = bbox.isEmpty() ? getDimensions() : bbox.getDimensions();
174  if (lhsDim != rhs.getDimensions()) {
176  (boost::format("Dimension mismatch: %dx%d v. %dx%d") % lhsDim.getX() %
177  lhsDim.getY() % rhs.getWidth() % rhs.getHeight())
178  .str());
179  }
180  if (bbox.isEmpty()) {
181  copy_pixels(rhs._gilView, _gilView);
182  } else {
183  auto lhsOff = (origin == PARENT) ? bbox.getMin() - _origin : lsst::geom::Extent2I(bbox.getMin());
184  auto lhsGilView = _makeSubView(lhsDim, lhsOff, _gilView);
185  copy_pixels(rhs._gilView, lhsGilView);
186  }
187 }
188 
189 template <typename PixelT>
191  return const_cast<typename ImageBase<PixelT>::PixelReference>(
192  static_cast<typename ImageBase<PixelT>::PixelConstReference>(_gilView(x, y)[0]));
193 }
194 
195 template <typename PixelT>
197  CheckIndices const& check) {
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  (getWidth() - 1) % (getHeight() - 1))
202  .str());
203  }
204 
205  return const_cast<typename ImageBase<PixelT>::PixelReference>(
206  static_cast<typename ImageBase<PixelT>::PixelConstReference>(_gilView(x, y)[0]));
207 }
208 
209 template <typename PixelT>
211  return _gilView(x, y)[0];
212 }
213 
214 template <typename PixelT>
216  int x, int y, CheckIndices const& check) const {
217  if (check && (x < 0 || x >= getWidth() || y < 0 || y >= getHeight())) {
219  (boost::format("Index (%d, %d) is out of range [0--%d], [0--%d]") % x % y %
220  (this->getWidth() - 1) % (this->getHeight() - 1))
221  .str());
222  }
223 
224  return _gilView(x, y)[0];
225 }
226 
227 template <typename PixelT>
229  using std::swap; // See Meyers, Effective C++, Item 25
230 
231  swap(_manager, rhs._manager); // just swapping the pointers
232  swap(_gilView, rhs._gilView);
233  swap(_origin, rhs._origin);
234 }
235 
236 template <typename PixelT>
238  a.swap(b);
239 }
240 
241 //
242 // Iterators
243 //
244 template <typename PixelT>
246  return _gilView.begin();
247 }
248 
249 template <typename PixelT>
251  return _gilView.end();
252 }
253 
254 template <typename PixelT>
256  return _gilView.rbegin();
257 }
258 
259 template <typename PixelT>
261  return _gilView.rend();
262 }
263 
264 template <typename PixelT>
266  return _gilView.at(x, y);
267 }
268 
269 template <typename PixelT>
271  if (!contiguous) {
272  throw LSST_EXCEPT(pex::exceptions::RuntimeError, "Only contiguous == true makes sense");
273  }
274  if (!this->isContiguous()) {
275  throw LSST_EXCEPT(pex::exceptions::RuntimeError, "Image's pixels are not contiguous");
276  }
277 
278  return row_begin(0);
279 }
280 
281 template <typename PixelT>
283  if (!contiguous) {
284  throw LSST_EXCEPT(pex::exceptions::RuntimeError, "Only contiguous == true makes sense");
285  }
286  if (!this->isContiguous()) {
287  throw LSST_EXCEPT(pex::exceptions::RuntimeError, "Image's pixels are not contiguous");
288  }
289 
290  return row_end(getHeight() - 1);
291 }
292 
293 template <typename PixelT>
295  fill_pixels(_gilView, rhs);
296 
297  return *this;
298 }
299 
300 //
301 // On to Image itself. ctors, cctors, and operator=
302 //
303 template <typename PixelT>
304 Image<PixelT>::Image(unsigned int width, unsigned int height, PixelT initialValue)
305  : ImageBase<PixelT>(lsst::geom::ExtentI(width, height)) {
306  *this = initialValue;
307 }
308 
309 template <typename PixelT>
311  : ImageBase<PixelT>(dimensions) {
312  *this = initialValue;
313 }
314 
315 template <typename PixelT>
316 Image<PixelT>::Image(lsst::geom::Box2I const& bbox, PixelT initialValue) : ImageBase<PixelT>(bbox) {
317  *this = initialValue;
318 }
319 
320 template <typename PixelT>
321 Image<PixelT>::Image(Image const& rhs, bool const deep) : ImageBase<PixelT>(rhs, deep) {}
322 // Delegate to copy-constructor for backwards compatibility
323 template <typename PixelT>
324 Image<PixelT>::Image(Image&& rhs) : Image(rhs, false) {}
325 
326 template <typename PixelT>
328  bool const deep)
329  : ImageBase<PixelT>(rhs, bbox, origin, deep) {}
330 
331 template <typename PixelT>
333  this->ImageBase<PixelT>::operator=(rhs);
334 
335  return *this;
336 }
337 
338 template <typename PixelT>
340  this->ImageBase<PixelT>::operator=(rhs);
341 
342  return *this;
343 }
344 // Delegate to copy-assignment for backwards compatibility
345 template <typename PixelT>
347  return *this = rhs;
348 }
349 
350 #ifndef DOXYGEN // doc for this section has been moved to header
351 
352 template <typename PixelT>
354  lsst::geom::Box2I const& bbox, ImageOrigin origin)
355  : ImageBase<PixelT>() {
356  fits::Fits fitsfile(fileName, "r", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
357  fitsfile.setHdu(hdu);
358  try {
359  *this = Image(fitsfile, metadata, bbox, origin);
360  } catch (fits::FitsError& e) {
361  fitsfile.status = 0; // reset so we can read NAXIS
362  if (fitsfile.getImageDim() == 0) { // no pixels to read
363  LSST_EXCEPT_ADD(e, str(boost::format("HDU %d has NAXIS == 0") % hdu));
364  }
365  throw e;
366  }
367 }
368 template <typename PixelT>
369 Image<PixelT>::Image(fits::MemFileManager& manager, int const hdu,
371  ImageOrigin const origin)
372  : ImageBase<PixelT>() {
373  fits::Fits fitsfile(manager, "r", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
374  fitsfile.setHdu(hdu);
375  *this = Image(fitsfile, metadata, bbox, origin);
376 }
377 
378 template <typename PixelT>
380  lsst::geom::Box2I const& bbox, ImageOrigin const origin)
381  : ImageBase<PixelT>() {
382  typedef boost::mpl::vector<unsigned char, unsigned short, short, int, unsigned int, float, double,
384  fits_image_types;
385 
386  if (!metadata) {
387  metadata.reset(new daf::base::PropertyList());
388  }
389 
390  fits_read_image<fits_image_types>(fitsfile, *this, *metadata, bbox, origin);
391 }
392 
393 template <typename PixelT>
394 void Image<PixelT>::writeFits(std::string const& fileName,
396  std::string const& mode) const {
397  fits::Fits fitsfile(fileName, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
398  writeFits(fitsfile, metadata_i);
399 }
400 
401 template <typename PixelT>
404  std::string const& mode) const {
405  fits::Fits fitsfile(manager, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
406  writeFits(fitsfile, metadata_i);
407 }
408 
409 template <typename PixelT>
410 void Image<PixelT>::writeFits(fits::Fits& fitsfile,
412  fitsfile.writeImage(*this, fits::ImageWriteOptions(*this), metadata);
413 }
414 
415 template <typename PixelT>
418  std::shared_ptr<Mask<MaskPixel> const> mask) const {
419  fits::Fits fitsfile(filename, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
420  writeFits(fitsfile, options, header, mask);
421 }
422 
423 template <typename PixelT>
426  std::shared_ptr<Mask<MaskPixel> const> mask) const {
427  fits::Fits fitsfile(manager, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
428  writeFits(fitsfile, options, header, mask);
429 }
430 
431 template <typename PixelT>
432 void Image<PixelT>::writeFits(fits::Fits& fitsfile, fits::ImageWriteOptions const& options,
434  std::shared_ptr<Mask<MaskPixel> const> mask) const {
435  fitsfile.writeImage(*this, options, header, mask);
436 }
437 
438 #endif // !DOXYGEN
439 
440 template <typename PixelT>
442  using std::swap; // See Meyers, Effective C++, Item 25
444  ; // no private variables to swap
445 }
446 
447 template <typename PixelT>
449  a.swap(b);
450 }
451 
452 // In-place, per-pixel, sqrt().
453 template <typename PixelT>
455  transform_pixels(_getRawView(), _getRawView(),
456  [](PixelT const& l) -> PixelT { return static_cast<PixelT>(std::sqrt(l)); });
457 }
458 
459 template <typename PixelT>
461  transform_pixels(_getRawView(), _getRawView(), [&rhs](PixelT const& l) -> PixelT { return l + rhs; });
462  return *this;
463 }
464 
465 template <typename PixelT>
467  if (this->getDimensions() != rhs.getDimensions()) {
469  (boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
470  this->getHeight() % rhs.getWidth() % rhs.getHeight())
471  .str());
472  }
473  transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(),
474  [](PixelT const& l, PixelT const& r) -> PixelT { return l + r; });
475  return *this;
476 }
477 
478 template <typename PixelT>
480  for (int y = 0; y != this->getHeight(); ++y) {
481  double const yPos = this->indexToPosition(y, Y);
482  double xPos = this->indexToPosition(0, X);
483  for (typename Image<PixelT>::x_iterator ptr = this->row_begin(y), end = this->row_end(y); ptr != end;
484  ++ptr, ++xPos) {
485  *ptr += function(xPos, yPos);
486  }
487  }
488  return *this;
489 }
490 
491 template <typename PixelT>
492 void Image<PixelT>::scaledPlus(double const c, Image<PixelT> const& rhs) {
493  if (this->getDimensions() != rhs.getDimensions()) {
495  (boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
496  this->getHeight() % rhs.getWidth() % rhs.getHeight())
497  .str());
498  }
499  transform_pixels(
500  _getRawView(), rhs._getRawView(), _getRawView(),
501  [&c](PixelT const& l, PixelT const& r) -> PixelT { return l + static_cast<PixelT>(c * r); });
502 }
503 
504 template <typename PixelT>
506  transform_pixels(_getRawView(), _getRawView(), [&rhs](PixelT const& l) -> PixelT { return l - rhs; });
507  return *this;
508 }
509 
510 template <typename PixelT>
512  if (this->getDimensions() != rhs.getDimensions()) {
514  (boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
515  this->getHeight() % rhs.getWidth() % rhs.getHeight())
516  .str());
517  }
518  transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(),
519  [](PixelT const& l, PixelT const& r) -> PixelT { return l - r; });
520  return *this;
521 }
522 
523 template <typename PixelT>
524 void Image<PixelT>::scaledMinus(double const c, Image<PixelT> const& rhs) {
525  if (this->getDimensions() != rhs.getDimensions()) {
527  (boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
528  this->getHeight() % rhs.getWidth() % rhs.getHeight())
529  .str());
530  }
531  transform_pixels(
532  _getRawView(), rhs._getRawView(), _getRawView(),
533  [&c](PixelT const& l, PixelT const& r) -> PixelT { return l - static_cast<PixelT>(c * r); });
534 }
535 
536 template <typename PixelT>
538  for (int y = 0; y != this->getHeight(); ++y) {
539  double const yPos = this->indexToPosition(y, Y);
540  double xPos = this->indexToPosition(0, X);
541  for (typename Image<PixelT>::x_iterator ptr = this->row_begin(y), end = this->row_end(y); ptr != end;
542  ++ptr, ++xPos) {
543  *ptr -= function(xPos, yPos);
544  }
545  }
546  return *this;
547 }
548 
549 template <typename PixelT>
551  transform_pixels(_getRawView(), _getRawView(), [&rhs](PixelT const& l) -> PixelT { return l * rhs; });
552  return *this;
553 }
554 
555 template <typename PixelT>
557  if (this->getDimensions() != rhs.getDimensions()) {
559  (boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
560  this->getHeight() % rhs.getWidth() % rhs.getHeight())
561  .str());
562  }
563  transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(),
564  [](PixelT const& l, PixelT const& r) -> PixelT { return l * r; });
565  return *this;
566 }
567 
568 template <typename PixelT>
569 void Image<PixelT>::scaledMultiplies(double const c, Image<PixelT> const& rhs) {
570  if (this->getDimensions() != rhs.getDimensions()) {
572  (boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
573  this->getHeight() % rhs.getWidth() % rhs.getHeight())
574  .str());
575  }
576  transform_pixels(
577  _getRawView(), rhs._getRawView(), _getRawView(),
578  [&c](PixelT const& l, PixelT const& r) -> PixelT { return l * static_cast<PixelT>(c * r); });
579 }
580 
581 template <typename PixelT>
583  transform_pixels(_getRawView(), _getRawView(), [&rhs](PixelT const& l) -> PixelT { return l / rhs; });
584  return *this;
585 }
586 //
587 // Specialize float and double for efficiency
588 //
589 template <>
591  double const irhs = 1 / rhs;
592  *this *= irhs;
593  return *this;
594 }
595 
596 template <>
598  float const irhs = 1 / rhs;
599  *this *= irhs;
600  return *this;
601 }
602 
603 template <typename PixelT>
605  if (this->getDimensions() != rhs.getDimensions()) {
607  (boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
608  this->getHeight() % rhs.getWidth() % rhs.getHeight())
609  .str());
610  }
611  transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(),
612  [](PixelT const& l, PixelT const& r) -> PixelT { return l / r; });
613  return *this;
614 }
615 
616 template <typename PixelT>
617 void Image<PixelT>::scaledDivides(double const c, Image<PixelT> const& rhs) {
618  if (this->getDimensions() != rhs.getDimensions()) {
620  (boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
621  this->getHeight() % rhs.getWidth() % rhs.getHeight())
622  .str());
623  }
624  transform_pixels(
625  _getRawView(), rhs._getRawView(), _getRawView(),
626  [&c](PixelT const& l, PixelT const& r) -> PixelT { return l / static_cast<PixelT>(c * r); });
627 }
628 
629 namespace {
630 /*
631  * Worker routine for manipulating images;
632  */
633 template <typename LhsPixelT, typename RhsPixelT>
634 struct plusEq : public pixelOp2<LhsPixelT, RhsPixelT> {
635  LhsPixelT operator()(LhsPixelT lhs, RhsPixelT rhs) const { return static_cast<LhsPixelT>(lhs + rhs); }
636 };
637 
638 template <typename LhsPixelT, typename RhsPixelT>
639 struct minusEq : public pixelOp2<LhsPixelT, RhsPixelT> {
640  LhsPixelT operator()(LhsPixelT lhs, RhsPixelT rhs) const { return static_cast<LhsPixelT>(lhs - rhs); }
641 };
642 
643 template <typename LhsPixelT, typename RhsPixelT>
644 struct timesEq : public pixelOp2<LhsPixelT, RhsPixelT> {
645  LhsPixelT operator()(LhsPixelT lhs, RhsPixelT rhs) const { return static_cast<LhsPixelT>(lhs * rhs); }
646 };
647 
648 template <typename LhsPixelT, typename RhsPixelT>
649 struct divideEq : public pixelOp2<LhsPixelT, RhsPixelT> {
650  LhsPixelT operator()(LhsPixelT lhs, RhsPixelT rhs) const { return static_cast<LhsPixelT>(lhs / rhs); }
651 };
652 } // namespace
653 
654 template <typename LhsPixelT, typename RhsPixelT>
656  for_each_pixel(lhs, rhs, plusEq<LhsPixelT, RhsPixelT>());
657  return lhs;
658 }
659 
660 template <typename LhsPixelT, typename RhsPixelT>
662  for_each_pixel(lhs, rhs, minusEq<LhsPixelT, RhsPixelT>());
663  return lhs;
664 }
665 
666 template <typename LhsPixelT, typename RhsPixelT>
668  for_each_pixel(lhs, rhs, timesEq<LhsPixelT, RhsPixelT>());
669  return lhs;
670 }
671 
672 template <typename LhsPixelT, typename RhsPixelT>
674  for_each_pixel(lhs, rhs, divideEq<LhsPixelT, RhsPixelT>());
675  return lhs;
676 }
677 
680  if (metadata.exists("ZNAXIS1") && metadata.exists("ZNAXIS2")) {
681  dims = lsst::geom::Extent2I(metadata.getAsInt("ZNAXIS1"), metadata.getAsInt("ZNAXIS2"));
682  } else {
683  dims = lsst::geom::Extent2I(metadata.getAsInt("NAXIS1"), metadata.getAsInt("NAXIS2"));
684  }
686  return lsst::geom::Box2I(xy0, dims);
687 }
688 
689 template <typename T1, typename T2>
690 bool imagesOverlap(ImageBase<T1> const& image1, ImageBase<T2> const& image2) {
691  auto arr1 = image1.getArray();
692  // get the address of the first and one-past-the-last element of arr1 using ndarray iterators;
693  // this works because the iterators for contiguous 1-d ndarray Arrays are just pointers
694  auto beg1Addr = arr1.front().begin();
695  auto end1Addr = arr1.back().end();
696 
697  auto arr2 = image2.getArray();
698  auto beg2Addr = arr2.front().begin();
699  auto end2Addr = arr2.back().end();
700 
701  auto ptrLess = std::less<void const* const>();
702  return ptrLess(beg1Addr, end2Addr) && ptrLess(beg2Addr, end1Addr);
703 }
704 
705 //
706 // Explicit instantiations
707 //
709 #define INSTANTIATE_OPERATOR(OP_EQ, T) \
710  template Image<T>& operator OP_EQ(Image<T>& lhs, Image<std::uint16_t> const& rhs); \
711  template Image<T>& operator OP_EQ(Image<T>& lhs, Image<int> const& rhs); \
712  template Image<T>& operator OP_EQ(Image<T>& lhs, Image<float> const& rhs); \
713  template Image<T>& operator OP_EQ(Image<T>& lhs, Image<double> const& rhs); \
714  template Image<T>& operator OP_EQ(Image<T>& lhs, Image<std::uint64_t> const& rhs);
715 
716 #define INSTANTIATE(T) \
717  template class ImageBase<T>; \
718  template class Image<T>; \
719  INSTANTIATE_OPERATOR(+=, T); \
720  INSTANTIATE_OPERATOR(-=, T); \
721  INSTANTIATE_OPERATOR(*=, T); \
722  INSTANTIATE_OPERATOR(/=, T)
723 
724 #define INSTANTIATE2(T1, T2) template bool imagesOverlap<T1, T2>(ImageBase<T1> const&, ImageBase<T2> const&);
725 
727 INSTANTIATE(int);
728 INSTANTIATE(float);
729 INSTANTIATE(double);
731 
735 INSTANTIATE2(std::uint16_t, double);
737 
739 INSTANTIATE2(int, int);
740 INSTANTIATE2(int, float);
741 INSTANTIATE2(int, double);
743 
745 INSTANTIATE2(float, int);
746 INSTANTIATE2(float, float);
747 INSTANTIATE2(float, double);
749 
750 INSTANTIATE2(double, std::uint16_t);
751 INSTANTIATE2(double, int);
752 INSTANTIATE2(double, float);
753 INSTANTIATE2(double, double);
754 INSTANTIATE2(double, std::uint64_t);
755 
759 INSTANTIATE2(std::uint64_t, double);
761 
763 } // namespace image
764 } // namespace afw
765 } // namespace lsst
int getImageDim()
Return the number of dimensions in the current HDU.
Definition: fits.cc:1299
void scaledPlus(OutImageT &outImage, double c1, InImageT const &inImage1, double c2, InImageT const &inImage2)
Compute the scaled sum of two images.
A functor class equivalent to std::function<LhsT (LhsT, RhsT)>, but with a virtual operator() ...
Extent2I const getDimensions() const
x_iterator fast_iterator
A fast STL compliant iterator for contiguous images N.b.
Definition: ImageBase.h:139
ConstReference< PixelT >::type PixelConstReference
A ConstReference to a PixelT.
Definition: ImageBase.h:121
double indexToPosition(double ind)
Convert image index to image position.
Definition: ImageUtils.h:55
_view_t::reverse_iterator reverse_iterator
An STL compliant reverse iterator.
Definition: ImageBase.h:131
bool isEmpty() const
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:655
afw::table::Key< afw::table::Array< MaskPixelT > > mask
Point2I const getMin() const
T swap(T... args)
int getHeight() const
Return the number of rows in the image.
Definition: ImageBase.h:301
Options for writing an image to FITS.
Definition: fits.h:218
int getAsInt(std::string const &name) const
_view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
Definition: ImageBase.h:135
tuple options
void for_each_pixel(Image< LhsT > &lhs, pixelOp0< LhsT > const &func)
Set each pixel in an Image<LhsT> to func()
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:296
The base class for all image classed (Image, Mask, MaskedImage, ...)
Definition: ImageBase.h:104
A Function taking two arguments.
Definition: Function.h:273
#define INSTANTIATE2(ImagePixelT1, ImagePixelT2)
Definition: MaskedImage.cc:754
STL class.
_view_t::iterator iterator
An STL compliant iterator.
Definition: ImageBase.h:127
An exception thrown when problems are found when reading or writing FITS files.
Definition: fits.h:35
afw::table::PointKey< int > dimensions
Definition: GaussianPsf.cc:44
A base class for image defects.
int end
Definition: BoundedField.cc:99
Represent a 2-dimensional array of bitmask pixels.
Definition: Mask.h:84
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:120
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:172
#define INSTANTIATE(FROMSYS, TOSYS)
Definition: Detector.cc:156
table::Key< int > b
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:690
bool exists(std::string const &name) const
A class used to request that array accesses be checked.
Definition: ImageBase.h:76
T reset(T... args)
double x
void swap(ImageBase &rhs)
Definition: Image.cc:228
T max(T... args)
void setHdu(int hdu, bool relative=false)
Set the current HDU.
Definition: fits.cc:478
void operator*=(ExtentBase< int, N > &lhs, double rhs)
void swap(Image< PixelT > &a, Image< PixelT > &b)
Definition: Image.cc:448
#define LSST_EXCEPT(type,...)
Extent< int, 2 > Extent2I
reverse_iterator rend() const
Return an STL compliant reverse iterator to the end of the image.
Definition: Image.cc:260
lsst::geom::Point2I getImageXY0FromMetadata(daf::base::PropertySet &metadata, std::string const &wcsName, bool strip=false)
Definition: wcsUtils.cc:98
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:661
int getWidth() const
Return the number of columns in the image.
Definition: ImageBase.h:299
Reference< PixelT >::type PixelReference
A Reference to a PixelT.
Definition: ImageBase.h:119
table::Box2IKey bbox
table::Key< int > a
reverse_iterator rbegin() const
Return an STL compliant reverse iterator to the start of the image.
Definition: Image.cc:255
iterator begin() const
Return an STL compliant iterator to the start of the image.
Definition: Image.cc:245
iterator at(int x, int y) const
Return an STL compliant iterator at the point (x, y)
Definition: Image.cc:265
T sqrt(T... args)
lsst::geom::Extent2I getDimensions() const
Return the image&#39;s size; useful for passing to constructors.
Definition: ImageBase.h:359
void writeImage(ndarray::Array< T const, N, C > const &array)
Write an ndarray::Array to a FITS image HDU.
Definition: fits.h:476
_view_t _getRawView() const
Definition: ImageBase.h:468
static _view_t _allocateView(lsst::geom::Extent2I const &dimensions, Manager::Ptr &manager)
Definition: Image.cc:53
#define LSST_EXCEPT_ADD(e, m)
ndarray::Array< MaskPixelT, 2, 1 > Array
A mutable ndarray representation of the image.
Definition: ImageBase.h:151
void swap(Image &rhs)
Definition: Image.cc:441
lsst::geom::Box2I bboxFromMetadata(daf::base::PropertySet &metadata)
Determine the image bounding box from its metadata (FITS header)
Definition: Image.cc:678
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:67
int y
Definition: SpanSet.cc:44
std::string const wcsNameForXY0
Definition: ImageBase.h:72
void operator/=(ExtentBase< int, N > &lhs, double rhs)
static _view_t _makeSubView(lsst::geom::Extent2I const &dimensions, lsst::geom::Extent2I const &offset, const _view_t &view)
Definition: Image.cc:73