lsst.afw  13.0-109-g62eb66483
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/daf/base.h"
50 #include "lsst/daf/base/Citizen.h"
51 #include "lsst/pex/exceptions.h"
52 #include "ndarray.h"
53 
54 namespace lsst {
55 namespace afw {
56 
57 namespace formatters {
58 template <typename PixelT>
59 class ImageFormatter;
60 template <typename PixelT>
61 class DecoratedImageFormatter;
62 }
63 
64 namespace image {
65 
67 template <typename PixelT>
68 class Image : public ImageBase<PixelT> {
69 public:
70  template <typename, typename, typename>
71  friend class MaskedImage;
72 
74 
76  template <typename ImagePT = PixelT>
80  };
81  template <typename OtherPixelT>
82  friend class Image; // needed by generalised copy constructors
83 
94  explicit Image(unsigned int width, unsigned int height, PixelT initialValue = 0);
104  explicit Image(geom::Extent2I const& dimensions = geom::Extent2I(), PixelT initialValue = 0);
111  explicit Image(geom::Box2I const& bbox, PixelT initialValue = 0);
112 
126  explicit Image(Image const& rhs, geom::Box2I const& bbox, ImageOrigin const origin = PARENT,
127  const bool deep = false);
137  Image(const Image& rhs, const bool deep = false);
138 
151  explicit Image(std::string const& fileName, int hdu = INT_MIN,
152  std::shared_ptr<lsst::daf::base::PropertySet> metadata =
153  std::shared_ptr<lsst::daf::base::PropertySet>(),
154  geom::Box2I const& bbox = geom::Box2I(), ImageOrigin origin = PARENT);
155 
168  explicit Image(fits::MemFileManager& manager, int hdu = INT_MIN,
169  std::shared_ptr<lsst::daf::base::PropertySet> metadata =
170  std::shared_ptr<lsst::daf::base::PropertySet>(),
171  geom::Box2I const& bbox = geom::Box2I(), ImageOrigin origin = PARENT);
172 
182  explicit Image(fits::Fits& fitsfile, std::shared_ptr<lsst::daf::base::PropertySet> metadata =
183  std::shared_ptr<lsst::daf::base::PropertySet>(),
184  geom::Box2I const& bbox = geom::Box2I(), ImageOrigin origin = PARENT);
185 
186  // generalised copy constructor
187  template <typename OtherPixelT>
188  Image(Image<OtherPixelT> const& rhs, const bool deep) : image::ImageBase<PixelT>(rhs, deep) {}
189 
190  explicit Image(ndarray::Array<PixelT, 2, 1> const& array, bool deep = false,
191  geom::Point2I const& xy0 = geom::Point2I())
192  : image::ImageBase<PixelT>(array, deep, xy0) {}
193 
194  virtual ~Image() {}
195  //
196  // Assignment operators are not inherited
197  //
199  Image& operator=(const PixelT rhs);
209  Image& operator=(const Image& rhs);
210 
218  void writeFits(std::string const& fileName, std::shared_ptr<lsst::daf::base::PropertySet const> metadata =
219  std::shared_ptr<lsst::daf::base::PropertySet const>(),
220  std::string const& mode = "w") const;
221 
229  void writeFits(fits::MemFileManager& manager,
230  std::shared_ptr<lsst::daf::base::PropertySet const> metadata =
231  std::shared_ptr<lsst::daf::base::PropertySet const>(),
232  std::string const& mode = "w") const;
233 
240  void writeFits(fits::Fits& fitsfile, std::shared_ptr<lsst::daf::base::PropertySet const> metadata =
241  std::shared_ptr<lsst::daf::base::PropertySet const>()) const;
242 
252  void writeFits(
253  std::string const& filename,
254  fits::ImageWriteOptions const& options,
255  std::string const& mode = "w",
256  std::shared_ptr<daf::base::PropertySet const> header=nullptr,
257  std::shared_ptr<Mask<MaskPixel> const> mask=nullptr
258  ) const;
259 
269  void writeFits(
270  fits::MemFileManager& manager,
271  fits::ImageWriteOptions const& options,
272  std::string const& mode = "w",
273  std::shared_ptr<daf::base::PropertySet const> header=nullptr,
274  std::shared_ptr<Mask<MaskPixel> const> mask=nullptr
275  ) const;
276 
285  void writeFits(
286  fits::Fits& fitsfile,
287  fits::ImageWriteOptions const& options,
288  std::shared_ptr<daf::base::PropertySet const> header=nullptr,
289  std::shared_ptr<Mask<MaskPixel> const> mask=nullptr
290  ) const;
291 
300  static Image readFits(std::string const& filename, int hdu = INT_MIN) {
301  return Image<PixelT>(filename, hdu);
302  }
303 
312  static Image readFits(fits::MemFileManager& manager, int hdu = INT_MIN) {
313  return Image<PixelT>(manager, hdu);
314  }
315 
316  void swap(Image& rhs);
317  //
318  // Operators etc.
319  //
321  Image& operator+=(PixelT const rhs);
323  virtual Image& operator+=(Image<PixelT> const& rhs);
331  void scaledPlus(double const c, Image<PixelT> const& rhs);
333  Image& operator-=(PixelT const rhs);
335  Image& operator-=(Image<PixelT> const& rhs);
343  void scaledMinus(double const c, Image<PixelT> const& rhs);
345  Image& operator*=(PixelT const rhs);
347  Image& operator*=(Image<PixelT> const& rhs);
349  void scaledMultiplies(double const c, Image<PixelT> const& rhs);
355  Image& operator/=(PixelT const rhs);
357  Image& operator/=(Image<PixelT> const& rhs);
359  void scaledDivides(double const c, Image<PixelT> const& rhs);
360 
361  // In-place per-pixel sqrt(). Useful when handling variance planes.
362  void sqrt();
363 
364 protected:
366 
367 private:
368  LSST_PERSIST_FORMATTER(lsst::afw::formatters::ImageFormatter<PixelT>)
369 };
370 
372 template <typename LhsPixelT, typename RhsPixelT>
375 template <typename LhsPixelT, typename RhsPixelT>
378 template <typename LhsPixelT, typename RhsPixelT>
381 template <typename LhsPixelT, typename RhsPixelT>
383 
384 template <typename PixelT>
385 void swap(Image<PixelT>& a, Image<PixelT>& b);
386 
390 template <typename PixelT>
391 class DecoratedImage : public lsst::daf::base::Persistable, public lsst::daf::base::Citizen {
392 public:
407  explicit DecoratedImage(const geom::Box2I& bbox);
415  explicit DecoratedImage(std::shared_ptr<Image<PixelT>> rhs);
424  DecoratedImage(DecoratedImage const& rhs, const bool deep = false);
433  explicit DecoratedImage(std::string const& fileName, const int hdu = INT_MIN,
434  geom::Box2I const& bbox = geom::Box2I(), ImageOrigin const origin = PARENT);
435 
441  DecoratedImage& operator=(const DecoratedImage& image);
442 
443  std::shared_ptr<lsst::daf::base::PropertySet> getMetadata() const { return _metadata; }
444  void setMetadata(std::shared_ptr<lsst::daf::base::PropertySet> metadata) { _metadata = metadata; }
445 
447  int getWidth() const { return _image->getWidth(); }
449  int getHeight() const { return _image->getHeight(); }
450 
452  int getX0() const { return _image->getX0(); }
454  int getY0() const { return _image->getY0(); }
455 
457  const geom::Extent2I getDimensions() const { return _image->getDimensions(); }
458 
459  void swap(DecoratedImage& rhs);
460 
468  void writeFits(std::string const& fileName, std::shared_ptr<lsst::daf::base::PropertySet const> metadata =
469  std::shared_ptr<lsst::daf::base::PropertySet const>(),
470  std::string const& mode = "w") const;
471 
473  std::shared_ptr<Image<PixelT>> getImage() { return _image; }
475  std::shared_ptr<Image<PixelT> const> getImage() const { return _image; }
476 
482  double getGain() const { return _gain; }
484  void setGain(double gain) { _gain = gain; }
485 
486 private:
488  std::shared_ptr<Image<PixelT>> _image;
489  std::shared_ptr<lsst::daf::base::PropertySet> _metadata;
490 
491  double _gain;
492 
493  void init();
494 };
495 
496 template <typename PixelT>
498 
504 
505 }
506 }
507 } // lsst::afw::image
508 
509 #endif
std::shared_ptr< Image< PixelT > > getImage()
Return a shared_ptr to the DecoratedImage&#39;s Image.
Definition: Image.h:473
std::shared_ptr< Image< PixelT > const > getImage() const
Return a shared_ptr to the DecoratedImage&#39;s Image as const.
Definition: Image.h:475
A templated class to return this classes&#39; type (present in Image/Mask/MaskedImage) ...
Definition: Image.h:77
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:443
int getWidth() const
Return the number of columns in the image.
Definition: Image.h:447
int getHeight() const
Return the number of rows in the image.
Definition: Image.h:449
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
static Image readFits(std::string const &filename, int hdu=INT_MIN)
Read an Image from a regular FITS file.
Definition: Image.h:300
const geom::Extent2I getDimensions() const
Return the image&#39;s size; useful for passing to constructors.
Definition: Image.h:457
Options for writing an image to FITS.
Definition: fits.h:201
virtual ~Image()
Definition: Image.h:194
void setMetadata(std::shared_ptr< lsst::daf::base::PropertySet > metadata)
Definition: Image.h:444
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:279
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
lsst::daf::base::PropertySet PropertySet
Definition: Wcs.cc:55
afw::table::PointKey< int > dimensions
Definition: GaussianPsf.cc:44
A base class for image defects.
Definition: cameraGeom.dox:3
Represent a 2-dimensional array of bitmask pixels.
Definition: Mask.h:83
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:101
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:81
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:484
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:190
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
int getX0() const
Return the image&#39;s column-origin.
Definition: Image.h:452
static Image readFits(fits::MemFileManager &manager, int hdu=INT_MIN)
Read an Image from a FITS RAM file.
Definition: Image.h:312
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:188
int getY0() const
Return the image&#39;s row-origin.
Definition: Image.h:454
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:68
detail::Image_tag image_category
Definition: Image.h:73
double getGain() const
Return the DecoratedImage&#39;s gain.
Definition: Image.h:482
Image< ImagePT > type
Return the desired type.
Definition: Image.h:79
A container for an Image and its associated metadata.
Definition: Image.h:391