31 #ifndef LSST_AFW_IMAGE_IMAGE_H
32 #define LSST_AFW_IMAGE_IMAGE_H
40 #include "boost/mpl/bool.hpp"
55 namespace lsst {
namespace afw {
57 namespace formatters {
58 template <
typename PixelT>
class ImageFormatter;
59 template <
typename PixelT>
class DecoratedImageFormatter;
77 template<
typename ImageT>
90 operator bool()
const {
return _check; }
97 template<
typename PixelT>
99 typedef typename boost::gil::channel_traits<PixelT>::reference
type;
102 template<
typename PixelT>
104 typedef typename boost::gil::channel_traits<PixelT>::const_reference
type;
114 template<
typename PixelT>
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;
125 typedef std::shared_ptr<ImageBase<PixelT> >
Ptr;
126 typedef std::shared_ptr<const ImageBase<PixelT> >
ConstPtr;
166 typedef typename ndarray::Array<PixelT, 2, 1>
Array;
168 typedef typename ndarray::Array<PixelT const, 2, 1>
ConstArray;
174 template<
typename SinglePixelT>
192 template<
typename OtherPixelT>
194 lsst::daf::base::
Citizen(typeid(this)) {
196 throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError,
197 "Only deep copies are permitted for ImageBases with different pixel types");
201 copy_and_convert_pixels(rhs.
_gilView, tmp._gilView);
278 int const roundedIndex =
static_cast<int>(fullIndex + 0.5);
279 double const residual = fullIndex - roundedIndex;
280 return std::pair<int, double>(roundedIndex, residual);
411 template<
typename PixelT>
412 void swap(ImageBase<PixelT>& a, ImageBase<PixelT>&
b);
416 template<
typename PixelT>
417 class Image :
public ImageBase<PixelT> {
420 typedef std::shared_ptr<Image<PixelT> >
Ptr;
421 typedef std::shared_ptr<const Image<PixelT> >
ConstPtr;
426 template<
typename ImagePT=PixelT>
433 template<
typename OtherPixelT>
friend class Image;
435 explicit Image(
unsigned int width,
unsigned int height,
PixelT initialValue=0);
440 const bool deep=
false);
441 Image(
const Image& rhs,
const bool deep=
false);
456 std::string
const & fileName,
int hdu=0,
498 template<
typename OtherPixelT>
502 explicit Image(ndarray::Array<PixelT,2,1>
const & array,
bool deep =
false,
521 std::string
const& fileName,
523 std::string
const& mode=
"w"
536 std::string
const& mode=
"w"
599 template<
typename LhsPixelT,
typename RhsPixelT>
600 void operator+=(Image<LhsPixelT> &lhs, Image<RhsPixelT>
const& rhs);
601 template<
typename LhsPixelT,
typename RhsPixelT>
602 void operator-=(Image<LhsPixelT> &lhs, Image<RhsPixelT>
const& rhs);
603 template<
typename LhsPixelT,
typename RhsPixelT>
604 void operator*=(Image<LhsPixelT> &lhs, Image<RhsPixelT>
const& rhs);
605 template<
typename LhsPixelT,
typename RhsPixelT>
606 void operator/=(Image<LhsPixelT> &lhs, Image<RhsPixelT>
const& rhs);
608 template<
typename PixelT>
609 void swap(Image<PixelT>& a, Image<PixelT>&
b);
615 template<
typename PixelT>
620 typedef std::shared_ptr<DecoratedImage>
Ptr;
622 typedef std::shared_ptr<const DecoratedImage>
ConstPtr;
633 std::
string const& fileName,
635 geom::Box2I const& bbox=geom::Box2I(),
660 std::string
const& fileName,
662 std::string
const& mode=
"w"
iterator at(int x, int y) const
Return an STL compliant iterator at the point (x, y)
void scaledDivides(double const c, Image< PixelT >const &rhs)
Divide lhs by Image c*rhs (i.e. pixel-by-pixel division)
boost::gil::channel_traits< PixelT >::reference type
reference type
PixelConstReference get0(int x, int y, CheckIndices const &check) const
iterator end() const
Return an STL compliant iterator to the end of the image.
void setXY0(geom::Point2I const origin)
A templated class to return this classes' type (present in Image/Mask/MaskedImage) ...
_const_view_t::reverse_iterator const_reverse_iterator
An STL compliant const reverse iterator.
A coordinate class intended to represent absolute positions.
A set of classes of general utility in connection with images.
reverse_iterator rend() const
Return an STL compliant reverse iterator to the end of the image.
ConstReference< PixelT >::type PixelConstReference
A ConstReference to a PixelT.
#define LSST_PERSIST_FORMATTER(formatter...)
_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.
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.
detail::basic_tag image_category
trait class to identify type of image
boost::shared_ptr< Image< PixelT > > _image
_const_view_t::x_iterator const_x_iterator
A const iterator for traversing the pixels in a row.
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)
std::shared_ptr< const ImageBase< PixelT > > ConstPtr
A shared_ptr to a const ImageBase.
double indexToPosition(double ind, lsst::afw::image::xOrY const xy) const
Convert image index to image position.
std::shared_ptr< DecoratedImage > Ptr
shared_ptr to a DecoratedImage
boost::shared_ptr< Image< PixelT > > ImagePtr
shared_ptr to the Image
Image< ImagePT > type
Return the desired type.
void operator/=(PixelT const rhs)
geom::Box2I getBBox(ImageOrigin origin=PARENT) const
static _view_t _makeSubView(geom::Extent2I const &dimensions, geom::Extent2I const &offset, const _view_t &view)
void swap(DecoratedImage &rhs)
void swap(Mask< PixelT > &a, Mask< PixelT > &b)
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, ...)
Extent< int, 2 > Extent2I
void operator*=(Image< LhsPixelT > &lhs, Image< RhsPixelT > const &rhs)
std::shared_ptr< const DecoratedImage > ConstPtr
shared_ptr to a const DecoratedImage
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.
void operator<<=(const ImageBase &rhs)
Image(ndarray::Array< PixelT, 2, 1 > const &array, bool deep=false, geom::Point2I const &xy0=geom::Point2I())
table::Key< table::Array< Kernel::Pixel > > image
void scaledPlus(double const c, Image< PixelT >const &rhs)
Add Image c*rhs to lhs.
boost::shared_ptr< lsst::daf::base::PropertySet > getMetadata() const
_view_t::iterator iterator
An STL compliant iterator.
lsst::afw::image::detail::types_traits< PixelT >::const_view_t _const_view_t
geom::Point2I getXY0() const
afw::table::PointKey< int > dimensions
Image & operator=(const PixelT rhs)
Set the image's pixels to rhs.
void operator*=(PixelT const rhs)
Multiply lhs by scalar rhs.
static Image readFits(std::string const &filename, int hdu=0)
Read an Image from a regular FITS file.
lsst::afw::image::detail::types_traits< PixelT >::view_t _view_t
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.
std::shared_ptr< ImageBase< PixelT > > Ptr
A shared_ptr to an ImageBase.
Types and classes to interface lsst::afw::image to boost::gil.
void assign(ImageBase const &rsh, geom::Box2I const &bbox=geom::Box2I(), ImageOrigin origin=PARENT)
_view_t _getRawView() const
ImagePtr getImage()
Return a shared_ptr to the DecoratedImage's Image.
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.
int getHeight() const
Return the number of rows in the image.
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.
void setGain(double gain)
Set the DecoratedImage's gain.
void operator+=(PixelT const rhs)
Add scalar rhs to lhs.
void swap(ImageBase &rhs)
y_iterator col_end(int x) const
Return an y_iterator to the end of the y'th row.
void operator-=(PixelT const rhs)
Subtract scalar rhs from lhs.
static Image readFits(fits::MemFileManager &manager, int hdu=0)
Read an Image from a FITS RAM file.
std::shared_ptr< Image< PixelT > > Ptr
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.
PixelConstReference get0(int x, int y) const
void setXY0(int const x0, int const y0)
void writeFits(std::string const &fileName, boost::shared_ptr< lsst::daf::base::PropertySet const > metadata=boost::shared_ptr< lsst::daf::base::PropertySet const >(), std::string const &mode="w") const
_view_t::xy_locator::const_t const_xy_locator
A const_xy_locator.
#define LSST_EXCEPT(type,...)
Image(Image< OtherPixelT > const &rhs, const bool deep)
y_iterator col_begin(int x) const
boost::shared_ptr< lsst::daf::base::PropertySet > _metadata
Citizen(const std::type_info &)
static _view_t _allocateView(geom::Extent2I const &dimensions, Manager::Ptr &manager)
ImageConstPtr getImage() const
Return a shared_ptr to the DecoratedImage's Image as const.
_const_view_t::y_iterator const_y_iterator
A const iterator for traversing the pixels in a column.
void scaledMinus(double const c, Image< PixelT >const &rhs)
Subtract Image c*rhs from lhs.
Class for storing generic metadata.
std::shared_ptr< const Image< PixelT > > ConstPtr
void operator/=(Image< LhsPixelT > &lhs, Image< RhsPixelT > const &rhs)
Reference< PixelT >::type PixelReference
A Reference to a PixelT.
int getX0() const
Return the image's column-origin.
boost::shared_ptr< Image< PixelT > const > ImageConstPtr
shared_ptr to the Image as const
Define the basic Function classes.
static SinglePixel PixelCast(SinglePixelT rhs)
Convert a type to our SinglePixel type.
afw::table::Key< double > b
void scaledMultiplies(double const c, Image< PixelT >const &rhs)
Multiply lhs by Image c*rhs (i.e. pixel-by-pixel multiplication)
ImageT::image_category image_category
xy_locator xy_at(int x, int y) const
void operator-=(Image< LhsPixelT > &lhs, Image< RhsPixelT > const &rhs)
Base class for all persistable classes.
void setMetadata(boost::shared_ptr< lsst::daf::base::PropertySet > metadata)
x_iterator row_begin(int y) const
const geom::Extent2I getDimensions() const
Return the image's size; useful for passing to constructors.
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
reverse_iterator rbegin() const
Return an STL compliant reverse iterator to the start of the image.
Include files required for standard LSST Exception handling.
const double PixelZeroPos
FITS uses 1.0, SDSS uses 0.5, LSST uses 0.0 (http://dev.lsstcorp.org/trac/wiki/BottomLeftPixelProposa...
_view_t::xy_locator xy_locator
An xy_locator.
ImageBase(const ImageBase< OtherPixelT > &rhs, const bool deep)
A coordinate class intended to represent offsets and dimensions.
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.
detail::Image_tag image_category
A class to represent a 2-dimensional array of pixels.
CheckIndices(bool check=true)
std::string const wcsNameForXY0
void writeFits(std::string const &fileName, boost::shared_ptr< lsst::daf::base::PropertySet const > metadata=boost::shared_ptr< lsst::daf::base::PropertySet const >(), std::string const &mode="w") const
Write an image to a regular FITS file.
boost::gil::channel_traits< PixelT >::const_reference type
const reference type
ImageBase & operator=(const ImageBase &rhs)
PixelReference operator()(int x, int y)
Return a reference to the pixel (x, y)
A container for an Image and its associated metadata.
void operator+=(Image< LhsPixelT > &lhs, Image< RhsPixelT > const &rhs)
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.
int getY0() const
Return the image's row-origin.
metafunction to extract const reference type from PixelT