LSSTApplications  17.0+11,17.0+34,17.0+56,17.0+57,17.0+59,17.0+7,17.0-1-g377950a+33,17.0.1-1-g114240f+2,17.0.1-1-g4d4fbc4+28,17.0.1-1-g55520dc+49,17.0.1-1-g5f4ed7e+52,17.0.1-1-g6dd7d69+17,17.0.1-1-g8de6c91+11,17.0.1-1-gb9095d2+7,17.0.1-1-ge9fec5e+5,17.0.1-1-gf4e0155+55,17.0.1-1-gfc65f5f+50,17.0.1-1-gfc6fb1f+20,17.0.1-10-g87f9f3f+1,17.0.1-11-ge9de802+16,17.0.1-16-ga14f7d5c+4,17.0.1-17-gc79d625+1,17.0.1-17-gdae4c4a+8,17.0.1-2-g26618f5+29,17.0.1-2-g54f2ebc+9,17.0.1-2-gf403422+1,17.0.1-20-g2ca2f74+6,17.0.1-23-gf3eadeb7+1,17.0.1-3-g7e86b59+39,17.0.1-3-gb5ca14a,17.0.1-3-gd08d533+40,17.0.1-30-g596af8797,17.0.1-4-g59d126d+4,17.0.1-4-gc69c472+5,17.0.1-6-g5afd9b9+4,17.0.1-7-g35889ee+1,17.0.1-7-gc7c8782+18,17.0.1-9-gc4bbfb2+3,w.2019.22
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/daf/base/Citizen.h"
50 #include "lsst/pex/exceptions.h"
51 #include "ndarray.h"
52 
53 namespace lsst {
54 namespace afw {
55 namespace image {
56 
58 template <typename PixelT>
59 class Image : public ImageBase<PixelT> {
60 public:
61  template <typename, typename, typename>
62  friend class MaskedImage;
63 
65 
67  template <typename ImagePT = PixelT>
71  };
72  template <typename OtherPixelT>
73  friend class Image; // needed by generalised copy constructors
74 
85  explicit Image(unsigned int width, unsigned int height, PixelT initialValue = 0);
95  explicit Image(lsst::geom::Extent2I const& dimensions = lsst::geom::Extent2I(), PixelT initialValue = 0);
102  explicit Image(lsst::geom::Box2I const& bbox, PixelT initialValue = 0);
103 
117  explicit Image(Image const& rhs, lsst::geom::Box2I const& bbox, ImageOrigin const origin = PARENT,
118  const bool deep = false);
128  Image(const Image& rhs, const bool deep = false);
129  Image(Image&& rhs);
130 
145  explicit Image(std::string const& fileName, int hdu = fits::DEFAULT_HDU,
149  bool allowUnsafe=false);
150 
165  explicit Image(fits::MemFileManager& manager, int hdu = fits::DEFAULT_HDU,
169  bool allowUnsafe=false);
170 
182  explicit Image(fits::Fits& fitsfile,
186  bool allowUnsafe=false);
187 
188  // generalised copy constructor
189  template <typename OtherPixelT>
190  Image(Image<OtherPixelT> const& rhs, const bool deep) : image::ImageBase<PixelT>(rhs, deep) {}
191 
192  explicit Image(ndarray::Array<PixelT, 2, 1> const& array, bool deep = false,
194  : image::ImageBase<PixelT>(array, deep, xy0) {}
195 
196  ~Image() override = default;
197  //
198  // Assignment operators are not inherited
199  //
201  Image& operator=(const PixelT rhs);
211  Image& operator=(const Image& rhs);
212  Image& operator=(Image&& rhs);
213 
228  return Image(*this, bbox, origin, false);
229  }
230 
233  return subset(bbox);
234  }
235 
237 
245  void writeFits(std::string const& fileName,
248  std::string const& mode = "w") const;
249 
257  void writeFits(fits::MemFileManager& manager,
260  std::string const& mode = "w") const;
261 
270 
280  void writeFits(std::string const& filename, fits::ImageWriteOptions const& options,
281  std::string const& mode = "w",
283  std::shared_ptr<Mask<MaskPixel> const> mask = nullptr) const;
284 
294  void writeFits(fits::MemFileManager& manager, fits::ImageWriteOptions const& options,
295  std::string const& mode = "w",
297  std::shared_ptr<Mask<MaskPixel> const> mask = nullptr) const;
298 
307  void writeFits(fits::Fits& fitsfile, fits::ImageWriteOptions const& options,
309  std::shared_ptr<Mask<MaskPixel> const> mask = nullptr) const;
310 
319  static Image readFits(std::string const& filename, int hdu = fits::DEFAULT_HDU) {
320  return Image<PixelT>(filename, hdu);
321  }
322 
331  static Image readFits(fits::MemFileManager& manager, int hdu = fits::DEFAULT_HDU) {
332  return Image<PixelT>(manager, hdu);
333  }
334 
335  void swap(Image& rhs);
336  //
337  // Operators etc.
338  //
340  Image& operator+=(PixelT const rhs);
342  virtual Image& operator+=(Image<PixelT> const& rhs);
350  void scaledPlus(double const c, Image<PixelT> const& rhs);
352  Image& operator-=(PixelT const rhs);
354  Image& operator-=(Image<PixelT> const& rhs);
362  void scaledMinus(double const c, Image<PixelT> const& rhs);
364  Image& operator*=(PixelT const rhs);
366  Image& operator*=(Image<PixelT> const& rhs);
368  void scaledMultiplies(double const c, Image<PixelT> const& rhs);
374  Image& operator/=(PixelT const rhs);
376  Image& operator/=(Image<PixelT> const& rhs);
378  void scaledDivides(double const c, Image<PixelT> const& rhs);
379 
380  // In-place per-pixel sqrt(). Useful when handling variance planes.
381  void sqrt();
382 
383 protected:
385 };
386 
388 template <typename LhsPixelT, typename RhsPixelT>
391 template <typename LhsPixelT, typename RhsPixelT>
394 template <typename LhsPixelT, typename RhsPixelT>
397 template <typename LhsPixelT, typename RhsPixelT>
399 
400 template <typename PixelT>
402 
406 template <typename PixelT>
408 public:
423  explicit DecoratedImage(const lsst::geom::Box2I& bbox);
440  DecoratedImage(DecoratedImage const& rhs, const bool deep = false);
451  explicit DecoratedImage(std::string const& fileName, const int hdu = fits::DEFAULT_HDU,
452  lsst::geom::Box2I const& bbox = lsst::geom::Box2I(),
453  ImageOrigin const origin = PARENT, bool allowUnsafe=false);
454 
461 
463  void setMetadata(std::shared_ptr<lsst::daf::base::PropertySet> metadata) { _metadata = metadata; }
464 
466  int getWidth() const { return _image->getWidth(); }
468  int getHeight() const { return _image->getHeight(); }
469 
471  int getX0() const { return _image->getX0(); }
473  int getY0() const { return _image->getY0(); }
474 
476  const lsst::geom::Extent2I getDimensions() const { return _image->getDimensions(); }
477 
478  void swap(DecoratedImage& rhs);
479 
487  void writeFits(std::string const& fileName,
490  std::string const& mode = "w") const;
491 
500  void writeFits(std::string const& fileName, fits::ImageWriteOptions const& options,
503  std::string const& mode = "w") const;
504 
508  std::shared_ptr<Image<PixelT> const> getImage() const { return _image; }
509 
515  double getGain() const { return _gain; }
517  void setGain(double gain) { _gain = gain; }
518 
519 private:
522 
523  double _gain;
524 
525  void init();
526 };
527 
528 template <typename PixelT>
530 
536 
540 template <typename T1, typename T2>
541 bool imagesOverlap(ImageBase<T1> const& image1, ImageBase<T2> const& image2);
542 
543 } // namespace image
544 } // namespace afw
545 } // namespace lsst
546 
547 #endif
std::shared_ptr< Image< PixelT > > getImage()
Return a shared_ptr to the DecoratedImage&#39;s Image.
Definition: Image.h:506
Image operator[](lsst::geom::Box2I const &bbox) const
Return a subimage corresponding to the given box (interpreted as PARENT coordinates).
Definition: Image.h:232
std::shared_ptr< Image< PixelT > const > getImage() const
Return a shared_ptr to the DecoratedImage&#39;s Image as const.
Definition: Image.h:508
A templated class to return this classes&#39; type (present in Image/Mask/MaskedImage) ...
Definition: Image.h:68
Image & operator=(const PixelT rhs)
Set the image&#39;s pixels to rhs.
Definition: Image.cc:362
afw::table::PointKey< int > dimensions
Definition: GaussianPsf.cc:49
Image & operator*=(PixelT const rhs)
Multiply lhs by scalar rhs.
Definition: Image.cc:573
std::shared_ptr< lsst::daf::base::PropertySet > getMetadata() const
Definition: Image.h:462
static int init()
Called once when the memory system is being initialised.
Definition: Citizen.cc:196
int getWidth() const
Return the number of columns in the image.
Definition: Image.h:466
int getHeight() const
Return the number of rows in the image.
Definition: Image.h:468
table::Key< int > b
Options for writing an image to FITS.
Definition: fits.h:219
Image & operator/=(PixelT const rhs)
Divide lhs by scalar rhs.
Definition: Image.cc:605
table::Key< int > a
void scaledDivides(double const c, Image< PixelT > const &rhs)
Divide lhs by Image c*rhs (i.e. pixel-by-pixel division)
Definition: Image.cc:640
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.
tuple options
Definition: lsstimport.py:47
void setMetadata(std::shared_ptr< lsst::daf::base::PropertySet > metadata)
Definition: Image.h:463
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:297
The base class for all image classed (Image, Mask, MaskedImage, ...)
Definition: ImageBase.h:103
Image subset(lsst::geom::Box2I const &bbox, ImageOrigin origin=PARENT) const
Return a subimage corresponding to the given box.
Definition: Image.h:227
A Function taking two arguments.
Definition: Function.h:261
STL class.
Image & operator-=(PixelT const rhs)
Subtract scalar rhs from lhs.
Definition: Image.cc:528
A base class for image defects.
Represent a 2-dimensional array of bitmask pixels.
Definition: Mask.h:78
Image(ndarray::Array< PixelT, 2, 1 > const &array, bool deep=false, lsst::geom::Point2I const &xy0=lsst::geom::Point2I())
Definition: Image.h:192
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:121
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:74
Image & operator+=(PixelT const rhs)
Add scalar rhs to lhs.
Definition: Image.cc:483
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:721
void setGain(double gain)
Set the DecoratedImage&#39;s gain.
Definition: Image.h:517
void scaledPlus(double const c, Image< PixelT > const &rhs)
Add Image c*rhs to lhs.
Definition: Image.cc:515
table::Box2IKey bbox
Definition: Detector.cc:169
~Image() override=default
afw::table::Key< afw::table::Array< MaskPixelT > > mask
friend class DecoratedImage
Definition: ImageBase.h:167
void scaledMultiplies(double const c, Image< PixelT > const &rhs)
Multiply lhs by Image c*rhs (i.e. pixel-by-pixel multiplication)
Definition: Image.cc:592
Class for storing generic metadata.
Definition: PropertySet.h:68
int getX0() const
Return the image&#39;s column-origin.
Definition: Image.h:471
const lsst::geom::Extent2I getDimensions() const
Return the image&#39;s size; useful for passing to constructors.
Definition: Image.h:476
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
Definition: Citizen.h:55
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...
friend class Image
Definition: Image.h:73
Image(Image< OtherPixelT > const &rhs, const bool deep)
Definition: Image.h:190
static Image readFits(std::string const &filename, int hdu=fits::DEFAULT_HDU)
Read an Image from a regular FITS file.
Definition: Image.h:319
An integer coordinate rectangle.
Definition: Box.h:54
void swap(Image &rhs)
Definition: Image.cc:464
static Image readFits(fits::MemFileManager &manager, int hdu=fits::DEFAULT_HDU)
Read an Image from a FITS RAM file.
Definition: Image.h:331
lsst::geom::Box2I bboxFromMetadata(daf::base::PropertySet &metadata)
Determine the image bounding box from its metadata (FITS header)
Definition: Image.cc:709
int getY0() const
Return the image&#39;s row-origin.
Definition: Image.h:473
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:59
detail::Image_tag image_category
Definition: Image.h:64
double getGain() const
Return the DecoratedImage&#39;s gain.
Definition: Image.h:515
Image< ImagePT > type
Return the desired type.
Definition: Image.h:70
A container for an Image and its associated metadata.
Definition: Image.h:407
void scaledMinus(double const c, Image< PixelT > const &rhs)
Subtract Image c*rhs from lhs.
Definition: Image.cc:547
const int DEFAULT_HDU
Specify that the default HDU should be read.
Definition: fitsDefaults.h:18