lsst.afw  14.0-49-g535656444+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/afw/geom/Extent.h"
42 #include "lsst/afw/geom/Box.h"
43 #include "lsst/afw/geom/Point.h"
45 #include "lsst/afw/image/lsstGil.h"
47 #include "lsst/afw/image/Mask.h"
48 #include "lsst/afw/math/Function.h"
49 #include "lsst/afw/fitsDefaults.h"
50 #include "lsst/daf/base.h"
51 #include "lsst/daf/base/Citizen.h"
52 #include "lsst/pex/exceptions.h"
53 #include "ndarray.h"
54 
55 namespace lsst {
56 namespace afw {
57 
58 namespace formatters {
59 template <typename PixelT>
60 class ImageFormatter;
61 template <typename PixelT>
62 class DecoratedImageFormatter;
63 }
64 
65 namespace image {
66 
68 template <typename PixelT>
69 class Image : public ImageBase<PixelT> {
70 public:
71  template <typename, typename, typename>
72  friend class MaskedImage;
73 
75 
77  template <typename ImagePT = PixelT>
81  };
82  template <typename OtherPixelT>
83  friend class Image; // needed by generalised copy constructors
84 
95  explicit Image(unsigned int width, unsigned int height, PixelT initialValue = 0);
105  explicit Image(geom::Extent2I const& dimensions = geom::Extent2I(), PixelT initialValue = 0);
112  explicit Image(geom::Box2I const& bbox, PixelT initialValue = 0);
113 
127  explicit Image(Image const& rhs, geom::Box2I const& bbox, ImageOrigin const origin = PARENT,
128  const bool deep = false);
138  Image(const Image& rhs, const bool deep = false);
139  Image(Image&& rhs);
140 
153  explicit Image(std::string const& fileName, int hdu = fits::DEFAULT_HDU,
156  geom::Box2I const& bbox = geom::Box2I(), ImageOrigin origin = PARENT);
157 
170  explicit Image(fits::MemFileManager& manager, int hdu = fits::DEFAULT_HDU,
173  geom::Box2I const& bbox = geom::Box2I(), ImageOrigin origin = PARENT);
174 
184  explicit Image(fits::Fits& fitsfile, std::shared_ptr<lsst::daf::base::PropertySet> metadata =
186  geom::Box2I const& bbox = geom::Box2I(), ImageOrigin origin = PARENT);
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,
193  geom::Point2I const& xy0 = geom::Point2I())
194  : image::ImageBase<PixelT>(array, deep, xy0) {}
195 
196  virtual ~Image() = 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 
221  void writeFits(std::string const& fileName, std::shared_ptr<lsst::daf::base::PropertySet const> metadata =
223  std::string const& mode = "w") const;
224 
232  void writeFits(fits::MemFileManager& manager,
235  std::string const& mode = "w") const;
236 
243  void writeFits(fits::Fits& fitsfile, std::shared_ptr<lsst::daf::base::PropertySet const> metadata =
245 
255  void writeFits(
256  std::string const& filename,
258  std::string const& mode = "w",
260  std::shared_ptr<Mask<MaskPixel> const> mask=nullptr
261  ) const;
262 
272  void writeFits(
273  fits::MemFileManager& manager,
274  fits::ImageWriteOptions const& options,
275  std::string const& mode = "w",
277  std::shared_ptr<Mask<MaskPixel> const> mask=nullptr
278  ) const;
279 
288  void writeFits(
289  fits::Fits& fitsfile,
290  fits::ImageWriteOptions const& options,
292  std::shared_ptr<Mask<MaskPixel> const> mask=nullptr
293  ) const;
294 
303  static Image readFits(std::string const& filename, int hdu = fits::DEFAULT_HDU) {
304  return Image<PixelT>(filename, hdu);
305  }
306 
315  static Image readFits(fits::MemFileManager& manager, int hdu = fits::DEFAULT_HDU) {
316  return Image<PixelT>(manager, hdu);
317  }
318 
319  void swap(Image& rhs);
320  //
321  // Operators etc.
322  //
324  Image& operator+=(PixelT const rhs);
326  virtual Image& operator+=(Image<PixelT> const& rhs);
334  void scaledPlus(double const c, Image<PixelT> const& rhs);
336  Image& operator-=(PixelT const rhs);
338  Image& operator-=(Image<PixelT> const& rhs);
346  void scaledMinus(double const c, Image<PixelT> const& rhs);
348  Image& operator*=(PixelT const rhs);
350  Image& operator*=(Image<PixelT> const& rhs);
352  void scaledMultiplies(double const c, Image<PixelT> const& rhs);
358  Image& operator/=(PixelT const rhs);
360  Image& operator/=(Image<PixelT> const& rhs);
362  void scaledDivides(double const c, Image<PixelT> const& rhs);
363 
364  // In-place per-pixel sqrt(). Useful when handling variance planes.
365  void sqrt();
366 
367 protected:
369 
370 private:
372 };
373 
375 template <typename LhsPixelT, typename RhsPixelT>
378 template <typename LhsPixelT, typename RhsPixelT>
381 template <typename LhsPixelT, typename RhsPixelT>
384 template <typename LhsPixelT, typename RhsPixelT>
386 
387 template <typename PixelT>
389 
393 template <typename PixelT>
395 public:
410  explicit DecoratedImage(const geom::Box2I& bbox);
427  DecoratedImage(DecoratedImage const& rhs, const bool deep = false);
436  explicit DecoratedImage(std::string const& fileName, const int hdu = fits::DEFAULT_HDU,
437  geom::Box2I const& bbox = geom::Box2I(), ImageOrigin const origin = PARENT);
438 
444  DecoratedImage& operator=(const DecoratedImage& image);
445 
447  void setMetadata(std::shared_ptr<lsst::daf::base::PropertySet> metadata) { _metadata = metadata; }
448 
450  int getWidth() const { return _image->getWidth(); }
452  int getHeight() const { return _image->getHeight(); }
453 
455  int getX0() const { return _image->getX0(); }
457  int getY0() const { return _image->getY0(); }
458 
460  const geom::Extent2I getDimensions() const { return _image->getDimensions(); }
461 
462  void swap(DecoratedImage& rhs);
463 
471  void writeFits(std::string const& fileName, std::shared_ptr<lsst::daf::base::PropertySet const> metadata =
473  std::string const& mode = "w") const;
474 
478  std::shared_ptr<Image<PixelT> const> getImage() const { return _image; }
479 
485  double getGain() const { return _gain; }
487  void setGain(double gain) { _gain = gain; }
488 
489 private:
493 
494  double _gain;
495 
496  void init();
497 };
498 
499 template <typename PixelT>
501 
507 
508 }
509 }
510 } // lsst::afw::image
511 
512 #endif
std::shared_ptr< Image< PixelT > > getImage()
Return a shared_ptr to the DecoratedImage&#39;s Image.
Definition: Image.h:476
std::shared_ptr< Image< PixelT > const > getImage() const
Return a shared_ptr to the DecoratedImage&#39;s Image as const.
Definition: Image.h:478
A templated class to return this classes&#39; type (present in Image/Mask/MaskedImage) ...
Definition: Image.h:78
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:446
int getWidth() const
Return the number of columns in the image.
Definition: Image.h:450
int getHeight() const
Return the number of rows in the image.
Definition: Image.h:452
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
afw::table::Key< afw::table::Array< MaskPixelT > > mask
const geom::Extent2I getDimensions() const
Return the image&#39;s size; useful for passing to constructors.
Definition: Image.h:460
def init()
Options for writing an image to FITS.
Definition: fits.h:220
tuple options
void setMetadata(std::shared_ptr< lsst::daf::base::PropertySet > metadata)
Definition: Image.h:447
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:276
An integer coordinate rectangle.
Definition: Box.h:55
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
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
geom::Box2I bboxFromMetadata(daf::base::PropertySet &metadata)
Determine the image bounding box from its metadata (FITS header)
Definition: Image.cc:688
void setGain(double gain)
Set the DecoratedImage&#39;s gain.
Definition: Image.h:487
Class implementing persistence and retrieval for Images.
Image(ndarray::Array< PixelT, 2, 1 > const &array, bool deep=false, geom::Point2I const &xy0=geom::Point2I())
Definition: Image.h:192
void swap(DecoratedImage< PixelT > &a, DecoratedImage< PixelT > &b)
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
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
#define LSST_PERSIST_FORMATTER(formatter...)
int getX0() const
Return the image&#39;s column-origin.
Definition: Image.h:455
table::Box2IKey bbox
table::Key< int > a
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
Class implementing persistence and retrieval for DecoratedImages.
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:303
static Image readFits(fits::MemFileManager &manager, int hdu=fits::DEFAULT_HDU)
Read an Image from a FITS RAM file.
Definition: Image.h:315
int getY0() const
Return the image&#39;s row-origin.
Definition: Image.h:457
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:69
detail::Image_tag image_category
Definition: Image.h:74
double getGain() const
Return the DecoratedImage&#39;s gain.
Definition: Image.h:485
Image< ImagePT > type
Return the desired type.
Definition: Image.h:80
A container for an Image and its associated metadata.
Definition: Image.h:394
const int DEFAULT_HDU
Specify that the default HDU should be read.
Definition: fitsDefaults.h:18