LSST Applications g11f7dcd041+3309dba821,g1ce3e0751c+f991eae79d,g28da252d5a+9cd75b2bbf,g2bbee38e9b+b474e213a6,g2bc492864f+b474e213a6,g2cdde0e794+1e3907a55c,g2e95ee2dae+55e7f830ef,g347aa1857d+b474e213a6,g3a166c0a6a+b474e213a6,g4322eb9e3a+f7440700bb,g461a3dce89+b86e4b8053,g52b1c1532d+b86e4b8053,g607f77f49a+d6777fb84b,g78056777b3+b52dbcd3a1,g858d7b2824+d6777fb84b,g8cd86fa7b1+15b40b54d8,g9ddcbc5298+f24b38b85a,ga61afda322+d6777fb84b,gae0086650b+b86e4b8053,gbb886bcc26+69efdcef3b,gbd462c55f0+538be87034,gc120e1dc64+9b164a6ff8,gc28159a63d+b474e213a6,gc2a6998b7e+f95f64aeae,gc30aee3386+6076c0b52b,gcaf7e4fdec+d6777fb84b,gcdd4ae20e8+490f2fb51f,gce08ada175+bde66f6e3f,gcf0d15dbbd+490f2fb51f,gdaeeff99f8+006e14e809,gdbce86181e+61a8f2cffc,ge35ccca647+5538b8be6d,ge3d4d395c2+5a6209b744,ge79ae78c31+b474e213a6,gf048a9a2f4+aeb9e52fbb,w.2024.28
LSST Data Management Base Package
Loading...
Searching...
No Matches
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
35#include <climits>
36#include <memory>
37
38#include "lsst/geom.h"
40#include "lsst/afw/image/Mask.h"
43#include "ndarray.h"
44
45namespace lsst {
46namespace afw {
47namespace image {
48
50template <typename PixelT>
51class Image : public ImageBase<PixelT> {
52public:
53 template <typename, typename, typename>
54 friend class MaskedImage;
55
57
59 template <typename ImagePT = PixelT>
63 };
64 template <typename OtherPixelT>
65 friend class Image; // needed by generalised copy constructors
66
77 explicit Image(unsigned int width, unsigned int height, PixelT initialValue = 0);
87 explicit Image(lsst::geom::Extent2I const& dimensions = lsst::geom::Extent2I(), PixelT initialValue = 0);
94 explicit Image(lsst::geom::Box2I const& bbox, PixelT initialValue = 0);
95
109 explicit Image(Image const& rhs, lsst::geom::Box2I const& bbox, ImageOrigin const origin = PARENT,
110 const bool deep = false);
120 Image(const Image& rhs, const bool deep = false);
121 Image(Image&& rhs);
122
137 explicit Image(std::string const& fileName, int hdu = fits::DEFAULT_HDU,
140 lsst::geom::Box2I const& bbox = lsst::geom::Box2I(), ImageOrigin origin = PARENT,
141 bool allowUnsafe = false);
142
157 explicit Image(fits::MemFileManager& manager, int hdu = fits::DEFAULT_HDU,
160 lsst::geom::Box2I const& bbox = lsst::geom::Box2I(), ImageOrigin origin = PARENT,
161 bool allowUnsafe = false);
162
177 lsst::geom::Box2I const& bbox = lsst::geom::Box2I(), ImageOrigin origin = PARENT,
178 bool allowUnsafe = false);
179
180 // generalised copy constructor
181 template <typename OtherPixelT>
182 Image(Image<OtherPixelT> const& rhs, const bool deep) : image::ImageBase<PixelT>(rhs, deep) {}
183
184 explicit Image(ndarray::Array<PixelT, 2, 1> const& array, bool deep = false,
186 : image::ImageBase<PixelT>(array, deep, xy0) {}
187
188 ~Image() override = default;
189 //
190 // Assignment operators are not inherited
191 //
193 Image& operator=(const PixelT rhs);
203 Image& operator=(const Image& rhs);
204 Image& operator=(Image&& rhs);
205
219 Image subset(lsst::geom::Box2I const& bbox, ImageOrigin origin = PARENT) const {
220 return Image(*this, bbox, origin, false);
221 }
222
225
226 using ImageBase<PixelT>::operator[];
227
229
237 daf::base::PropertySet const * metadata = nullptr,
238 std::string const& mode = "w") const;
240
242
250 daf::base::PropertySet const * metadata = nullptr,
251 std::string const& mode = "w") const;
253
255
261 void writeFits(fits::Fits& fitsfile, daf::base::PropertySet const * metadata = nullptr) const;
263
265
275 std::string const& mode = "w",
276 daf::base::PropertySet const * header = nullptr,
277 Mask<MaskPixel> const * mask = nullptr) const;
279
281
291 std::string const& mode = "w",
292 daf::base::PropertySet const * header = nullptr,
293 Mask<MaskPixel> const *mask = nullptr) const;
295
297
306 daf::base::PropertySet const * header = nullptr,
307 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
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(PixelT const c, Image<PixelT> const& rhs);
351 Image& operator-=(PixelT const rhs);
353 Image& operator-=(Image<PixelT> const& rhs);
361 void scaledMinus(PixelT const c, Image<PixelT> const& rhs);
363 Image& operator*=(PixelT const rhs);
365 Image& operator*=(Image<PixelT> const& rhs);
367 void scaledMultiplies(PixelT const c, Image<PixelT> const& rhs);
373 Image& operator/=(PixelT const rhs);
375 Image& operator/=(Image<PixelT> const& rhs);
377 void scaledDivides(PixelT const c, Image<PixelT> const& rhs);
378
379 // In-place per-pixel sqrt(). Useful when handling variance planes.
380 void sqrt();
381
382protected:
383 using ImageBase<PixelT>::_getRawView;
384};
385
387template <typename LhsPixelT, typename RhsPixelT>
388Image<LhsPixelT>& operator+=(Image<LhsPixelT>& lhs, Image<RhsPixelT> const& rhs);
390template <typename LhsPixelT, typename RhsPixelT>
391Image<LhsPixelT>& operator-=(Image<LhsPixelT>& lhs, Image<RhsPixelT> const& rhs);
393template <typename LhsPixelT, typename RhsPixelT>
394Image<LhsPixelT>& operator*=(Image<LhsPixelT>& lhs, Image<RhsPixelT> const& rhs);
396template <typename LhsPixelT, typename RhsPixelT>
397Image<LhsPixelT>& operator/=(Image<LhsPixelT>& lhs, Image<RhsPixelT> const& rhs);
398
399template <typename PixelT>
400void swap(Image<PixelT>& a, Image<PixelT>& b);
401
405template <typename PixelT>
407public:
413 explicit DecoratedImage(const lsst::geom::Extent2I& dimensions = lsst::geom::Extent2I());
422 explicit DecoratedImage(const lsst::geom::Box2I& bbox);
439 DecoratedImage(DecoratedImage const& rhs, const bool deep = false);
450 explicit DecoratedImage(std::string const& fileName, const int hdu = fits::DEFAULT_HDU,
452 ImageOrigin const origin = PARENT, bool allowUnsafe = false);
453
460
462 void setMetadata(std::shared_ptr<lsst::daf::base::PropertySet> metadata) { _metadata = metadata; }
463
465 int getWidth() const { return _image->getWidth(); }
467 int getHeight() const { return _image->getHeight(); }
468
470 int getX0() const { return _image->getX0(); }
472 int getY0() const { return _image->getY0(); }
473
475 const lsst::geom::Extent2I getDimensions() const { return _image->getDimensions(); }
476
477 void swap(DecoratedImage& rhs);
478
480
487 void writeFits(std::string const& fileName,
488 daf::base::PropertySet const * metadata = nullptr,
489 std::string const& mode = "w") const;
491
493
501 void writeFits(std::string const& fileName, fits::ImageWriteOptions const& options,
502 daf::base::PropertySet const * metadata = nullptr,
503 std::string const& mode = "w") const;
505
509 std::shared_ptr<Image<PixelT> const> getImage() const { return _image; }
510
516 double getGain() const { return _gain; }
518 void setGain(double gain) { _gain = gain; }
519
520private:
523
524 double _gain;
525
526 void init();
527};
528
529template <typename PixelT>
530void swap(DecoratedImage<PixelT>& a, DecoratedImage<PixelT>& b);
531
537
541template <typename T1, typename T2>
542bool imagesOverlap(ImageBase<T1> const& image1, ImageBase<T2> const& image2);
543
544} // namespace image
545} // namespace afw
546} // namespace lsst
547
548#endif
AmpInfoBoxKey bbox
Definition Amplifier.cc:117
table::Key< double > gain
Definition Amplifier.cc:118
afw::table::Key< afw::table::Array< MaskPixelT > > mask
table::Key< int > b
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition fits.h:308
Lifetime-management for memory that goes into FITS memory files.
Definition fits.h:125
A container for an Image and its associated metadata.
Definition Image.h:406
DecoratedImage(const lsst::geom::Extent2I &dimensions=lsst::geom::Extent2I())
Create an image of the specified size.
const lsst::geom::Extent2I getDimensions() const
Return the image's size; useful for passing to constructors.
Definition Image.h:475
DecoratedImage & operator=(const DecoratedImage &image)
Assignment operator.
void swap(DecoratedImage &rhs)
double getGain() const
Return the DecoratedImage's gain.
Definition Image.h:516
int getY0() const
Return the image's row-origin.
Definition Image.h:472
int getHeight() const
Return the number of rows in the image.
Definition Image.h:467
void setMetadata(std::shared_ptr< lsst::daf::base::PropertySet > metadata)
Definition Image.h:462
int getX0() const
Return the image's column-origin.
Definition Image.h:470
void writeFits(std::string const &fileName, daf::base::PropertySet const *metadata=nullptr, std::string const &mode="w") const
Write a FITS file.
std::shared_ptr< lsst::daf::base::PropertySet > getMetadata() const
Definition Image.h:461
std::shared_ptr< Image< PixelT > > getImage()
Return a shared_ptr to the DecoratedImage's Image.
Definition Image.h:507
std::shared_ptr< Image< PixelT > const > getImage() const
Return a shared_ptr to the DecoratedImage's Image as const.
Definition Image.h:509
void setGain(double gain)
Set the DecoratedImage's gain.
Definition Image.h:518
int getWidth() const
Return the number of columns in the image.
Definition Image.h:465
The base class for all image classed (Image, Mask, MaskedImage, ...)
Definition ImageBase.h:102
typename ndarray::Array< PixelT, 2, 1 > Array
A mutable ndarray representation of the image.
Definition ImageBase.h:149
_view_t _getRawView() const
Definition ImageBase.h:465
A class to represent a 2-dimensional array of pixels.
Definition Image.h:51
void writeFits(std::string const &filename, fits::ImageWriteOptions const &options, std::string const &mode="w", daf::base::PropertySet const *header=nullptr, Mask< MaskPixel > const *mask=nullptr) const
Write an image to a regular FITS file.
Image & operator*=(PixelT const rhs)
Multiply lhs by scalar rhs.
Definition Image.cc:545
Image & operator-=(PixelT const rhs)
Subtract scalar rhs from lhs.
Definition Image.cc:500
void scaledPlus(PixelT const c, Image< PixelT > const &rhs)
Add Image c*rhs to lhs.
Definition Image.cc:487
Image(fits::Fits &fitsfile, std::shared_ptr< lsst::daf::base::PropertySet > metadata=std::shared_ptr< lsst::daf::base::PropertySet >(), lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool allowUnsafe=false)
Construct an Image from an already-open FITS object.
Image & operator=(const PixelT rhs)
Set the image's pixels to rhs.
Definition Image.cc:337
Image subset(lsst::geom::Box2I const &bbox, ImageOrigin origin=PARENT) const
Return a subimage corresponding to the given box.
Definition Image.h:219
void writeFits(fits::MemFileManager &manager, fits::ImageWriteOptions const &options, std::string const &mode="w", daf::base::PropertySet const *header=nullptr, Mask< MaskPixel > const *mask=nullptr) const
Write an image to a FITS RAM file.
Image(fits::MemFileManager &manager, int hdu=fits::DEFAULT_HDU, std::shared_ptr< lsst::daf::base::PropertySet > metadata=std::shared_ptr< lsst::daf::base::PropertySet >(), lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool allowUnsafe=false)
Construct an Image by reading a FITS image in memory.
Image operator[](lsst::geom::Box2I const &bbox) const
Return a subimage corresponding to the given box (interpreted as PARENT coordinates).
Definition Image.h:224
Image & operator+=(PixelT const rhs)
Add scalar rhs to lhs.
Definition Image.cc:455
static Image readFits(fits::MemFileManager &manager, int hdu=fits::DEFAULT_HDU)
Read an Image from a FITS RAM file.
Definition Image.h:330
~Image() override=default
void scaledMinus(PixelT const c, Image< PixelT > const &rhs)
Subtract Image c*rhs from lhs.
Definition Image.cc:519
void swap(Image &rhs)
Definition Image.cc:437
void writeFits(fits::MemFileManager &manager, daf::base::PropertySet const *metadata=nullptr, std::string const &mode="w") const
Write an image to a FITS RAM file.
Image & operator/=(PixelT const rhs)
Divide lhs by scalar rhs.
Definition Image.cc:577
Image(ndarray::Array< PixelT, 2, 1 > const &array, bool deep=false, lsst::geom::Point2I const &xy0=lsst::geom::Point2I())
Definition Image.h:184
Image(Image< OtherPixelT > const &rhs, const bool deep)
Definition Image.h:182
void writeFits(std::string const &fileName, daf::base::PropertySet const *metadata=nullptr, std::string const &mode="w") const
Write an image to a regular FITS file.
void scaledDivides(PixelT const c, Image< PixelT > const &rhs)
Divide lhs by Image c*rhs (i.e. pixel-by-pixel division)
Definition Image.cc:612
static Image readFits(std::string const &filename, int hdu=fits::DEFAULT_HDU)
Read an Image from a regular FITS file.
Definition Image.h:318
void scaledMultiplies(PixelT const c, Image< PixelT > const &rhs)
Multiply lhs by Image c*rhs (i.e. pixel-by-pixel multiplication)
Definition Image.cc:564
Image(std::string const &fileName, int hdu=fits::DEFAULT_HDU, std::shared_ptr< lsst::daf::base::PropertySet > metadata=std::shared_ptr< lsst::daf::base::PropertySet >(), lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool allowUnsafe=false)
Construct an Image by reading a regular FITS file.
void writeFits(fits::Fits &fitsfile, daf::base::PropertySet const *metadata=nullptr) const
Write an image to an open FITS file object.
void writeFits(fits::Fits &fitsfile, fits::ImageWriteOptions const &options, daf::base::PropertySet const *header=nullptr, Mask< MaskPixel > const *mask=nullptr) const
Write an image to an open FITS file object.
friend class Image
Definition Image.h:65
A class to manipulate images, masks, and variance as a single object.
Definition MaskedImage.h:74
A Function taking two arguments.
Definition Function.h:259
Class for storing generic metadata.
Definition PropertySet.h:66
An integer coordinate rectangle.
Definition Box.h:55
const int DEFAULT_HDU
Specify that the default HDU should be read.
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:658
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:664
lsst::geom::Box2I bboxFromMetadata(daf::base::PropertySet &metadata)
Determine the image bounding box from its metadata (FITS header)
Definition Image.cc:681
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:676
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:670
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:693
void swap(Image< PixelT > &a, Image< PixelT > &b)
Definition Image.cc:443
Options for writing an image to FITS.
Definition fits.h:223
A templated class to return this classes' type (present in Image/Mask/MaskedImage)
Definition Image.h:60
Image< ImagePT > type
Return the desired type.
Definition Image.h:62