LSSTApplications  21.0.0+1b62c9342b,21.0.0+45a059f35e,21.0.0-1-ga51b5d4+ceb9cf20a3,21.0.0-2-g103fe59+4d13aff7ba,21.0.0-2-g1367e85+571a348718,21.0.0-2-g2909d54+45a059f35e,21.0.0-2-g45278ab+1b62c9342b,21.0.0-2-g4bc9b9f+ebfe466dad,21.0.0-2-g5242d73+571a348718,21.0.0-2-g54e2caa+ae261561d3,21.0.0-2-g66bcc37+0b2c5d3971,21.0.0-2-g7f82c8f+08f1f55c36,21.0.0-2-g8dde007+5d1b9cb3f5,21.0.0-2-g8f08a60+73884b2cf5,21.0.0-2-ga326454+08f1f55c36,21.0.0-2-ga63a54e+5beb793fda,21.0.0-2-gc738bc1+8c4731df06,21.0.0-2-gde069b7+5a8f2956b8,21.0.0-2-ge17e5af+571a348718,21.0.0-2-ge712728+cfa36ee5f9,21.0.0-2-gecfae73+e597808034,21.0.0-2-gfc62afb+571a348718,21.0.0-20-g4449a12+6d1341e0f3,21.0.0-21-g006371a9+1cd928f0c5,21.0.0-3-g4c5b185+c3794955c6,21.0.0-3-g6d51c4a+0b2c5d3971,21.0.0-3-g8076721+5adeb471db,21.0.0-3-gaa929c8+01f4b7cfca,21.0.0-3-gd222c45+afc8332dbe,21.0.0-4-g1383c07+0b2c5d3971,21.0.0-4-g3300ddd+1b62c9342b,21.0.0-4-g5873dc9+9a92674037,21.0.0-4-g8a80011+ca0917f8b6,21.0.0-5-gcff38f6+36b2eaf090,21.0.0-6-g463d161+bfc341698e,21.0.0-6-gd3283ba+01f4b7cfca,21.0.0-8-g19111d86+8234efb485,21.0.0-9-g7bed000b9+c7d3cce47e,w.2021.04
LSSTDataManagementBasePackage
Image.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
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  * 2-D images
27  *
28  * This file contains the 2-d image support for LSST
29  */
30 #ifndef LSST_AFW_IMAGE_IMAGE_H
31 #define LSST_AFW_IMAGE_IMAGE_H
32 
33 #include <string>
34 #include <utility>
35 #include <functional>
36 
37 #include "boost/mpl/bool.hpp"
38 #include <climits>
39 #include <memory>
40 
41 #include "lsst/geom.h"
43 #include "lsst/afw/image/lsstGil.h"
45 #include "lsst/afw/image/Mask.h"
46 #include "lsst/afw/math/Function.h"
47 #include "lsst/afw/fitsDefaults.h"
49 #include "lsst/pex/exceptions.h"
50 #include "ndarray.h"
51 
52 namespace lsst {
53 namespace afw {
54 namespace image {
55 
57 template <typename PixelT>
58 class Image : public ImageBase<PixelT> {
59 public:
60  template <typename, typename, typename>
61  friend class MaskedImage;
62 
64 
66  template <typename ImagePT = PixelT>
70  };
71  template <typename OtherPixelT>
72  friend class Image; // needed by generalised copy constructors
73 
84  explicit Image(unsigned int width, unsigned int height, PixelT initialValue = 0);
94  explicit Image(lsst::geom::Extent2I const& dimensions = lsst::geom::Extent2I(), PixelT initialValue = 0);
101  explicit Image(lsst::geom::Box2I const& bbox, PixelT initialValue = 0);
102 
116  explicit Image(Image const& rhs, lsst::geom::Box2I const& bbox, ImageOrigin const origin = PARENT,
117  const bool deep = false);
127  Image(const Image& rhs, const bool deep = false);
128  Image(Image&& rhs);
129 
144  explicit Image(std::string const& fileName, int hdu = fits::DEFAULT_HDU,
148  bool allowUnsafe = false);
149 
164  explicit Image(fits::MemFileManager& manager, int hdu = fits::DEFAULT_HDU,
168  bool allowUnsafe = false);
169 
181  explicit Image(fits::Fits& fitsfile,
185  bool allowUnsafe = false);
186 
187  // generalised copy constructor
188  template <typename OtherPixelT>
189  Image(Image<OtherPixelT> const& rhs, const bool deep) : image::ImageBase<PixelT>(rhs, deep) {}
190 
191  explicit Image(ndarray::Array<PixelT, 2, 1> const& array, bool deep = false,
193  : image::ImageBase<PixelT>(array, deep, xy0) {}
194 
195  ~Image() override = default;
196  //
197  // Assignment operators are not inherited
198  //
200  Image& operator=(const PixelT rhs);
210  Image& operator=(const Image& rhs);
211  Image& operator=(Image&& rhs);
212 
227  return Image(*this, bbox, origin, false);
228  }
229 
231  Image operator[](lsst::geom::Box2I const& bbox) const { return subset(bbox); }
232 
234 
242  void writeFits(std::string const& fileName,
245  std::string const& mode = "w") const;
246 
257  std::string const& mode = "w") const;
258 
267 
277  void writeFits(std::string const& filename, fits::ImageWriteOptions const& options,
278  std::string const& mode = "w",
280  std::shared_ptr<Mask<MaskPixel> const> mask = nullptr) const;
281 
292  std::string const& mode = "w",
294  std::shared_ptr<Mask<MaskPixel> const> mask = nullptr) const;
295 
304  void writeFits(fits::Fits& fitsfile, fits::ImageWriteOptions const& options,
306  std::shared_ptr<Mask<MaskPixel> const> mask = nullptr) const;
307 
316  static Image readFits(std::string const& filename, int hdu = fits::DEFAULT_HDU) {
317  return Image<PixelT>(filename, hdu);
318  }
319 
328  static Image readFits(fits::MemFileManager& manager, int hdu = fits::DEFAULT_HDU) {
329  return Image<PixelT>(manager, hdu);
330  }
331 
332  void swap(Image& rhs);
333  //
334  // Operators etc.
335  //
337  Image& operator+=(PixelT const rhs);
339  virtual Image& operator+=(Image<PixelT> const& rhs);
347  void scaledPlus(double const c, Image<PixelT> const& rhs);
349  Image& operator-=(PixelT const rhs);
351  Image& operator-=(Image<PixelT> const& rhs);
359  void scaledMinus(double const c, Image<PixelT> const& rhs);
361  Image& operator*=(PixelT const rhs);
363  Image& operator*=(Image<PixelT> const& rhs);
365  void scaledMultiplies(double const c, Image<PixelT> const& rhs);
371  Image& operator/=(PixelT const rhs);
373  Image& operator/=(Image<PixelT> const& rhs);
375  void scaledDivides(double const c, Image<PixelT> const& rhs);
376 
377  // In-place per-pixel sqrt(). Useful when handling variance planes.
378  void sqrt();
379 
380 protected:
382 };
383 
385 template <typename LhsPixelT, typename RhsPixelT>
386 Image<LhsPixelT>& operator+=(Image<LhsPixelT>& lhs, Image<RhsPixelT> const& rhs);
388 template <typename LhsPixelT, typename RhsPixelT>
389 Image<LhsPixelT>& operator-=(Image<LhsPixelT>& lhs, Image<RhsPixelT> const& rhs);
391 template <typename LhsPixelT, typename RhsPixelT>
392 Image<LhsPixelT>& operator*=(Image<LhsPixelT>& lhs, Image<RhsPixelT> const& rhs);
394 template <typename LhsPixelT, typename RhsPixelT>
395 Image<LhsPixelT>& operator/=(Image<LhsPixelT>& lhs, Image<RhsPixelT> const& rhs);
396 
397 template <typename PixelT>
398 void swap(Image<PixelT>& a, Image<PixelT>& b);
399 
403 template <typename PixelT>
405 public:
420  explicit DecoratedImage(const lsst::geom::Box2I& bbox);
437  DecoratedImage(DecoratedImage const& rhs, const bool deep = false);
448  explicit DecoratedImage(std::string const& fileName, const int hdu = fits::DEFAULT_HDU,
450  ImageOrigin const origin = PARENT, bool allowUnsafe = false);
451 
458 
460  void setMetadata(std::shared_ptr<lsst::daf::base::PropertySet> metadata) { _metadata = metadata; }
461 
463  int getWidth() const { return _image->getWidth(); }
465  int getHeight() const { return _image->getHeight(); }
466 
468  int getX0() const { return _image->getX0(); }
470  int getY0() const { return _image->getY0(); }
471 
473  const lsst::geom::Extent2I getDimensions() const { return _image->getDimensions(); }
474 
475  void swap(DecoratedImage& rhs);
476 
484  void writeFits(std::string const& fileName,
487  std::string const& mode = "w") const;
488 
497  void writeFits(std::string const& fileName, fits::ImageWriteOptions const& options,
500  std::string const& mode = "w") const;
501 
505  std::shared_ptr<Image<PixelT> const> getImage() const { return _image; }
506 
512  double getGain() const { return _gain; }
514  void setGain(double gain) { _gain = gain; }
515 
516 private:
519 
520  double _gain;
521 
522  void init();
523 };
524 
525 template <typename PixelT>
526 void swap(DecoratedImage<PixelT>& a, DecoratedImage<PixelT>& b);
527 
533 
537 template <typename T1, typename T2>
538 bool imagesOverlap(ImageBase<T1> const& image1, ImageBase<T2> const& image2);
539 
540 } // namespace image
541 } // namespace afw
542 } // namespace lsst
543 
544 #endif
lsst::afw::image::Image::writeFits
void writeFits(std::string const &fileName, std::shared_ptr< lsst::daf::base::PropertySet const > metadata=std::shared_ptr< lsst::daf::base::PropertySet const >(), std::string const &mode="w") const
Write an image to a regular FITS file.
lsst::afw::image::Image::Image
Image(Image< OtherPixelT > const &rhs, const bool deep)
Definition: Image.h:189
lsst::afw::image
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
Definition: imageAlgorithm.dox:1
exceptions.h
lsst::afw::image::DecoratedImage
A container for an Image and its associated metadata.
Definition: Image.h:404
lsst::afw::image::DecoratedImage::getY0
int getY0() const
Return the image's row-origin.
Definition: Image.h:470
std::string
STL class.
lsst::afw::image::Image::operator*=
Image & operator*=(PixelT const rhs)
Multiply lhs by scalar rhs.
Definition: Image.cc:552
std::shared_ptr< lsst::daf::base::PropertySet >
lsst::afw::image::Mask
Represent a 2-dimensional array of bitmask pixels.
Definition: Mask.h:77
lsst::afw::fits::DEFAULT_HDU
const int DEFAULT_HDU
Specify that the default HDU should be read.
Definition: fitsDefaults.h:18
lsst::afw::image::Image::Image
Image(fits::Fits &fitsfile, std::shared_ptr< lsst::daf::base::PropertySet > metadata=std::shared_ptr< lsst::daf::base::PropertySet >(), lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool allowUnsafe=false)
Construct an Image from an already-open FITS object.
lsst::afw::image::Image::scaledMultiplies
void scaledMultiplies(double const c, Image< PixelT > const &rhs)
Multiply lhs by Image c*rhs (i.e. pixel-by-pixel multiplication)
Definition: Image.cc:571
lsst::afw::fits::Fits
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:297
lsst::afw::image::Image::readFits
static Image readFits(fits::MemFileManager &manager, int hdu=fits::DEFAULT_HDU)
Read an Image from a FITS RAM file.
Definition: Image.h:328
ImageBase.h
lsst::afw::image::DecoratedImage::setMetadata
void setMetadata(std::shared_ptr< lsst::daf::base::PropertySet > metadata)
Definition: Image.h:460
lsst::ip::diffim::detail::PixelT
float PixelT
Definition: AssessSpatialKernelVisitor.cc:208
lsst::afw
Definition: imageAlgorithm.dox:1
geom.h
lsst::afw::image::DecoratedImage::operator=
DecoratedImage & operator=(const DecoratedImage &image)
Assignment operator.
Definition: DecoratedImage.cc:74
lsst::afw::image::Image::operator/=
Image & operator/=(PixelT const rhs)
Divide lhs by scalar rhs.
Definition: Image.cc:584
lsst::afw::image::Image::operator+=
Image & operator+=(PixelT const rhs)
Add scalar rhs to lhs.
Definition: Image.cc:462
lsst::afw::fits::MemFileManager
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:121
mask
afw::table::Key< afw::table::Array< MaskPixelT > > mask
Definition: HeavyFootprint.cc:217
lsst::afw::fits::ImageWriteOptions
Options for writing an image to FITS.
Definition: fits.h:219
lsst::afw::image::Image::scaledPlus
void scaledPlus(double const c, Image< PixelT > const &rhs)
Add Image c*rhs to lhs.
Definition: Image.cc:494
lsst::afw::image::Image::writeFits
void writeFits(std::string const &filename, fits::ImageWriteOptions const &options, std::string const &mode="w", std::shared_ptr< daf::base::PropertySet const > header=nullptr, std::shared_ptr< Mask< MaskPixel > const > mask=nullptr) const
Write an image to a regular FITS file.
lsst::afw::image::operator*=
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:677
lsst::afw::image::DecoratedImage::swap
void swap(DecoratedImage &rhs)
Definition: DecoratedImage.cc:82
lsst::afw::image::Image::scaledMinus
void scaledMinus(double const c, Image< PixelT > const &rhs)
Subtract Image c*rhs from lhs.
Definition: Image.cc:526
lsst::afw::image::Image::operator[]
Image operator[](lsst::geom::Box2I const &bbox) const
Return a subimage corresponding to the given box (interpreted as PARENT coordinates).
Definition: Image.h:231
lsst::afw::image::Image::readFits
static Image readFits(std::string const &filename, int hdu=fits::DEFAULT_HDU)
Read an Image from a regular FITS file.
Definition: Image.h:316
lsst::afw::image::MaskedImage
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:73
lsst::afw::image::DecoratedImage::setGain
void setGain(double gain)
Set the DecoratedImage's gain.
Definition: Image.h:514
lsst::afw::image::Image::writeFits
void writeFits(fits::MemFileManager &manager, fits::ImageWriteOptions const &options, std::string const &mode="w", std::shared_ptr< daf::base::PropertySet const > header=nullptr, std::shared_ptr< Mask< MaskPixel > const > mask=nullptr) const
Write an image to a FITS RAM file.
fitsDefaults.h
lsst::afw::image::DecoratedImage::getX0
int getX0() const
Return the image's column-origin.
Definition: Image.h:468
lsst::afw::image::Image::Image
Image(std::string const &fileName, int hdu=fits::DEFAULT_HDU, std::shared_ptr< lsst::daf::base::PropertySet > metadata=std::shared_ptr< lsst::daf::base::PropertySet >(), lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool allowUnsafe=false)
Construct an Image by reading a regular FITS file.
lsst::afw::image::Image::Image
friend class Image
Definition: Image.h:72
PropertySet.h
lsst::afw::image::DecoratedImage::getHeight
int getHeight() const
Return the number of rows in the image.
Definition: Image.h:465
lsst::afw::image::DecoratedImage::getGain
double getGain() const
Return the DecoratedImage's gain.
Definition: Image.h:512
lsst::afw::image::Image::Image
Image(ndarray::Array< PixelT, 2, 1 > const &array, bool deep=false, lsst::geom::Point2I const &xy0=lsst::geom::Point2I())
Definition: Image.h:191
dimensions
afw::table::PointKey< int > dimensions
Definition: GaussianPsf.cc:49
lsst::afw::image::Image::ImageTypeFactory
A templated class to return this classes' type (present in Image/Mask/MaskedImage)
Definition: Image.h:67
lsst::afw::image::Image::operator=
Image & operator=(const PixelT rhs)
Set the image's pixels to rhs.
Definition: Image.cc:344
lsst::afw::image::Image::writeFits
void writeFits(fits::MemFileManager &manager, std::shared_ptr< lsst::daf::base::PropertySet const > metadata=std::shared_ptr< lsst::daf::base::PropertySet const >(), std::string const &mode="w") const
Write an image to a FITS RAM file.
lsst::afw::image::operator-=
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:671
b
table::Key< int > b
Definition: TransmissionCurve.cc:467
lsst::afw::image::DecoratedImage::getWidth
int getWidth() const
Return the number of columns in the image.
Definition: Image.h:463
lsst::afw::image::DecoratedImage::getImage
std::shared_ptr< Image< PixelT > const > getImage() const
Return a shared_ptr to the DecoratedImage's Image as const.
Definition: Image.h:505
lsst::afw::image::Image::image_category
detail::Image_tag image_category
Definition: Image.h:63
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
lsst::afw::image::DecoratedImage::DecoratedImage
DecoratedImage(const lsst::geom::Extent2I &dimensions=lsst::geom::Extent2I())
Create an image of the specified size.
Definition: DecoratedImage.cc:56
lsst::afw::image::detail::Image_tag
tag for an Image
Definition: ImageBase.h:63
lsst::afw::image::Image::writeFits
void writeFits(fits::Fits &fitsfile, fits::ImageWriteOptions const &options, std::shared_ptr< daf::base::PropertySet const > header=nullptr, std::shared_ptr< Mask< MaskPixel > const > mask=nullptr) const
Write an image to an open FITS file object.
lsst::afw::image::bboxFromMetadata
lsst::geom::Box2I bboxFromMetadata(daf::base::PropertySet &metadata)
Determine the image bounding box from its metadata (FITS header)
Definition: Image.cc:688
lsst::afw::math::Function2< double >
Mask.h
gain
table::Key< double > gain
Definition: Amplifier.cc:118
a
table::Key< int > a
Definition: TransmissionCurve.cc:466
lsst::afw::image::DecoratedImage::getImage
std::shared_ptr< Image< PixelT > > getImage()
Return a shared_ptr to the DecoratedImage's Image.
Definition: Image.h:503
lsst::afw::image::operator/=
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:683
lsst::afw::image::DecoratedImage::getDimensions
const lsst::geom::Extent2I getDimensions() const
Return the image's size; useful for passing to constructors.
Definition: Image.h:473
lsst::geom::Point< int, 2 >
lsst::daf::base::PropertySet
Class for storing generic metadata.
Definition: PropertySet.h:67
lsst::afw::image::Image::subset
Image subset(lsst::geom::Box2I const &bbox, ImageOrigin origin=PARENT) const
Return a subimage corresponding to the given box.
Definition: Image.h:226
lsst::geom::Box2I
An integer coordinate rectangle.
Definition: Box.h:55
lsst::afw::image::Image::sqrt
void sqrt()
Definition: Image.cc:456
lsst::afw::image::PARENT
@ PARENT
Definition: ImageBase.h:94
lsst::afw::image::swap
void swap(Image< PixelT > &a, Image< PixelT > &b)
Definition: Image.cc:450
ImageUtils.h
lsst::afw::image::operator+=
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:665
lsst::afw::image::ImageOrigin
ImageOrigin
Definition: ImageBase.h:94
lsst::afw::image::imagesOverlap
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:700
lsst::afw::image::Image::Image
Image(fits::MemFileManager &manager, int hdu=fits::DEFAULT_HDU, std::shared_ptr< lsst::daf::base::PropertySet > metadata=std::shared_ptr< lsst::daf::base::PropertySet >(), lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool allowUnsafe=false)
Construct an Image by reading a FITS image in memory.
lsst::afw::image::Image::swap
void swap(Image &rhs)
Definition: Image.cc:443
lsst::afw::image::DecoratedImage::getMetadata
std::shared_ptr< lsst::daf::base::PropertySet > getMetadata() const
Definition: Image.h:459
lsst::afw::image::Image
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:58
lsst::afw::image::Image::~Image
~Image() override=default
lsst::afw::image::Image::operator-=
Image & operator-=(PixelT const rhs)
Subtract scalar rhs from lhs.
Definition: Image.cc:507
Function.h
lsst::afw::image::ImageBase
The base class for all image classed (Image, Mask, MaskedImage, ...)
Definition: ImageBase.h:102
lsst::afw::image::Image::writeFits
void writeFits(fits::Fits &fitsfile, std::shared_ptr< lsst::daf::base::PropertySet const > metadata=std::shared_ptr< lsst::daf::base::PropertySet const >()) const
Write an image to an open FITS file object.
lsst::geom::Extent< int, 2 >
lsst::afw::image::Image::ImageTypeFactory::type
Image< ImagePT > type
Return the desired type.
Definition: Image.h:69
bbox
AmpInfoBoxKey bbox
Definition: Amplifier.cc:117
lsstGil.h
lsst::afw::image::Image::scaledDivides
void scaledDivides(double const c, Image< PixelT > const &rhs)
Divide lhs by Image c*rhs (i.e. pixel-by-pixel division)
Definition: Image.cc:619
lsst::afw::image::DecoratedImage::writeFits
void writeFits(std::string const &fileName, std::shared_ptr< lsst::daf::base::PropertySet const > metadata=std::shared_ptr< lsst::daf::base::PropertySet const >(), std::string const &mode="w") const
Write a FITS file.
Definition: DecoratedImage.cc:107