lsst.afw  16.0-19-g2da375352+1
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"
48 #include "lsst/daf/base.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 
56 namespace formatters {
57 template <typename PixelT>
58 class ImageFormatter;
59 template <typename PixelT>
60 class DecoratedImageFormatter;
61 } // namespace formatters
62 
63 namespace image {
64 
66 template <typename PixelT>
67 class Image : public ImageBase<PixelT> {
68 public:
69  template <typename, typename, typename>
70  friend class MaskedImage;
71 
73 
75  template <typename ImagePT = PixelT>
79  };
80  template <typename OtherPixelT>
81  friend class Image; // needed by generalised copy constructors
82 
93  explicit Image(unsigned int width, unsigned int height, PixelT initialValue = 0);
103  explicit Image(lsst::geom::Extent2I const& dimensions = lsst::geom::Extent2I(), PixelT initialValue = 0);
110  explicit Image(lsst::geom::Box2I const& bbox, PixelT initialValue = 0);
111 
125  explicit Image(Image const& rhs, lsst::geom::Box2I const& bbox, ImageOrigin const origin = PARENT,
126  const bool deep = false);
136  Image(const Image& rhs, const bool deep = false);
137  Image(Image&& rhs);
138 
151  explicit Image(std::string const& fileName, int hdu = fits::DEFAULT_HDU,
155 
168  explicit Image(fits::MemFileManager& manager, int hdu = fits::DEFAULT_HDU,
172 
182  explicit Image(fits::Fits& fitsfile,
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  virtual ~Image() = 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 
232  return subset(bbox);
233  }
234 
236 
244  void writeFits(std::string const& fileName,
247  std::string const& mode = "w") const;
248 
256  void writeFits(fits::MemFileManager& manager,
259  std::string const& mode = "w") const;
260 
267  void writeFits(fits::Fits& fitsfile, std::shared_ptr<lsst::daf::base::PropertySet const> metadata =
269 
279  void writeFits(std::string const& filename, fits::ImageWriteOptions const& options,
280  std::string const& mode = "w",
282  std::shared_ptr<Mask<MaskPixel> const> mask = nullptr) const;
283 
293  void writeFits(fits::MemFileManager& manager, fits::ImageWriteOptions const& options,
294  std::string const& mode = "w",
296  std::shared_ptr<Mask<MaskPixel> const> mask = nullptr) const;
297 
306  void writeFits(fits::Fits& fitsfile, fits::ImageWriteOptions const& options,
308  std::shared_ptr<Mask<MaskPixel> const> mask = nullptr) const;
309 
318  static Image readFits(std::string const& filename, int hdu = fits::DEFAULT_HDU) {
319  return Image<PixelT>(filename, hdu);
320  }
321 
330  static Image readFits(fits::MemFileManager& manager, int hdu = fits::DEFAULT_HDU) {
331  return Image<PixelT>(manager, hdu);
332  }
333 
334  void swap(Image& rhs);
335  //
336  // Operators etc.
337  //
339  Image& operator+=(PixelT const rhs);
341  virtual Image& operator+=(Image<PixelT> const& rhs);
349  void scaledPlus(double const c, Image<PixelT> const& rhs);
351  Image& operator-=(PixelT const rhs);
353  Image& operator-=(Image<PixelT> const& rhs);
361  void scaledMinus(double const c, Image<PixelT> const& rhs);
363  Image& operator*=(PixelT const rhs);
365  Image& operator*=(Image<PixelT> const& rhs);
367  void scaledMultiplies(double const c, Image<PixelT> const& rhs);
373  Image& operator/=(PixelT const rhs);
375  Image& operator/=(Image<PixelT> const& rhs);
377  void scaledDivides(double const c, Image<PixelT> const& rhs);
378 
379  // In-place per-pixel sqrt(). Useful when handling variance planes.
380  void sqrt();
381 
382 protected:
384 
385 private:
387 };
388 
390 template <typename LhsPixelT, typename RhsPixelT>
393 template <typename LhsPixelT, typename RhsPixelT>
396 template <typename LhsPixelT, typename RhsPixelT>
399 template <typename LhsPixelT, typename RhsPixelT>
401 
402 template <typename PixelT>
404 
408 template <typename PixelT>
410 public:
425  explicit DecoratedImage(const lsst::geom::Box2I& bbox);
442  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);
454 
460  DecoratedImage& operator=(const DecoratedImage& image);
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 
495  std::shared_ptr<Image<PixelT> const> getImage() const { return _image; }
496 
502  double getGain() const { return _gain; }
504  void setGain(double gain) { _gain = gain; }
505 
506 private:
510 
511  double _gain;
512 
513  void init();
514 };
515 
516 template <typename PixelT>
518 
524 
528 template <typename T1, typename T2>
529 bool imagesOverlap(ImageBase<T1> const& image1, ImageBase<T2> const& image2);
530 
531 } // namespace image
532 } // namespace afw
533 } // namespace lsst
534 
535 #endif
std::shared_ptr< Image< PixelT > > getImage()
Return a shared_ptr to the DecoratedImage&#39;s Image.
Definition: Image.h:493
Image operator[](lsst::geom::Box2I const &bbox) const
Return a subimage corresponding to the given box (interpreted as PARENT coordinates).
Definition: Image.h:231
std::shared_ptr< Image< PixelT > const > getImage() const
Return a shared_ptr to the DecoratedImage&#39;s Image as const.
Definition: Image.h:495
A templated class to return this classes&#39; type (present in Image/Mask/MaskedImage) ...
Definition: Image.h:76
void scaledPlus(OutImageT &outImage, double c1, InImageT const &inImage1, double c2, InImageT const &inImage2)
Compute the scaled sum of two images.
std::shared_ptr< lsst::daf::base::PropertySet > getMetadata() const
Definition: Image.h:462
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
void operator/=(ExtentBase< int, N > &lhs, double rhs) noexcept
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:680
afw::table::Key< afw::table::Array< MaskPixelT > > mask
def init()
void operator*=(ExtentBase< int, N > &lhs, double rhs) noexcept
Options for writing an image to FITS.
Definition: fits.h:218
tuple options
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:296
The base class for all image classed (Image, Mask, MaskedImage, ...)
Definition: ImageBase.h:104
Image subset(lsst::geom::Box2I const &bbox, ImageOrigin origin=PARENT) const
Return a subimage corresponding to the given box.
Definition: Image.h:226
A Function taking two arguments.
Definition: Function.h:281
STL class.
afw::table::PointKey< int > dimensions
Definition: GaussianPsf.cc:44
A base class for image defects.
Represent a 2-dimensional array of bitmask pixels.
Definition: Mask.h:84
Image(ndarray::Array< PixelT, 2, 1 > const &array, bool deep=false, lsst::geom::Point2I const &xy0=lsst::geom::Point2I())
Definition: Image.h:191
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:120
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:81
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:715
void setGain(double gain)
Set the DecoratedImage&#39;s gain.
Definition: Image.h:504
Class implementing persistence and retrieval for Images.
void swap(DecoratedImage< PixelT > &a, DecoratedImage< PixelT > &b)
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:686
#define LSST_PERSIST_FORMATTER(formatter...)
int getX0() const
Return the image&#39;s column-origin.
Definition: Image.h:471
table::Box2IKey bbox
table::Key< int > a
const lsst::geom::Extent2I getDimensions() const
Return the image&#39;s size; useful for passing to constructors.
Definition: Image.h:476
Class implementing persistence and retrieval for DecoratedImages.
Image(Image< OtherPixelT > const &rhs, const bool deep)
Definition: Image.h:189
static Image readFits(std::string const &filename, int hdu=fits::DEFAULT_HDU)
Read an Image from a regular FITS file.
Definition: Image.h:318
static Image readFits(fits::MemFileManager &manager, int hdu=fits::DEFAULT_HDU)
Read an Image from a FITS RAM file.
Definition: Image.h:330
lsst::geom::Box2I bboxFromMetadata(daf::base::PropertySet &metadata)
Determine the image bounding box from its metadata (FITS header)
Definition: Image.cc:703
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:67
detail::Image_tag image_category
Definition: Image.h:72
double getGain() const
Return the DecoratedImage&#39;s gain.
Definition: Image.h:502
Image< ImagePT > type
Return the desired type.
Definition: Image.h:78
A container for an Image and its associated metadata.
Definition: Image.h:409
const int DEFAULT_HDU
Specify that the default HDU should be read.
Definition: fitsDefaults.h:18