30 #ifndef LSST_AFW_IMAGE_IMAGE_H
31 #define LSST_AFW_IMAGE_IMAGE_H
39 #include "boost/mpl/bool.hpp"
49 #include "lsst/daf/base.h"
50 #include "lsst/daf/base/Citizen.h"
51 #include "lsst/pex/exceptions.h"
57 namespace formatters {
58 template <
typename PixelT>
60 template <
typename PixelT>
61 class DecoratedImageFormatter;
79 template <
typename ImageT>
91 operator bool()
const {
return _check; }
98 template <
typename PixelT>
100 typedef typename boost::gil::channel_traits<PixelT>::reference
type;
103 template <
typename PixelT>
105 typedef typename boost::gil::channel_traits<PixelT>::const_reference
type;
115 template <
typename PixelT>
116 class ImageBase :
public lsst::daf::base::Persistable,
public lsst::daf::base::Citizen {
118 typedef typename lsst::afw::image::detail::types_traits<PixelT>::view_t _view_t;
119 typedef typename lsst::afw::image::detail::types_traits<PixelT>::const_view_t _const_view_t;
121 typedef ndarray::Manager Manager;
163 typedef typename ndarray::Array<PixelT, 2, 1>
Array;
165 typedef typename ndarray::Array<PixelT const, 2, 1>
ConstArray;
167 template <
typename OtherPixelT>
171 template <
typename SinglePixelT>
181 template <
typename,
typename,
typename>
222 const bool deep =
false);
229 template <
typename OtherPixelT>
232 throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError,
233 "Only deep copies are permitted for ImageBases with different pixel types");
237 copy_and_convert_pixels(rhs._gilView, tmp._gilView);
346 int const roundedIndex =
static_cast<int>(fullIndex + 0.5);
347 double const residual = fullIndex - roundedIndex;
348 return std::pair<int, double>(roundedIndex, residual);
465 Manager::Ptr _manager;
474 const _view_t& view);
481 template <
typename PixelT>
482 void swap(ImageBase<PixelT>& a, ImageBase<PixelT>& b);
485 template <
typename PixelT>
488 template <
typename,
typename,
typename>
494 template <
typename ImagePT = PixelT>
499 template <
typename OtherPixelT>
512 explicit Image(
unsigned int width,
unsigned int height, PixelT initialValue = 0);
545 const bool deep =
false);
555 Image(
const Image& rhs,
const bool deep =
false);
569 explicit Image(std::string
const& fileName,
int hdu = INT_MIN,
570 std::shared_ptr<lsst::daf::base::PropertySet> metadata =
571 std::shared_ptr<lsst::daf::base::PropertySet>(),
587 std::shared_ptr<lsst::daf::base::PropertySet> metadata =
588 std::shared_ptr<lsst::daf::base::PropertySet>(),
600 explicit Image(
fits::Fits& fitsfile, std::shared_ptr<lsst::daf::base::PropertySet> metadata =
601 std::shared_ptr<lsst::daf::base::PropertySet>(),
605 template <
typename OtherPixelT>
608 explicit Image(ndarray::Array<PixelT, 2, 1>
const& array,
bool deep =
false,
636 void writeFits(std::string
const& fileName, std::shared_ptr<lsst::daf::base::PropertySet const> metadata =
637 std::shared_ptr<lsst::daf::base::PropertySet const>(),
638 std::string
const& mode =
"w")
const;
648 std::shared_ptr<lsst::daf::base::PropertySet const> metadata =
649 std::shared_ptr<lsst::daf::base::PropertySet const>(),
650 std::string
const& mode =
"w")
const;
658 void writeFits(
fits::Fits& fitsfile, std::shared_ptr<lsst::daf::base::PropertySet const> metadata =
659 std::shared_ptr<lsst::daf::base::PropertySet const>())
const;
741 template <
typename LhsPixelT,
typename RhsPixelT>
742 Image<LhsPixelT>&
operator+=(Image<LhsPixelT>& lhs, Image<RhsPixelT>
const& rhs);
744 template <
typename LhsPixelT,
typename RhsPixelT>
745 Image<LhsPixelT>&
operator-=(Image<LhsPixelT>& lhs, Image<RhsPixelT>
const& rhs);
747 template <
typename LhsPixelT,
typename RhsPixelT>
748 Image<LhsPixelT>&
operator*=(Image<LhsPixelT>& lhs, Image<RhsPixelT>
const& rhs);
750 template <
typename LhsPixelT,
typename RhsPixelT>
751 Image<LhsPixelT>&
operator/=(Image<LhsPixelT>& lhs, Image<RhsPixelT>
const& rhs);
753 template <
typename PixelT>
754 void swap(Image<PixelT>& a, Image<PixelT>& b);
759 template <
typename PixelT>
760 class DecoratedImage :
public lsst::daf::base::Persistable,
public lsst::daf::base::Citizen {
802 explicit DecoratedImage(std::string
const& fileName,
const int hdu = INT_MIN,
812 std::shared_ptr<lsst::daf::base::PropertySet>
getMetadata()
const {
return _metadata; }
813 void setMetadata(std::shared_ptr<lsst::daf::base::PropertySet> metadata) { _metadata = metadata; }
816 int getWidth()
const {
return _image->getWidth(); }
821 int getX0()
const {
return _image->getX0(); }
823 int getY0()
const {
return _image->getY0(); }
837 void writeFits(std::string
const& fileName, std::shared_ptr<lsst::daf::base::PropertySet const> metadata =
838 std::shared_ptr<lsst::daf::base::PropertySet const>(),
839 std::string
const& mode =
"w")
const;
842 std::shared_ptr<Image<PixelT>>
getImage() {
return _image; }
844 std::shared_ptr<Image<PixelT>
const>
getImage()
const {
return _image; }
857 std::shared_ptr<
Image<PixelT>> _image;
858 std::shared_ptr<lsst::daf::base::
PropertySet> _metadata;
865 template <typename PixelT>
std::shared_ptr< Image< PixelT > > getImage()
Return a shared_ptr to the DecoratedImage's Image.
boost::gil::channel_traits< PixelT >::reference type
reference type
PixelConstReference get0(int x, int y, CheckIndices const &check) const
void setXY0(geom::Point2I const origin)
Set the ImageBase's origin.
A templated class to return this classes' type (present in Image/Mask/MaskedImage) ...
Image & operator=(const PixelT rhs)
Set the image's pixels to rhs.
afw::table::PointKey< int > dimensions
iterator begin() const
Return an STL compliant iterator to the start of the image.
Image & operator*=(PixelT const rhs)
Multiply lhs by scalar rhs.
_const_view_t::reverse_iterator const_reverse_iterator
An STL compliant const reverse iterator.
x_iterator fast_iterator
A fast STL compliant iterator for contiguous images N.b.
ConstReference< PixelT >::type PixelConstReference
A ConstReference to a PixelT.
DecoratedImage(const geom::Extent2I &dimensions=geom::Extent2I())
Create an image of the specified size.
_view_t::reverse_iterator reverse_iterator
An STL compliant reverse iterator.
_view_t::x_iterator xy_x_iterator
An iterator for traversing the pixels in a row, created from an xy_locator.
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.
void set0(int x, int y, const PixelT v, CheckIndices const &check)
x_iterator x_at(int x, int y) const
Return an x_iterator to the point (x, y) in the image.
void swap(ImageBase< PixelT > &a, ImageBase< PixelT > &b)
detail::basic_tag image_category
trait class to identify type of image
static Image readFits(std::string const &filename, int hdu=INT_MIN)
Read an Image from a regular FITS file.
_const_view_t::x_iterator const_x_iterator
A const iterator for traversing the pixels in a row.
Image & operator/=(PixelT const rhs)
Divide lhs by scalar rhs.
bool isContiguous() const
PixelT Pixel
A pixel in this ImageBase.
_view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
std::pair< int, double > positionToIndex(double const pos, lsst::afw::image::xOrY const xy) const
Convert image position to index (nearest integer and fractional parts)
double indexToPosition(double ind, lsst::afw::image::xOrY const xy) const
Convert image index to image position.
double getGain() const
Return the DecoratedImage's gain.
void scaledDivides(double const c, Image< PixelT > const &rhs)
Divide lhs by Image c*rhs (i.e. pixel-by-pixel division)
void assign(ImageBase const &rhs, geom::Box2I const &bbox=geom::Box2I(), ImageOrigin origin=PARENT)
Copy pixels from another image to a specified subregion of this image.
geom::Box2I getBBox(ImageOrigin origin=PARENT) const
Extent< int, 2 > Extent2I
void swap(DecoratedImage &rhs)
void setMetadata(std::shared_ptr< lsst::daf::base::PropertySet > metadata)
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
The base class for all image classed (Image, Mask, MaskedImage, ...)
A Function taking two arguments.
int getX0() const
Return the image's column-origin.
iterator at(int x, int y) const
Return an STL compliant iterator at the point (x, y)
int getWidth() const
Return the number of columns in the image.
_const_view_t::iterator const_iterator
An STL compliant const iterator.
An integer coordinate rectangle.
Image & operator-=(PixelT const rhs)
Subtract scalar rhs from lhs.
_view_t::iterator iterator
An STL compliant iterator.
geom::Point2I getXY0() const
Return the image's origin.
ImageBase & operator<<=(const ImageBase &rhs)
Set the lhs's pixel values to equal the rhs's.
ImageBase & operator=(const ImageBase &rhs)
Shallow assignment operator.
DecoratedImage & operator=(const DecoratedImage &image)
Assignment operator.
geom::Extent2I getDimensions() const
Return the image's size; useful for passing to constructors.
void set0(int x, int y, const PixelT v)
x_iterator row_end(int y) const
Return an x_iterator to the end of the y'th row.
Lifetime-management for memory that goes into FITS memory files.
void writeFits(std::string const &fileName, std::shared_ptr< lsst::daf::base::PropertySet const > metadata=std::shared_ptr< lsst::daf::base::PropertySet const >(), std::string const &mode="w") const
Write an image to a regular FITS file.
_view_t _getRawView() const
A class to manipulate images, masks, and variance as a single object.
_view_t::y_iterator y_iterator
An iterator for traversing the pixels in a column.
std::shared_ptr< lsst::daf::base::PropertySet > getMetadata() const
int getHeight() const
Return the number of rows in the image.
Image & operator+=(PixelT const rhs)
Add scalar rhs to lhs.
traits class for image categories
A class used to request that array accesses be checked.
int getHeight() const
Return the number of rows in the image.
geom::Box2I bboxFromMetadata(daf::base::PropertySet &metadata)
Determine the image bounding box from its metadata (FITS header)
void setGain(double gain)
Set the DecoratedImage's gain.
void scaledPlus(double const c, Image< PixelT > const &rhs)
Add Image c*rhs to lhs.
Image(ndarray::Array< PixelT, 2, 1 > const &array, bool deep=false, geom::Point2I const &xy0=geom::Point2I())
void swap(ImageBase &rhs)
y_iterator col_end(int x) const
Return an y_iterator to the start of the y'th row.
y_iterator y_at(int x, int y) const
Return an y_iterator to the point (x, y) in the image.
ndarray::Array< PixelT const, 2, 1 > ConstArray
An immutable ndarray representation of the image.
std::shared_ptr< Image< PixelT > const > getImage() const
Return a shared_ptr to the DecoratedImage's Image as const.
PixelConstReference get0(int x, int y) const
reverse_iterator rbegin() const
Return an STL compliant reverse iterator to the start of the image.
void setXY0(int const x0, int const y0)
Set the ImageBase's origin.
_view_t::xy_locator::const_t const_xy_locator
A const_xy_locator.
reverse_iterator rend() const
Return an STL compliant reverse iterator to the end of the image.
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.
y_iterator col_begin(int x) const
Return an y_iterator to the start of the y'th row.
void scaledMultiplies(double const c, Image< PixelT > const &rhs)
Multiply lhs by Image c*rhs (i.e. pixel-by-pixel multiplication)
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.
_const_view_t::y_iterator const_y_iterator
A const iterator for traversing the pixels in a column.
lsst::daf::base::PropertySet PropertySet
static _view_t _allocateView(geom::Extent2I const &dimensions, Manager::Ptr &manager)
Reference< PixelT >::type PixelReference
A Reference to a PixelT.
int getX0() const
Return the image's column-origin.
static SinglePixel PixelCast(SinglePixelT rhs)
Convert a type to our SinglePixel type.
ImageT::image_category image_category
xy_locator xy_at(int x, int y) const
Return an xy_locator at the point (x, y) in the image.
static Image readFits(fits::MemFileManager &manager, int hdu=INT_MIN)
Read an Image from a FITS RAM file.
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. ...
x_iterator row_begin(int y) const
Return an x_iterator to the start of the y'th row.
const geom::Extent2I getDimensions() const
Return the image's size; useful for passing to constructors.
static _view_t _makeSubView(geom::Extent2I const &dimensions, geom::Extent2I const &offset, const _view_t &view)
const double PixelZeroPos
position of center of pixel 0
_view_t::xy_locator xy_locator
An xy_locator.
ImageBase(const ImageBase< OtherPixelT > &rhs, const bool deep)
generalised copy constructor
Image(Image< OtherPixelT > const &rhs, const bool deep)
int getWidth() const
Return the number of columns in the image.
ndarray::Array< PixelT, 2, 1 > Array
A mutable ndarray representation of the image.
PixelT SinglePixel
A single Pixel of the same type as those in the ImageBase.
A class to represent a 2-dimensional array of pixels.
CheckIndices(bool check=true)
detail::Image_tag image_category
PixelReference operator()(int x, int y)
Return a reference to the pixel (x, y)
std::string const wcsNameForXY0
boost::gil::channel_traits< PixelT >::const_reference type
const reference type
void writeFits(std::string const &fileName, std::shared_ptr< lsst::daf::base::PropertySet const > metadata=std::shared_ptr< lsst::daf::base::PropertySet const >(), std::string const &mode="w") const
Write a FITS file.
Image< ImagePT > type
Return the desired type.
iterator end() const
Return an STL compliant iterator to the end of the image.
A container for an Image and its associated metadata.
void scaledMinus(double const c, Image< PixelT > const &rhs)
Subtract Image c*rhs from lhs.
metafunction to extract reference type from PixelT
int getY0() const
Return the image's row-origin.
_view_t::y_iterator xy_y_iterator
An iterator for traversing the pixels in a row, created from an xy_locator.
int getY0() const
Return the image's row-origin.
metafunction to extract const reference type from PixelT