lsst.afw  15.0-21-g91b8abf62
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 "boost/mpl/vector.hpp"
31 #pragma clang diagnostic push
32 #pragma clang diagnostic ignored "-Wunused-variable"
33 #pragma clang diagnostic pop
34 #include "boost/format.hpp"
35 #include "boost/filesystem/path.hpp"
36 #include "boost/gil/gil_all.hpp"
37 
38 #include "lsst/pex/exceptions.h"
39 #include "lsst/afw/geom/wcsUtils.h"
40 #include "lsst/afw/image/Image.h"
42 #include "lsst/afw/fits.h"
45 
46 namespace lsst {
47 namespace afw {
48 namespace image {
49 
50 template <typename PixelT>
51 typename ImageBase<PixelT>::_view_t ImageBase<PixelT>::_allocateView(geom::Extent2I const& dimensions,
52  Manager::Ptr& manager) {
53  if (dimensions.getX() < 0 || dimensions.getY() < 0) {
55  str(boost::format("Both width and height must be non-negative: %d, %d") %
56  dimensions.getX() % dimensions.getY()));
57  }
58  if (dimensions.getX() != 0 && dimensions.getY() > std::numeric_limits<int>::max() / dimensions.getX()) {
60  str(boost::format("Image dimensions (%d x %d) too large; int overflow detected.") %
61  dimensions.getX() % dimensions.getY()));
62  }
64  ndarray::SimpleManager<PixelT>::allocate(dimensions.getX() * dimensions.getY());
65  manager = r.first;
66  return boost::gil::interleaved_view(dimensions.getX(), dimensions.getY(),
67  (typename _view_t::value_type*)r.second,
68  dimensions.getX() * sizeof(PixelT));
69 }
70 template <typename PixelT>
71 typename ImageBase<PixelT>::_view_t ImageBase<PixelT>::_makeSubView(geom::Extent2I const& dimensions,
72  geom::Extent2I const& offset,
73  const _view_t& view) {
74  if (offset.getX() < 0 || offset.getY() < 0 || offset.getX() + dimensions.getX() > view.width() ||
75  offset.getY() + dimensions.getY() > view.height()) {
77  (boost::format("Box2I(Point2I(%d,%d),Extent2I(%d,%d)) doesn't fit in image %dx%d") %
78  offset.getX() % offset.getY() % dimensions.getX() % dimensions.getY() %
79  view.width() % view.height())
80  .str());
81  }
82  return boost::gil::subimage_view(view, offset.getX(), offset.getY(), dimensions.getX(),
83  dimensions.getY());
84 }
85 
86 template <typename PixelT>
88  : daf::base::Citizen(typeid(this)),
89  _origin(0, 0),
90  _manager(),
91  _gilView(_allocateView(dimensions, _manager)) {}
92 
93 template <typename PixelT>
95  : daf::base::Citizen(typeid(this)),
96  _origin(bbox.getMin()),
97  _manager(),
98  _gilView(_allocateView(bbox.getDimensions(), _manager)) {}
99 
100 template <typename PixelT>
101 ImageBase<PixelT>::ImageBase(ImageBase const& rhs, bool const deep
102 
103  )
104  : daf::base::Citizen(typeid(this)),
105  _origin(rhs._origin),
106  _manager(rhs._manager),
107  _gilView(rhs._gilView) {
108  if (deep) {
109  ImageBase tmp(getBBox());
110  tmp.assign(*this); // now copy the pixels
111  swap(tmp);
112  }
113 }
114 // Delegate to copy-constructor for backwards compatibility
115 template <typename PixelT>
117 
118 template <typename PixelT>
120  bool const deep
121 
122  )
123  : daf::base::Citizen(typeid(this)),
124  _origin((origin == PARENT) ? bbox.getMin() : rhs._origin + geom::Extent2I(bbox.getMin())),
125  _manager(rhs._manager), // reference counted pointer, don't copy pixels
126  _gilView(_makeSubView(bbox.getDimensions(), _origin - rhs._origin, rhs._gilView)) {
127  if (deep) {
128  ImageBase tmp(getBBox());
129  tmp.assign(*this); // now copy the pixels
130  swap(tmp);
131  }
132 }
133 
134 template <typename PixelT>
135 ImageBase<PixelT>::ImageBase(Array const& array, bool deep, geom::Point2I const& xy0)
136  : daf::base::Citizen(typeid(this)),
137  _origin(xy0),
138  _manager(array.getManager()),
139  _gilView(boost::gil::interleaved_view(array.template getSize<1>(), array.template getSize<0>(),
140  (typename _view_t::value_type*)array.getData(),
141  array.template getStride<0>() * sizeof(PixelT))) {
142  if (deep) {
143  ImageBase tmp(*this, true);
144  swap(tmp);
145  }
146 }
147 
148 template <typename PixelT>
150  ImageBase tmp(rhs);
151  swap(tmp); // See Meyers, Effective C++, Item 11
152 
153  return *this;
154 }
155 // Delegate to copy-assignment for backwards compatibility
156 template <typename PixelT>
158  return *this = rhs;
159 }
160 
161 template <typename PixelT>
163  assign(rhs);
164  return *this;
165 }
166 
167 template <typename PixelT>
169  auto lhsDim = bbox.isEmpty() ? getDimensions() : bbox.getDimensions();
170  if (lhsDim != rhs.getDimensions()) {
172  (boost::format("Dimension mismatch: %dx%d v. %dx%d") % lhsDim.getX() %
173  lhsDim.getY() % rhs.getWidth() % rhs.getHeight())
174  .str());
175  }
176  if (bbox.isEmpty()) {
177  copy_pixels(rhs._gilView, _gilView);
178  } else {
179  auto lhsOff = (origin == PARENT) ? bbox.getMin() - _origin : geom::Extent2I(bbox.getMin());
180  auto lhsGilView = _makeSubView(lhsDim, lhsOff, _gilView);
181  copy_pixels(rhs._gilView, lhsGilView);
182  }
183 }
184 
185 template <typename PixelT>
187  return const_cast<typename ImageBase<PixelT>::PixelReference>(
188  static_cast<typename ImageBase<PixelT>::PixelConstReference>(_gilView(x, y)[0]));
189 }
190 
191 template <typename PixelT>
193  CheckIndices const& check) {
194  if (check && (x < 0 || x >= getWidth() || y < 0 || y >= getHeight())) {
195  throw LSST_EXCEPT(
197  (boost::format("Index (%d, %d) is out of range [0--%d], [0--%d]") % x % y % (getWidth() - 1) %
198  (getHeight() -
199  1)).str());
200  }
201 
202  return const_cast<typename ImageBase<PixelT>::PixelReference>(
203  static_cast<typename ImageBase<PixelT>::PixelConstReference>(_gilView(x, y)[0]));
204 }
205 
206 template <typename PixelT>
208  return _gilView(x, y)[0];
209 }
210 
211 template <typename PixelT>
213  int x, int y, CheckIndices const& check) const {
214  if (check && (x < 0 || x >= getWidth() || y < 0 || y >= getHeight())) {
216  (boost::format("Index (%d, %d) is out of range [0--%d], [0--%d]") % x % y %
217  (this->getWidth() - 1) %
218  (this->getHeight() -
219  1)).str());
220  }
221 
222  return _gilView(x, y)[0];
223 }
224 
225 template <typename PixelT>
227  using std::swap; // See Meyers, Effective C++, Item 25
228 
229  swap(_manager, rhs._manager); // just swapping the pointers
230  swap(_gilView, rhs._gilView);
231  swap(_origin, rhs._origin);
232 }
233 
234 template <typename PixelT>
236  a.swap(b);
237 }
238 
239 //
240 // Iterators
241 //
242 template <typename PixelT>
244  return _gilView.begin();
245 }
246 
247 template <typename PixelT>
249  return _gilView.end();
250 }
251 
252 template <typename PixelT>
254  return _gilView.rbegin();
255 }
256 
257 template <typename PixelT>
259  return _gilView.rend();
260 }
261 
262 template <typename PixelT>
264  return _gilView.at(x, y);
265 }
266 
267 template <typename PixelT>
269  if (!contiguous) {
270  throw LSST_EXCEPT(pex::exceptions::RuntimeError, "Only contiguous == true makes sense");
271  }
272  if (!this->isContiguous()) {
273  throw LSST_EXCEPT(pex::exceptions::RuntimeError, "Image's pixels are not contiguous");
274  }
275 
276  return row_begin(0);
277 }
278 
279 template <typename PixelT>
281  if (!contiguous) {
282  throw LSST_EXCEPT(pex::exceptions::RuntimeError, "Only contiguous == true makes sense");
283  }
284  if (!this->isContiguous()) {
285  throw LSST_EXCEPT(pex::exceptions::RuntimeError, "Image's pixels are not contiguous");
286  }
287 
288  return row_end(getHeight() - 1);
289 }
290 
291 template <typename PixelT>
293  fill_pixels(_gilView, rhs);
294 
295  return *this;
296 }
297 
298 //
299 // On to Image itself. ctors, cctors, and operator=
300 //
301 template <typename PixelT>
302 Image<PixelT>::Image(unsigned int width, unsigned int height, PixelT initialValue)
303  : ImageBase<PixelT>(geom::ExtentI(width, height)) {
304  *this = initialValue;
305 }
306 
307 template <typename PixelT>
308 Image<PixelT>::Image(geom::Extent2I const& dimensions, PixelT initialValue) : ImageBase<PixelT>(dimensions) {
309  *this = initialValue;
310 }
311 
312 template <typename PixelT>
313 Image<PixelT>::Image(geom::Box2I const& bbox, PixelT initialValue) : ImageBase<PixelT>(bbox) {
314  *this = initialValue;
315 }
316 
317 template <typename PixelT>
318 Image<PixelT>::Image(Image const& rhs, bool const deep) : ImageBase<PixelT>(rhs, deep) {}
319 // Delegate to copy-constructor for backwards compatibility
320 template <typename PixelT>
321 Image<PixelT>::Image(Image&& rhs) : Image(rhs, false) {}
322 
323 template <typename PixelT>
324 Image<PixelT>::Image(Image const& rhs, geom::Box2I const& bbox, ImageOrigin const origin, bool const deep
325 
326  )
327  : ImageBase<PixelT>(rhs, bbox, origin, deep) {}
328 
329 template <typename PixelT>
331  this->ImageBase<PixelT>::operator=(rhs);
332 
333  return *this;
334 }
335 
336 template <typename PixelT>
338  this->ImageBase<PixelT>::operator=(rhs);
339 
340  return *this;
341 }
342 // Delegate to copy-assignment for backwards compatibility
343 template <typename PixelT>
345  return *this = rhs;
346 }
347 
348 #ifndef DOXYGEN // doc for this section has been moved to header
349 
350 template <typename PixelT>
352  geom::Box2I const& bbox, ImageOrigin origin)
353  : ImageBase<PixelT>() {
354  fits::Fits fitsfile(fileName, "r", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
355  fitsfile.setHdu(hdu);
356  try {
357  *this = Image(fitsfile, metadata, bbox, origin);
358  } catch (fits::FitsError& e) {
359  fitsfile.status = 0; // reset so we can read NAXIS
360  if (fitsfile.getImageDim() == 0) { // no pixels to read
361  LSST_EXCEPT_ADD(e, str(boost::format("HDU %d has NAXIS == 0") % hdu));
362  }
363  throw e;
364  }
365 }
366 template <typename PixelT>
367 Image<PixelT>::Image(fits::MemFileManager& manager, int const hdu,
369  ImageOrigin const origin)
370  : ImageBase<PixelT>() {
371  fits::Fits fitsfile(manager, "r", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
372  fitsfile.setHdu(hdu);
373  *this = Image(fitsfile, metadata, bbox, origin);
374 }
375 
376 template <typename PixelT>
378  geom::Box2I const& bbox, ImageOrigin const origin)
379  : ImageBase<PixelT>() {
380  typedef boost::mpl::vector<unsigned char, unsigned short, short, int, unsigned int, float, double,
382  fits_image_types;
383 
384  if (!metadata) {
385  metadata.reset(new daf::base::PropertyList());
386  }
387 
388  fits_read_image<fits_image_types>(fitsfile, *this, *metadata, bbox, origin);
389 }
390 
391 template <typename PixelT>
392 void Image<PixelT>::writeFits(std::string const& fileName,
394  std::string const& mode) const {
395  fits::Fits fitsfile(fileName, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
396  writeFits(fitsfile, metadata_i);
397 }
398 
399 template <typename PixelT>
402  std::string const& mode) const {
403  fits::Fits fitsfile(manager, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
404  writeFits(fitsfile, metadata_i);
405 }
406 
407 template <typename PixelT>
408 void Image<PixelT>::writeFits(fits::Fits& fitsfile,
410  fitsfile.writeImage(*this, fits::ImageWriteOptions(*this), metadata);
411 }
412 
413 template <typename PixelT>
415  std::string const& filename,
417  std::string const& mode,
420 ) const {
421  fits::Fits fitsfile(filename, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
422  writeFits(fitsfile, options, header, mask);
423 }
424 
425 template <typename PixelT>
427  fits::MemFileManager& manager,
428  fits::ImageWriteOptions const& options,
429  std::string const& mode,
432 ) const {
433  fits::Fits fitsfile(manager, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
434  writeFits(fitsfile, options, header, mask);
435 }
436 
437 template <typename PixelT>
439  fits::Fits& fitsfile,
440  fits::ImageWriteOptions const& options,
443 ) const {
444  fitsfile.writeImage(*this, options, header, mask);
445 }
446 
447 
448 #endif // !DOXYGEN
449 
450 template <typename PixelT>
452  using std::swap; // See Meyers, Effective C++, Item 25
454  ; // no private variables to swap
455 }
456 
457 template <typename PixelT>
459  a.swap(b);
460 }
461 
462 // In-place, per-pixel, sqrt().
463 template <typename PixelT>
465  transform_pixels(_getRawView(), _getRawView(),
466  [](PixelT const& l) -> PixelT { return static_cast<PixelT>(std::sqrt(l)); });
467 }
468 
469 template <typename PixelT>
471  transform_pixels(_getRawView(), _getRawView(), [&rhs](PixelT const& l) -> PixelT { return l + rhs; });
472  return *this;
473 }
474 
475 template <typename PixelT>
477  if (this->getDimensions() != rhs.getDimensions()) {
479  (boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
480  this->getHeight() % rhs.getWidth() % rhs.getHeight())
481  .str());
482  }
483  transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(),
484  [](PixelT const& l, PixelT const& r) -> PixelT { return l + r; });
485  return *this;
486 }
487 
488 template <typename PixelT>
490  for (int y = 0; y != this->getHeight(); ++y) {
491  double const yPos = this->indexToPosition(y, Y);
492  double xPos = this->indexToPosition(0, X);
493  for (typename Image<PixelT>::x_iterator ptr = this->row_begin(y), end = this->row_end(y); ptr != end;
494  ++ptr, ++xPos) {
495  *ptr += function(xPos, yPos);
496  }
497  }
498  return *this;
499 }
500 
501 template <typename PixelT>
502 void Image<PixelT>::scaledPlus(double const c, Image<PixelT> const& rhs) {
503  if (this->getDimensions() != rhs.getDimensions()) {
505  (boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
506  this->getHeight() % rhs.getWidth() % rhs.getHeight())
507  .str());
508  }
509  transform_pixels(
510  _getRawView(), rhs._getRawView(), _getRawView(),
511  [&c](PixelT const& l, PixelT const& r) -> PixelT { return l + static_cast<PixelT>(c * r); });
512 }
513 
514 template <typename PixelT>
516  transform_pixels(_getRawView(), _getRawView(), [&rhs](PixelT const& l) -> PixelT { return l - rhs; });
517  return *this;
518 }
519 
520 template <typename PixelT>
522  if (this->getDimensions() != rhs.getDimensions()) {
524  (boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
525  this->getHeight() % rhs.getWidth() % rhs.getHeight())
526  .str());
527  }
528  transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(),
529  [](PixelT const& l, PixelT const& r) -> PixelT { return l - r; });
530  return *this;
531 }
532 
533 template <typename PixelT>
534 void Image<PixelT>::scaledMinus(double const c, Image<PixelT> const& rhs) {
535  if (this->getDimensions() != rhs.getDimensions()) {
537  (boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
538  this->getHeight() % rhs.getWidth() % rhs.getHeight())
539  .str());
540  }
541  transform_pixels(
542  _getRawView(), rhs._getRawView(), _getRawView(),
543  [&c](PixelT const& l, PixelT const& r) -> PixelT { return l - static_cast<PixelT>(c * r); });
544 }
545 
546 template <typename PixelT>
548  for (int y = 0; y != this->getHeight(); ++y) {
549  double const yPos = this->indexToPosition(y, Y);
550  double xPos = this->indexToPosition(0, X);
551  for (typename Image<PixelT>::x_iterator ptr = this->row_begin(y), end = this->row_end(y); ptr != end;
552  ++ptr, ++xPos) {
553  *ptr -= function(xPos, yPos);
554  }
555  }
556  return *this;
557 }
558 
559 template <typename PixelT>
561  transform_pixels(_getRawView(), _getRawView(), [&rhs](PixelT const& l) -> PixelT { return l * rhs; });
562  return *this;
563 }
564 
565 template <typename PixelT>
567  if (this->getDimensions() != rhs.getDimensions()) {
569  (boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
570  this->getHeight() % rhs.getWidth() % rhs.getHeight())
571  .str());
572  }
573  transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(),
574  [](PixelT const& l, PixelT const& r) -> PixelT { return l * r; });
575  return *this;
576 }
577 
578 template <typename PixelT>
579 void Image<PixelT>::scaledMultiplies(double const c, Image<PixelT> const& rhs) {
580  if (this->getDimensions() != rhs.getDimensions()) {
582  (boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
583  this->getHeight() % rhs.getWidth() % rhs.getHeight())
584  .str());
585  }
586  transform_pixels(
587  _getRawView(), rhs._getRawView(), _getRawView(),
588  [&c](PixelT const& l, PixelT const& r) -> PixelT { return l * static_cast<PixelT>(c * r); });
589 }
590 
591 template <typename PixelT>
593  transform_pixels(_getRawView(), _getRawView(), [&rhs](PixelT const& l) -> PixelT { return l / rhs; });
594  return *this;
595 }
596 //
597 // Specialize float and double for efficiency
598 //
599 template <>
601  double const irhs = 1 / rhs;
602  *this *= irhs;
603  return *this;
604 }
605 
606 template <>
608  float const irhs = 1 / rhs;
609  *this *= irhs;
610  return *this;
611 }
612 
613 template <typename PixelT>
615  if (this->getDimensions() != rhs.getDimensions()) {
617  (boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
618  this->getHeight() % rhs.getWidth() % rhs.getHeight())
619  .str());
620  }
621  transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(),
622  [](PixelT const& l, PixelT const& r) -> PixelT { return l / r; });
623  return *this;
624 }
625 
626 template <typename PixelT>
627 void Image<PixelT>::scaledDivides(double const c, Image<PixelT> const& rhs) {
628  if (this->getDimensions() != rhs.getDimensions()) {
630  (boost::format("Images are of different size, %dx%d v %dx%d") % this->getWidth() %
631  this->getHeight() % rhs.getWidth() % rhs.getHeight())
632  .str());
633  }
634  transform_pixels(
635  _getRawView(), rhs._getRawView(), _getRawView(),
636  [&c](PixelT const& l, PixelT const& r) -> PixelT { return l / static_cast<PixelT>(c * r); });
637 }
638 
639 namespace {
640 /*
641  * Worker routine for manipulating images;
642  */
643 template <typename LhsPixelT, typename RhsPixelT>
644 struct plusEq : 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 minusEq : public pixelOp2<LhsPixelT, RhsPixelT> {
650  LhsPixelT operator()(LhsPixelT lhs, RhsPixelT rhs) const { return static_cast<LhsPixelT>(lhs - rhs); }
651 };
652 
653 template <typename LhsPixelT, typename RhsPixelT>
654 struct timesEq : public pixelOp2<LhsPixelT, RhsPixelT> {
655  LhsPixelT operator()(LhsPixelT lhs, RhsPixelT rhs) const { return static_cast<LhsPixelT>(lhs * rhs); }
656 };
657 
658 template <typename LhsPixelT, typename RhsPixelT>
659 struct divideEq : public pixelOp2<LhsPixelT, RhsPixelT> {
660  LhsPixelT operator()(LhsPixelT lhs, RhsPixelT rhs) const { return static_cast<LhsPixelT>(lhs / rhs); }
661 };
662 }
663 
664 template <typename LhsPixelT, typename RhsPixelT>
666  for_each_pixel(lhs, rhs, plusEq<LhsPixelT, RhsPixelT>());
667  return lhs;
668 }
669 
670 template <typename LhsPixelT, typename RhsPixelT>
672  for_each_pixel(lhs, rhs, minusEq<LhsPixelT, RhsPixelT>());
673  return lhs;
674 }
675 
676 template <typename LhsPixelT, typename RhsPixelT>
678  for_each_pixel(lhs, rhs, timesEq<LhsPixelT, RhsPixelT>());
679  return lhs;
680 }
681 
682 template <typename LhsPixelT, typename RhsPixelT>
684  for_each_pixel(lhs, rhs, divideEq<LhsPixelT, RhsPixelT>());
685  return lhs;
686 }
687 
689 {
690  geom::Extent2I dims;
691  if (metadata.exists("ZNAXIS1") && metadata.exists("ZNAXIS2")) {
692  dims = geom::Extent2I(metadata.getAsInt("ZNAXIS1"), metadata.getAsInt("ZNAXIS2"));
693  } else {
694  dims = geom::Extent2I(metadata.getAsInt("NAXIS1"), metadata.getAsInt("NAXIS2"));
695  }
697  return geom::Box2I(xy0, dims);
698 }
699 
700 //
701 // Explicit instantiations
702 //
704 #define INSTANTIATE_OPERATOR(OP_EQ, T) \
705  template Image<T>& operator OP_EQ(Image<T>& lhs, Image<std::uint16_t> const& rhs); \
706  template Image<T>& operator OP_EQ(Image<T>& lhs, Image<int> const& rhs); \
707  template Image<T>& operator OP_EQ(Image<T>& lhs, Image<float> const& rhs); \
708  template Image<T>& operator OP_EQ(Image<T>& lhs, Image<double> const& rhs); \
709  template Image<T>& operator OP_EQ(Image<T>& lhs, Image<std::uint64_t> const& rhs);
710 
711 #define INSTANTIATE(T) \
712  template class ImageBase<T>; \
713  template class Image<T>; \
714  INSTANTIATE_OPERATOR(+=, T); \
715  INSTANTIATE_OPERATOR(-=, T); \
716  INSTANTIATE_OPERATOR(*=, T); \
717  INSTANTIATE_OPERATOR(/=, T)
718 
720 INSTANTIATE(int);
721 INSTANTIATE(float);
722 INSTANTIATE(double);
725 }
726 }
727 } // 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:168
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
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 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:688
double x
void swap(ImageBase &rhs)
Definition: Image.cc:226
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:458
#define LSST_EXCEPT(type,...)
reverse_iterator rend() const
Return an STL compliant reverse iterator to the end of the image.
Definition: Image.cc:258
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:51
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:253
iterator begin() const
Return an STL compliant iterator to the start of the image.
Definition: Image.cc:243
iterator at(int x, int y) const
Return an STL compliant iterator at the point (x, y)
Definition: Image.cc:263
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:71
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:451
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