lsst.afw  14.0-38-g278b05818
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 
152  explicit Image(std::string const& fileName, int hdu = fits::DEFAULT_HDU,
155  geom::Box2I const& bbox = geom::Box2I(), ImageOrigin origin = PARENT);
156 
169  explicit Image(fits::MemFileManager& manager, int hdu = fits::DEFAULT_HDU,
172  geom::Box2I const& bbox = geom::Box2I(), ImageOrigin origin = PARENT);
173 
183  explicit Image(fits::Fits& fitsfile, std::shared_ptr<lsst::daf::base::PropertySet> metadata =
185  geom::Box2I const& bbox = geom::Box2I(), ImageOrigin origin = PARENT);
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,
192  geom::Point2I const& xy0 = geom::Point2I())
193  : image::ImageBase<PixelT>(array, deep, xy0) {}
194 
195  virtual ~Image() {}
196  //
197  // Assignment operators are not inherited
198  //
200  Image& operator=(const PixelT rhs);
210  Image& operator=(const Image& rhs);
211 
219  void writeFits(std::string const& fileName, std::shared_ptr<lsst::daf::base::PropertySet const> metadata =
221  std::string const& mode = "w") const;
222 
230  void writeFits(fits::MemFileManager& manager,
233  std::string const& mode = "w") const;
234 
241  void writeFits(fits::Fits& fitsfile, std::shared_ptr<lsst::daf::base::PropertySet const> metadata =
243 
253  void writeFits(
254  std::string const& filename,
256  std::string const& mode = "w",
258  std::shared_ptr<Mask<MaskPixel> const> mask=nullptr
259  ) const;
260 
270  void writeFits(
271  fits::MemFileManager& manager,
272  fits::ImageWriteOptions const& options,
273  std::string const& mode = "w",
275  std::shared_ptr<Mask<MaskPixel> const> mask=nullptr
276  ) const;
277 
286  void writeFits(
287  fits::Fits& fitsfile,
288  fits::ImageWriteOptions const& options,
290  std::shared_ptr<Mask<MaskPixel> const> mask=nullptr
291  ) const;
292 
301  static Image readFits(std::string const& filename, int hdu = fits::DEFAULT_HDU) {
302  return Image<PixelT>(filename, hdu);
303  }
304 
313  static Image readFits(fits::MemFileManager& manager, int hdu = fits::DEFAULT_HDU) {
314  return Image<PixelT>(manager, hdu);
315  }
316 
317  void swap(Image& rhs);
318  //
319  // Operators etc.
320  //
322  Image& operator+=(PixelT const rhs);
324  virtual Image& operator+=(Image<PixelT> const& rhs);
332  void scaledPlus(double const c, Image<PixelT> const& rhs);
334  Image& operator-=(PixelT const rhs);
336  Image& operator-=(Image<PixelT> const& rhs);
344  void scaledMinus(double const c, Image<PixelT> const& rhs);
346  Image& operator*=(PixelT const rhs);
348  Image& operator*=(Image<PixelT> const& rhs);
350  void scaledMultiplies(double const c, Image<PixelT> const& rhs);
356  Image& operator/=(PixelT const rhs);
358  Image& operator/=(Image<PixelT> const& rhs);
360  void scaledDivides(double const c, Image<PixelT> const& rhs);
361 
362  // In-place per-pixel sqrt(). Useful when handling variance planes.
363  void sqrt();
364 
365 protected:
367 
368 private:
370 };
371 
373 template <typename LhsPixelT, typename RhsPixelT>
376 template <typename LhsPixelT, typename RhsPixelT>
379 template <typename LhsPixelT, typename RhsPixelT>
382 template <typename LhsPixelT, typename RhsPixelT>
384 
385 template <typename PixelT>
387 
391 template <typename PixelT>
393 public:
408  explicit DecoratedImage(const geom::Box2I& bbox);
425  DecoratedImage(DecoratedImage const& rhs, const bool deep = false);
434  explicit DecoratedImage(std::string const& fileName, const int hdu = fits::DEFAULT_HDU,
435  geom::Box2I const& bbox = geom::Box2I(), ImageOrigin const origin = PARENT);
436 
442  DecoratedImage& operator=(const DecoratedImage& image);
443 
445  void setMetadata(std::shared_ptr<lsst::daf::base::PropertySet> metadata) { _metadata = metadata; }
446 
448  int getWidth() const { return _image->getWidth(); }
450  int getHeight() const { return _image->getHeight(); }
451 
453  int getX0() const { return _image->getX0(); }
455  int getY0() const { return _image->getY0(); }
456 
458  const geom::Extent2I getDimensions() const { return _image->getDimensions(); }
459 
460  void swap(DecoratedImage& rhs);
461 
469  void writeFits(std::string const& fileName, std::shared_ptr<lsst::daf::base::PropertySet const> metadata =
471  std::string const& mode = "w") const;
472 
476  std::shared_ptr<Image<PixelT> const> getImage() const { return _image; }
477 
483  double getGain() const { return _gain; }
485  void setGain(double gain) { _gain = gain; }
486 
487 private:
491 
492  double _gain;
493 
494  void init();
495 };
496 
497 template <typename PixelT>
499 
505 
506 }
507 }
508 } // lsst::afw::image
509 
510 #endif
std::shared_ptr< Image< PixelT > > getImage()
Return a shared_ptr to the DecoratedImage&#39;s Image.
Definition: Image.h:474
std::shared_ptr< Image< PixelT > const > getImage() const
Return a shared_ptr to the DecoratedImage&#39;s Image as const.
Definition: Image.h:476
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:444
int getWidth() const
Return the number of columns in the image.
Definition: Image.h:448
int getHeight() const
Return the number of rows in the image.
Definition: Image.h:450
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:649
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:458
def init()
Options for writing an image to FITS.
Definition: fits.h:202
tuple options
virtual ~Image()
Definition: Image.h:195
void setMetadata(std::shared_ptr< lsst::daf::base::PropertySet > metadata)
Definition: Image.h:445
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:280
The base class for all image classed (Image, Mask, MaskedImage, ...)
Definition: ImageBase.h:106
A Function taking two arguments.
Definition: Function.h:266
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:102
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:672
void setGain(double gain)
Set the DecoratedImage&#39;s gain.
Definition: Image.h:485
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:191
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:661
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:655
#define LSST_PERSIST_FORMATTER(formatter...)
int getX0() const
Return the image&#39;s column-origin.
Definition: Image.h:453
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:667
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:301
static Image readFits(fits::MemFileManager &manager, int hdu=fits::DEFAULT_HDU)
Read an Image from a FITS RAM file.
Definition: Image.h:313
int getY0() const
Return the image&#39;s row-origin.
Definition: Image.h:455
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:483
Image< ImagePT > type
Return the desired type.
Definition: Image.h:80
A container for an Image and its associated metadata.
Definition: Image.h:392
const int DEFAULT_HDU
Specify that the default HDU should be read.
Definition: fitsDefaults.h:18