lsst.afw  15.0-29-ga12a2b06e
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(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(geom::Extent2I const& dimensions,
74  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()) {
79  (boost::format("Box2I(Point2I(%d,%d),Extent2I(%d,%d)) doesn't fit in image %dx%d") %
80  offset.getX() % offset.getY() % dimensions.getX() % dimensions.getY() %
81  view.width() % view.height())
82  .str());
83  }
84  return boost::gil::subimage_view(view, offset.getX(), offset.getY(), dimensions.getX(),
85  dimensions.getY());
86 }
87 
88 template <typename PixelT>
90  : daf::base::Citizen(typeid(this)),
91  _origin(0, 0),
92  _manager(),
93  _gilView(_allocateView(dimensions, _manager)) {}
94 
95 template <typename PixelT>
97  : daf::base::Citizen(typeid(this)),
98  _origin(bbox.getMin()),
99  _manager(),
100  _gilView(_allocateView(bbox.getDimensions(), _manager)) {}
101 
102 template <typename PixelT>
103 ImageBase<PixelT>::ImageBase(ImageBase const& rhs, bool const deep
104 
105  )
106  : daf::base::Citizen(typeid(this)),
107  _origin(rhs._origin),
108  _manager(rhs._manager),
109  _gilView(rhs._gilView) {
110  if (deep) {
111  ImageBase tmp(getBBox());
112  tmp.assign(*this); // now copy the pixels
113  swap(tmp);
114  }
115 }
116 // Delegate to copy-constructor for backwards compatibility
117 template <typename PixelT>
119 
120 template <typename PixelT>
122  bool const deep
123 
124  )
125  : daf::base::Citizen(typeid(this)),
126  _origin((origin == PARENT) ? bbox.getMin() : rhs._origin + geom::Extent2I(bbox.getMin())),
127  _manager(rhs._manager), // reference counted pointer, don't copy pixels
128  _gilView(_makeSubView(bbox.getDimensions(), _origin - rhs._origin, rhs._gilView)) {
129  if (deep) {
130  ImageBase tmp(getBBox());
131  tmp.assign(*this); // now copy the pixels
132  swap(tmp);
133  }
134 }
135 
136 template <typename PixelT>
137 ImageBase<PixelT>::ImageBase(Array const& array, bool deep, geom::Point2I const& xy0)
138  : daf::base::Citizen(typeid(this)),
139  _origin(xy0),
140  _manager(array.getManager()),
141  _gilView(boost::gil::interleaved_view(array.template getSize<1>(), array.template getSize<0>(),
142  (typename _view_t::value_type*)array.getData(),
143  array.template getStride<0>() * sizeof(PixelT))) {
144  if (deep) {
145  ImageBase tmp(*this, true);
146  swap(tmp);
147  }
148 }
149 
150 template <typename PixelT>
152  ImageBase tmp(rhs);
153  swap(tmp); // See Meyers, Effective C++, Item 11
154 
155  return *this;
156 }
157 // Delegate to copy-assignment for backwards compatibility
158 template <typename PixelT>
160  return *this = rhs;
161 }
162 
163 template <typename PixelT>
165  assign(rhs);
166  return *this;
167 }
168 
169 template <typename PixelT>
171  auto lhsDim = bbox.isEmpty() ? getDimensions() : bbox.getDimensions();
172  if (lhsDim != rhs.getDimensions()) {
174  (boost::format("Dimension mismatch: %dx%d v. %dx%d") % lhsDim.getX() %
175  lhsDim.getY() % rhs.getWidth() % rhs.getHeight())
176  .str());
177  }
178  if (bbox.isEmpty()) {
179  copy_pixels(rhs._gilView, _gilView);
180  } else {
181  auto lhsOff = (origin == PARENT) ? bbox.getMin() - _origin : geom::Extent2I(bbox.getMin());
182  auto lhsGilView = _makeSubView(lhsDim, lhsOff, _gilView);
183  copy_pixels(rhs._gilView, lhsGilView);
184  }
185 }
186 
187 template <typename PixelT>
189  return const_cast<typename ImageBase<PixelT>::PixelReference>(
190  static_cast<typename ImageBase<PixelT>::PixelConstReference>(_gilView(x, y)[0]));
191 }
192 
193 template <typename PixelT>
195  CheckIndices const& check) {
196  if (check && (x < 0 || x >= getWidth() || y < 0 || y >= getHeight())) {
197  throw LSST_EXCEPT(
199  (boost::format("Index (%d, %d) is out of range [0--%d], [0--%d]") % x % y % (getWidth() - 1) %
200  (getHeight() -
201  1)).str());
202  }
203 
204  return const_cast<typename ImageBase<PixelT>::PixelReference>(
205  static_cast<typename ImageBase<PixelT>::PixelConstReference>(_gilView(x, y)[0]));
206 }
207 
208 template <typename PixelT>
210  return _gilView(x, y)[0];
211 }
212 
213 template <typename PixelT>
215  int x, int y, CheckIndices const& check) const {
216  if (check && (x < 0 || x >= getWidth() || y < 0 || y >= getHeight())) {
218  (boost::format("Index (%d, %d) is out of range [0--%d], [0--%d]") % x % y %
219  (this->getWidth() - 1) %
220  (this->getHeight() -
221  1)).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>(geom::ExtentI(width, height)) {
306  *this = initialValue;
307 }
308 
309 template <typename PixelT>
310 Image<PixelT>::Image(geom::Extent2I const& dimensions, PixelT initialValue) : ImageBase<PixelT>(dimensions) {
311  *this = initialValue;
312 }
313 
314 template <typename PixelT>
315 Image<PixelT>::Image(geom::Box2I const& bbox, PixelT initialValue) : ImageBase<PixelT>(bbox) {
316  *this = initialValue;
317 }
318 
319 template <typename PixelT>
320 Image<PixelT>::Image(Image const& rhs, bool const deep) : ImageBase<PixelT>(rhs, deep) {}
321 // Delegate to copy-constructor for backwards compatibility
322 template <typename PixelT>
323 Image<PixelT>::Image(Image&& rhs) : Image(rhs, false) {}
324 
325 template <typename PixelT>
326 Image<PixelT>::Image(Image const& rhs, geom::Box2I const& bbox, ImageOrigin const origin, bool const deep
327 
328  )
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  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  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>
417  std::string const& filename,
419  std::string const& mode,
422 ) const {
423  fits::Fits fitsfile(filename, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
424  writeFits(fitsfile, options, header, mask);
425 }
426 
427 template <typename PixelT>
429  fits::MemFileManager& manager,
430  fits::ImageWriteOptions const& options,
431  std::string const& mode,
434 ) const {
435  fits::Fits fitsfile(manager, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
436  writeFits(fitsfile, options, header, mask);
437 }
438 
439 template <typename PixelT>
441  fits::Fits& fitsfile,
442  fits::ImageWriteOptions const& options,
445 ) const {
446  fitsfile.writeImage(*this, options, header, mask);
447 }
448 
449 
450 #endif // !DOXYGEN
451 
452 template <typename PixelT>
454  using std::swap; // See Meyers, Effective C++, Item 25
456  ; // no private variables to swap
457 }
458 
459 template <typename PixelT>
461  a.swap(b);
462 }
463 
464 // In-place, per-pixel, sqrt().
465 template <typename PixelT>
467  transform_pixels(_getRawView(), _getRawView(),
468  [](PixelT const& l) -> PixelT { return static_cast<PixelT>(std::sqrt(l)); });
469 }
470 
471 template <typename PixelT>
473  transform_pixels(_getRawView(), _getRawView(), [&rhs](PixelT const& l) -> PixelT { return l + rhs; });
474  return *this;
475 }
476 
477 template <typename PixelT>
479  if (this->getDimensions() != rhs.getDimensions()) {
481  (boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
482  this->getHeight() % rhs.getWidth() % rhs.getHeight())
483  .str());
484  }
485  transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(),
486  [](PixelT const& l, PixelT const& r) -> PixelT { return l + r; });
487  return *this;
488 }
489 
490 template <typename PixelT>
492  for (int y = 0; y != this->getHeight(); ++y) {
493  double const yPos = this->indexToPosition(y, Y);
494  double xPos = this->indexToPosition(0, X);
495  for (typename Image<PixelT>::x_iterator ptr = this->row_begin(y), end = this->row_end(y); ptr != end;
496  ++ptr, ++xPos) {
497  *ptr += function(xPos, yPos);
498  }
499  }
500  return *this;
501 }
502 
503 template <typename PixelT>
504 void Image<PixelT>::scaledPlus(double const c, Image<PixelT> const& rhs) {
505  if (this->getDimensions() != rhs.getDimensions()) {
507  (boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
508  this->getHeight() % rhs.getWidth() % rhs.getHeight())
509  .str());
510  }
511  transform_pixels(
512  _getRawView(), rhs._getRawView(), _getRawView(),
513  [&c](PixelT const& l, PixelT const& r) -> PixelT { return l + static_cast<PixelT>(c * r); });
514 }
515 
516 template <typename PixelT>
518  transform_pixels(_getRawView(), _getRawView(), [&rhs](PixelT const& l) -> PixelT { return l - rhs; });
519  return *this;
520 }
521 
522 template <typename PixelT>
524  if (this->getDimensions() != rhs.getDimensions()) {
526  (boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
527  this->getHeight() % rhs.getWidth() % rhs.getHeight())
528  .str());
529  }
530  transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(),
531  [](PixelT const& l, PixelT const& r) -> PixelT { return l - r; });
532  return *this;
533 }
534 
535 template <typename PixelT>
536 void Image<PixelT>::scaledMinus(double const c, Image<PixelT> const& rhs) {
537  if (this->getDimensions() != rhs.getDimensions()) {
539  (boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
540  this->getHeight() % rhs.getWidth() % rhs.getHeight())
541  .str());
542  }
543  transform_pixels(
544  _getRawView(), rhs._getRawView(), _getRawView(),
545  [&c](PixelT const& l, PixelT const& r) -> PixelT { return l - static_cast<PixelT>(c * r); });
546 }
547 
548 template <typename PixelT>
550  for (int y = 0; y != this->getHeight(); ++y) {
551  double const yPos = this->indexToPosition(y, Y);
552  double xPos = this->indexToPosition(0, X);
553  for (typename Image<PixelT>::x_iterator ptr = this->row_begin(y), end = this->row_end(y); ptr != end;
554  ++ptr, ++xPos) {
555  *ptr -= function(xPos, yPos);
556  }
557  }
558  return *this;
559 }
560 
561 template <typename PixelT>
563  transform_pixels(_getRawView(), _getRawView(), [&rhs](PixelT const& l) -> PixelT { return l * rhs; });
564  return *this;
565 }
566 
567 template <typename PixelT>
569  if (this->getDimensions() != rhs.getDimensions()) {
571  (boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
572  this->getHeight() % rhs.getWidth() % rhs.getHeight())
573  .str());
574  }
575  transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(),
576  [](PixelT const& l, PixelT const& r) -> PixelT { return l * r; });
577  return *this;
578 }
579 
580 template <typename PixelT>
581 void Image<PixelT>::scaledMultiplies(double const c, Image<PixelT> const& rhs) {
582  if (this->getDimensions() != rhs.getDimensions()) {
584  (boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
585  this->getHeight() % rhs.getWidth() % rhs.getHeight())
586  .str());
587  }
588  transform_pixels(
589  _getRawView(), rhs._getRawView(), _getRawView(),
590  [&c](PixelT const& l, PixelT const& r) -> PixelT { return l * static_cast<PixelT>(c * r); });
591 }
592 
593 template <typename PixelT>
595  transform_pixels(_getRawView(), _getRawView(), [&rhs](PixelT const& l) -> PixelT { return l / rhs; });
596  return *this;
597 }
598 //
599 // Specialize float and double for efficiency
600 //
601 template <>
603  double const irhs = 1 / rhs;
604  *this *= irhs;
605  return *this;
606 }
607 
608 template <>
610  float const irhs = 1 / rhs;
611  *this *= irhs;
612  return *this;
613 }
614 
615 template <typename PixelT>
617  if (this->getDimensions() != rhs.getDimensions()) {
619  (boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
620  this->getHeight() % rhs.getWidth() % rhs.getHeight())
621  .str());
622  }
623  transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(),
624  [](PixelT const& l, PixelT const& r) -> PixelT { return l / r; });
625  return *this;
626 }
627 
628 template <typename PixelT>
629 void Image<PixelT>::scaledDivides(double const c, Image<PixelT> const& rhs) {
630  if (this->getDimensions() != rhs.getDimensions()) {
632  (boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
633  this->getHeight() % rhs.getWidth() % rhs.getHeight())
634  .str());
635  }
636  transform_pixels(
637  _getRawView(), rhs._getRawView(), _getRawView(),
638  [&c](PixelT const& l, PixelT const& r) -> PixelT { return l / static_cast<PixelT>(c * r); });
639 }
640 
641 namespace {
642 /*
643  * Worker routine for manipulating images;
644  */
645 template <typename LhsPixelT, typename RhsPixelT>
646 struct plusEq : public pixelOp2<LhsPixelT, RhsPixelT> {
647  LhsPixelT operator()(LhsPixelT lhs, RhsPixelT rhs) const { return static_cast<LhsPixelT>(lhs + rhs); }
648 };
649 
650 template <typename LhsPixelT, typename RhsPixelT>
651 struct minusEq : public pixelOp2<LhsPixelT, RhsPixelT> {
652  LhsPixelT operator()(LhsPixelT lhs, RhsPixelT rhs) const { return static_cast<LhsPixelT>(lhs - rhs); }
653 };
654 
655 template <typename LhsPixelT, typename RhsPixelT>
656 struct timesEq : public pixelOp2<LhsPixelT, RhsPixelT> {
657  LhsPixelT operator()(LhsPixelT lhs, RhsPixelT rhs) const { return static_cast<LhsPixelT>(lhs * rhs); }
658 };
659 
660 template <typename LhsPixelT, typename RhsPixelT>
661 struct divideEq : public pixelOp2<LhsPixelT, RhsPixelT> {
662  LhsPixelT operator()(LhsPixelT lhs, RhsPixelT rhs) const { return static_cast<LhsPixelT>(lhs / rhs); }
663 };
664 }
665 
666 template <typename LhsPixelT, typename RhsPixelT>
668  for_each_pixel(lhs, rhs, plusEq<LhsPixelT, RhsPixelT>());
669  return lhs;
670 }
671 
672 template <typename LhsPixelT, typename RhsPixelT>
674  for_each_pixel(lhs, rhs, minusEq<LhsPixelT, RhsPixelT>());
675  return lhs;
676 }
677 
678 template <typename LhsPixelT, typename RhsPixelT>
680  for_each_pixel(lhs, rhs, timesEq<LhsPixelT, RhsPixelT>());
681  return lhs;
682 }
683 
684 template <typename LhsPixelT, typename RhsPixelT>
686  for_each_pixel(lhs, rhs, divideEq<LhsPixelT, RhsPixelT>());
687  return lhs;
688 }
689 
691 {
692  geom::Extent2I dims;
693  if (metadata.exists("ZNAXIS1") && metadata.exists("ZNAXIS2")) {
694  dims = geom::Extent2I(metadata.getAsInt("ZNAXIS1"), metadata.getAsInt("ZNAXIS2"));
695  } else {
696  dims = geom::Extent2I(metadata.getAsInt("NAXIS1"), metadata.getAsInt("NAXIS2"));
697  }
699  return geom::Box2I(xy0, dims);
700 }
701 
702 template <typename T1, typename T2>
703 bool imagesOverlap(ImageBase<T1> const& image1, ImageBase<T2> const& image2) {
704  auto arr1 = image1.getArray();
705  // get the address of the first and one-past-the-last element of arr1 using ndarray iterators;
706  // this works because the iterators for contiguous 1-d ndarray Arrays are just pointers
707  auto beg1Addr = arr1.front().begin();
708  auto end1Addr = arr1.back().end();
709 
710  auto arr2 = image2.getArray();
711  auto beg2Addr = arr2.front().begin();
712  auto end2Addr = arr2.back().end();
713 
714  auto ptrLess = std::less<void const* const>();
715  return ptrLess(beg1Addr, end2Addr) && ptrLess(beg2Addr, end1Addr);
716 }
717 
718 //
719 // Explicit instantiations
720 //
722 #define INSTANTIATE_OPERATOR(OP_EQ, T) \
723  template Image<T>& operator OP_EQ(Image<T>& lhs, Image<std::uint16_t> const& rhs); \
724  template Image<T>& operator OP_EQ(Image<T>& lhs, Image<int> const& rhs); \
725  template Image<T>& operator OP_EQ(Image<T>& lhs, Image<float> const& rhs); \
726  template Image<T>& operator OP_EQ(Image<T>& lhs, Image<double> const& rhs); \
727  template Image<T>& operator OP_EQ(Image<T>& lhs, Image<std::uint64_t> const& rhs);
728 
729 #define INSTANTIATE(T) \
730  template class ImageBase<T>; \
731  template class Image<T>; \
732  INSTANTIATE_OPERATOR(+=, T); \
733  INSTANTIATE_OPERATOR(-=, T); \
734  INSTANTIATE_OPERATOR(*=, T); \
735  INSTANTIATE_OPERATOR(/=, T)
736 
737 #define INSTANTIATE2(T1, T2) template bool imagesOverlap<T1, T2>(ImageBase<T1> const&, ImageBase<T2> const&);
738 
740 INSTANTIATE(int);
741 INSTANTIATE(float);
742 INSTANTIATE(double);
744 
748 INSTANTIATE2(std::uint16_t, double);
750 
752 INSTANTIATE2(int, int);
753 INSTANTIATE2(int, float);
754 INSTANTIATE2(int, double);
756 
758 INSTANTIATE2(float, int);
759 INSTANTIATE2(float, float);
760 INSTANTIATE2(float, double);
762 
763 INSTANTIATE2(double, std::uint16_t);
764 INSTANTIATE2(double, int);
765 INSTANTIATE2(double, float);
766 INSTANTIATE2(double, double);
767 INSTANTIATE2(double, std::uint64_t);
768 
772 INSTANTIATE2(std::uint64_t, double);
774 
776 }
777 }
778 } // end lsst::afw::image
int getImageDim()
Return the number of dimensions in the current HDU.
Definition: fits.cc:1300
Point2I const getMin() const
Definition: Box.h:123
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() ...
bool isEmpty() const
Return true if the box contains no points.
Definition: Box.h:163
x_iterator fast_iterator
A fast STL compliant iterator for contiguous images N.b.
Definition: ImageBase.h:141
ConstReference< PixelT >::type PixelConstReference
A ConstReference to a PixelT.
Definition: ImageBase.h:123
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:133
afw::table::Key< afw::table::Array< MaskPixelT > > mask
T swap(T... args)
void operator/=(ExtentBase< int, N > &lhs, double rhs)
Definition: Extent.h:436
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:220
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:137
void assign(ImageBase const &rhs, geom::Box2I const &bbox=geom::Box2I(), ImageOrigin origin=PARENT)
Copy pixels from another image to a specified subregion of this image.
Definition: Image.cc:170
geom::Point2I getImageXY0FromMetadata(daf::base::PropertySet &metadata, std::string const &wcsName, bool strip=false)
Definition: wcsUtils.cc:98
Extent< int, 2 > Extent2I
Definition: Extent.h:380
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:298
The base class for all image classed (Image, Mask, MaskedImage, ...)
Definition: ImageBase.h:106
A Function taking two arguments.
Definition: Function.h:277
#define INSTANTIATE2(ImagePixelT1, ImagePixelT2)
Definition: MaskedImage.cc:763
An integer coordinate rectangle.
Definition: Box.h:55
STL class.
_view_t::iterator iterator
An STL compliant iterator.
Definition: ImageBase.h:129
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
geom::Extent2I getDimensions() const
Return the image&#39;s size; useful for passing to constructors.
Definition: ImageBase.h:359
void operator*=(ExtentBase< int, N > &lhs, double rhs)
Definition: Extent.h:425
A base class for image defects.
int end
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
#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:703
bool exists(std::string const &name) const
A class used to request that array accesses be checked.
Definition: ImageBase.h:78
T reset(T... args)
geom::Box2I bboxFromMetadata(daf::base::PropertySet &metadata)
Determine the image bounding box from its metadata (FITS header)
Definition: Image.cc:690
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:477
Extent< int, 2 > ExtentI
Definition: Extent.h:377
Extent< double, N > & operator+=(Extent< double, N > &lhs, Extent< int, N > const &rhs)
Definition: Extent.h:452
void swap(Image< PixelT > &a, Image< PixelT > &b)
Definition: Image.cc:460
#define LSST_EXCEPT(type,...)
reverse_iterator rend() const
Return an STL compliant reverse iterator to the end of the image.
Definition: Image.cc:260
Extent2I const getDimensions() const
Definition: Box.h:153
int getWidth() const
Return the number of columns in the image.
Definition: ImageBase.h:299
static _view_t _allocateView(geom::Extent2I const &dimensions, Manager::Ptr &manager)
Definition: Image.cc:53
Reference< PixelT >::type PixelReference
A Reference to a PixelT.
Definition: ImageBase.h:121
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)
Extent< double, N > & operator-=(Extent< double, N > &lhs, Extent< int, N > const &rhs)
Definition: Extent.h:462
static _view_t _makeSubView(geom::Extent2I const &dimensions, geom::Extent2I const &offset, const _view_t &view)
Definition: Image.cc:73
void writeImage(ndarray::Array< T const, N, C > const &array)
Write an ndarray::Array to a FITS image HDU.
Definition: fits.h:478
_view_t _getRawView() const
Definition: ImageBase.h:468
#define LSST_EXCEPT_ADD(e, m)
ndarray::Array< MaskPixelT, 2, 1 > Array
A mutable ndarray representation of the image.
Definition: ImageBase.h:153
void swap(Image &rhs)
Definition: Image.cc:453
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:69
int y
Definition: SpanSet.cc:44
std::string const wcsNameForXY0
Definition: ImageBase.h:74