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>
173 return SinglePixel(rhs);
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);
289 PixelReference operator()(
int x,
int y);
291 PixelReference operator()(
int x,
int y,
CheckIndices const&);
293 PixelConstReference operator()(
int x,
int y)
const;
295 PixelConstReference operator()(
int x,
int y,
CheckIndices const&)
const;
297 PixelConstReference
get0(
int x,
int y)
const {
return operator()(x - getX0(), y - getY0()); }
299 return operator()(x - getX0(), y - getY0(), check);
301 void set0(
int x,
int y,
const PixelT v) { operator()(x - getX0(), y - getY0()) = v; }
303 operator()(x - getX0(), y - getY0(), check) = v;
317 int getX0()
const {
return _origin.getX(); }
325 int getY0()
const {
return _origin.getY(); }
345 double const fullIndex = pos -
PixelZeroPos - (xy ==
X ? getX0() : getY0());
346 int const roundedIndex =
static_cast<int>(fullIndex + 0.5);
347 double const residual = fullIndex - roundedIndex;
348 return std::pair<int, double>(roundedIndex, residual);
372 ConstArray getArray()
const;
381 iterator begin()
const;
383 iterator
end()
const;
385 reverse_iterator rbegin()
const;
387 reverse_iterator rend()
const;
389 iterator at(
int x,
int y)
const;
398 fast_iterator begin(
bool)
const;
406 fast_iterator
end(
bool)
const;
412 x_iterator
row_begin(
int y)
const {
return _gilView.row_begin(y); }
415 x_iterator
row_end(
int y)
const {
return _gilView.row_end(y); }
418 x_iterator
x_at(
int x,
int y)
const {
return _gilView.x_at(x, y); }
424 y_iterator
col_begin(
int x)
const {
return _gilView.col_begin(x); }
427 y_iterator
col_end(
int x)
const {
return _gilView.col_end(x); }
430 y_iterator
y_at(
int x,
int y)
const {
return _gilView.y_at(x, y); }
436 xy_locator
xy_at(
int x,
int y)
const {
return xy_locator(_gilView.xy_at(x, y)); }
465 Manager::Ptr _manager;
474 const _view_t& view);
478 inline bool isContiguous()
const {
return begin() + getWidth() * getHeight() ==
end(); }
481 template <
typename PixelT>
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,
617 Image& operator=(
const PixelT rhs);
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;
718 void scaledMultiplies(
double const c,
Image<PixelT> const& rhs);
728 void scaledDivides(
double const c,
Image<PixelT> const& rhs);
741 template <
typename LhsPixelT,
typename RhsPixelT>
744 template <
typename LhsPixelT,
typename RhsPixelT>
747 template <
typename LhsPixelT,
typename RhsPixelT>
750 template <
typename LhsPixelT,
typename RhsPixelT>
753 template <
typename PixelT>
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>
bool isContiguous() const
std::shared_ptr< Image< PixelT > > getImage()
Return a shared_ptr to the DecoratedImage's Image.
boost::gil::channel_traits< PixelT >::reference type
reference type
void setXY0(geom::Point2I const origin)
Set the ImageBase's origin.
std::shared_ptr< Image< PixelT > const > getImage() const
Return a shared_ptr to the DecoratedImage's Image as const.
A templated class to return this classes' type (present in Image/Mask/MaskedImage) ...
afw::table::PointKey< int > dimensions
void scaledPlus(OutImageT &outImage, double c1, InImageT const &inImage1, double c2, InImageT const &inImage2)
Compute the scaled sum of two images.
_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.
std::shared_ptr< lsst::daf::base::PropertySet > getMetadata() const
ConstReference< PixelT >::type PixelConstReference
A ConstReference to a PixelT.
int getWidth() const
Return the number of columns in the image.
_view_t::reverse_iterator reverse_iterator
An STL compliant reverse iterator.
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)
int getHeight() const
Return the number of rows in the image.
_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)
geom::Box2I getBBox(ImageOrigin origin=PARENT) const
detail::basic_tag image_category
trait class to identify type of image
int getHeight() const
Return the number of rows in the image.
static Image readFits(std::string const &filename, int hdu=INT_MIN)
Read an Image from a regular FITS file.
const geom::Extent2I getDimensions() const
Return the image's size; useful for passing to constructors.
_const_view_t::x_iterator const_x_iterator
A const iterator for traversing the pixels in a row.
PixelT Pixel
A pixel in this ImageBase.
_view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
Extent< int, 2 > Extent2I
int getX0() const
Return the image's column-origin.
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.
x_iterator row_begin(int y) const
Return an x_iterator to the start of the y'th row.
_const_view_t::iterator const_iterator
An STL compliant const iterator.
An integer coordinate rectangle.
_view_t::iterator iterator
An STL compliant iterator.
y_iterator y_at(int x, int y) const
Return an y_iterator to the point (x, y) in the image.
y_iterator col_begin(int x) const
Return an y_iterator to the start of the y'th row.
geom::Extent2I getDimensions() const
Return the image's size; useful for passing to constructors.
A base class for image defects.
void set0(int x, int y, const PixelT v)
Lifetime-management for memory that goes into FITS memory files.
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.
traits class for image categories
A class used to request that array accesses be checked.
geom::Box2I bboxFromMetadata(daf::base::PropertySet &metadata)
Determine the image bounding box from its metadata (FITS header)
y_iterator col_end(int x) const
Return an y_iterator to the start of the y'th row.
void setGain(double gain)
Set the DecoratedImage's gain.
Image(ndarray::Array< PixelT, 2, 1 > const &array, bool deep=false, geom::Point2I const &xy0=geom::Point2I())
ndarray::Array< PixelT const, 2, 1 > ConstArray
An immutable ndarray representation 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.
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.
int getY0() const
Return the image's row-origin.
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
int getWidth() const
Return the number of columns in the image.
Reference< PixelT >::type PixelReference
A Reference to a PixelT.
static SinglePixel PixelCast(SinglePixelT rhs)
Convert a type to our SinglePixel type.
x_iterator row_end(int y) const
Return an x_iterator to the end of the y'th row.
x_iterator x_at(int x, int y) const
Return an x_iterator to the point (x, y) in the image.
int getX0() const
Return the image's column-origin.
ImageT::image_category image_category
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. ...
PixelConstReference get0(int x, int y, CheckIndices const &check) const
_view_t _getRawView() const
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)
ndarray::Array< PixelT, 2, 1 > Array
A mutable ndarray representation of the image.
xy_locator xy_at(int x, int y) const
Return an xy_locator at the point (x, y) in the image.
PixelConstReference get0(int x, int y) const
PixelT SinglePixel
A single Pixel of the same type as those in the ImageBase.
int getY0() const
Return the image's row-origin.
A class to represent a 2-dimensional array of pixels.
CheckIndices(bool check=true)
detail::Image_tag image_category
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.
std::string const wcsNameForXY0
boost::gil::channel_traits< PixelT >::const_reference type
const reference type
Image< ImagePT > type
Return the desired type.
A container for an Image and its associated metadata.
metafunction to extract reference type from PixelT
_view_t::y_iterator xy_y_iterator
An iterator for traversing the pixels in a row, created from an xy_locator.
geom::Point2I getXY0() const
Return the image's origin.
metafunction to extract const reference type from PixelT