23 #if !defined(LSST_AFW_IMAGE_PIXEL_H)
24 #define LSST_AFW_IMAGE_PIXEL_H
29 #include <type_traits>
31 namespace lsst {
namespace afw {
namespace image {
namespace pixel {
33 template <
typename,
typename,
typename,
typename,
typename>
class BinaryExpr;
62 template<
typename _ImagePixelT,
typename _MaskPixelT,
typename _VariancePixelT=
double>
66 template<
typename,
typename,
typename>
friend class Pixel;
78 template<
typename rhsExpr>
90 _image(std::numeric_limits<_ImagePixelT>::has_quiet_NaN ?
91 std::numeric_limits<_ImagePixelT>::quiet_NaN() : 0),
93 _variance(std::numeric_limits<_VariancePixelT>::has_quiet_NaN ?
94 std::numeric_limits<_VariancePixelT>::quiet_NaN() : 0)
103 template<
typename PixelT>
109 std::numeric_limits<PixelT>::has_quiet_NaN ?
110 std::numeric_limits<PixelT>::quiet_NaN()
116 template<
typename _ImagePixelT,
typename _MaskPixelT,
typename _VariancePixelT>
131 template<
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
137 template<
typename _ImagePixelT,
typename _MaskPixelT,
typename _VariancePixelT=
double>
173 template<
typename rhsExpr>
210 template<
typename T1>
212 return lhs.
image() == rhs.image() && lhs.
mask() == rhs.mask() && lhs.
variance() == rhs.variance();
216 template<
typename T1>
218 return !(lhs == rhs);
225 template<
typename ExprT>
234 template<
typename ExprT>
243 template<
typename ExprT>
252 template<
typename ExprT>
268 template <
typename ExprT>
316 template <
typename T1>
317 struct noop :
public std::unary_function<T1, T1> {
329 template <
typename T1>
330 struct bitwise_or :
public std::binary_function<T1, T1, T1> {
345 template <
typename T1>
346 struct variance_divides {
347 T1
operator()(T1
const&
x, T1
const&
y, T1
const& vx, T1
const& vy)
const {
350 T1
const iy2 = 1.0/y2;
351 return x2*vy*iy2*iy2 + vx*iy2;
364 template <
typename T1>
365 struct variance_multiplies {
366 T1
operator()(T1
const&
x, T1
const&
y, T1
const& vx, T1
const& vy)
const {
369 return x2*vy + y2*vx;
382 template <
typename T1>
383 struct variance_plus {
384 T1
operator()(T1
const&, T1
const&, T1
const& vx, T1
const& vy)
const {
400 template <
typename T1>
404 T1
operator()(T1
const&, T1
const&, T1
const& vx, T1
const& vy)
const {
405 return vx + vy + 2*
_alpha*sqrt(vx*vy);
416 template <
typename ExprT1,
typename ImageBinOp,
typename MaskBinOp,
typename VarianceBinOp>
424 ImageBinOp imageOp=ImageBinOp(), MaskBinOp maskOp=MaskBinOp(), VarianceBinOp varOp=VarianceBinOp()) :
449 template <
typename ExprT1,
typename ExprT2,
typename ImageBinOp,
typename MaskBinOp,
typename VarianceBinOp>
457 ImageBinOp imageOp=ImageBinOp(), MaskBinOp maskOp=MaskBinOp(), VarianceBinOp varOp=VarianceBinOp()) :
462 ImageBinOp imageOp=ImageBinOp(), MaskBinOp maskOp=MaskBinOp(), VarianceBinOp =VarianceBinOp()) :
489 template <
typename ExprT1,
typename ImageBinOp,
typename MaskBinOp,
typename VarianceBinOp>
490 class BinaryExpr<ExprT1, double, ImageBinOp, MaskBinOp, VarianceBinOp> {
497 ImageBinOp imageOp=ImageBinOp(), MaskBinOp maskOp=MaskBinOp(), VarianceBinOp varOp=VarianceBinOp()) :
502 ImageBinOp imageOp=ImageBinOp(), MaskBinOp maskOp=MaskBinOp(), VarianceBinOp=VarianceBinOp()) :
528 template <
typename ExprT1>
530 std::negate<typename exprTraits<ExprT1>::ImagePixelT>,
534 std::negate<typename exprTraits<ExprT1>::ImagePixelT>,
541 template <
typename ExprT1,
typename ExprT2>
542 BinaryExpr<ExprT1, ExprT2,
543 std::plus<typename exprTraits<ExprT1>::ImagePixelT>,
544 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
547 std::plus<typename exprTraits<ExprT1>::ImagePixelT>,
553 template <
typename ExprT1,
typename ExprT2>
556 std::plus<typename exprTraits<ExprT1>::ImagePixelT>,
567 template <
typename ExprT1,
typename ExprT2>
568 ExprT1 doPlus(ExprT1 e1, ExprT2 e2,
574 template <
typename ExprT1,
typename ExprT2>
575 BinaryExpr<ExprT1, ExprT2,
576 std::plus<typename exprTraits<ExprT1>::ImagePixelT>,
577 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
578 variance_plus_covar<typename exprTraits<ExprT1>::VariancePixelT> > doPlus(ExprT1 e1, ExprT2 e2,
580 boost::mpl::false_) {
581 return BinaryExpr<ExprT1, ExprT2,
582 std::plus<typename exprTraits<ExprT1>::ImagePixelT>,
583 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
584 variance_plus_covar<typename exprTraits<ExprT1>::VariancePixelT> >(e1, e2,
alpha);
589 template<
typename ExprT1,
typename ExprT2>
590 inline ExprT1
plus(ExprT1& lhs,
594 return doPlus(lhs, rhs, covariance,
typename std::is_arithmetic<ExprT1>::type());
599 template <
typename ExprT1,
typename ExprT2>
600 BinaryExpr<ExprT1, ExprT2,
601 std::minus<typename exprTraits<ExprT1>::ImagePixelT>,
602 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
605 std::minus<typename exprTraits<ExprT1>::ImagePixelT>,
611 template <
typename ExprT1,
typename ExprT2>
614 std::minus<typename exprTraits<ExprT1>::ImagePixelT>,
622 template <
typename ExprT1,
typename ExprT2>
623 BinaryExpr<ExprT1, ExprT2,
624 std::multiplies<typename exprTraits<ExprT1>::ImagePixelT>,
625 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
628 std::multiplies<typename exprTraits<ExprT1>::ImagePixelT>,
634 template <
typename ExprT1,
typename ExprT2>
637 std::multiplies<typename exprTraits<ExprT1>::ImagePixelT>,
645 template <
typename ExprT1,
typename ExprT2>
646 BinaryExpr<ExprT1, ExprT2,
647 std::divides<typename exprTraits<ExprT1>::ImagePixelT>,
648 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
651 std::divides<typename exprTraits<ExprT1>::ImagePixelT>,
657 template <
typename ExprT1,
typename ExprT2>
660 std::divides<typename exprTraits<ExprT1>::ImagePixelT>,
668 template<
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
669 std::ostream& operator<<(std::ostream &os, SinglePixel<ImagePixelT, MaskPixelT, VariancePixelT>
const& v) {
670 return os <<
"(" << v.image() <<
", " << v.mask() <<
", " << v.variance() <<
")";
674 template<
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
675 std::ostream& operator<<(std::ostream &os, Pixel<ImagePixelT, MaskPixelT, VariancePixelT>
const& v) {
676 return os <<
"(" << v.image() <<
", " << v.mask() <<
", " << v.variance() <<
")";
680 template <
typename ExprT1,
typename ExprT2,
typename BinOp,
typename MaskBinOp,
typename VarBinOp>
681 std::ostream& operator<<(std::ostream &os, BinaryExpr<ExprT1, ExprT2, BinOp, MaskBinOp, VarBinOp>
const& v) {
682 return os <<
"(" << v.image() <<
", " << v.mask() <<
", " << v.variance() <<
")";
VariancePixelT variance() const
Return the variance part of a Pixel.
Pixel operator=(double const &rhs_image)
set the image part of a Pixel to rhs_image (the mask and variance are set to 0)
exprTraits< double >::MaskPixelT MaskPixelT
friend Pixel operator/=(Pixel const &e1, ExprT const &e2)
Evaluate e1 /= e2, and return e1.
Class for representing binary operations.
SinglePixel< ImagePixelT, MaskPixelT, VariancePixelT > makeSinglePixel(ImagePixelT x, MaskPixelT m, VariancePixelT v)
Return a SinglePixel.
bitwise_or doesn't seem to be in std::
BinaryExpr< ExprT1, ExprT2, std::multiplies< typename exprTraits< ExprT1 >::ImagePixelT >, bitwise_or< typename exprTraits< ExprT1 >::MaskPixelT >, variance_multiplies< typename exprTraits< ExprT1 >::VariancePixelT > > operator*(ExprT1 e1, ExprT2 e2)
Template to evaluate (e1 * e2)
MaskPixelT mask() const
evaluate the mask part of the expression
SinglePixel< ImagePixelT, MaskPixelT, VariancePixelT > expr_type
BinaryExpr(ExprT1 e1, ExprT2 e2, double const alpha, ImageBinOp imageOp=ImageBinOp(), MaskBinOp maskOp=MaskBinOp(), VarianceBinOp=VarianceBinOp())
A binary operation, with three functors to represent the image/mask/variance operations and an extra ...
exprTraits< ExprT1 >::VariancePixelT VariancePixelT
exprTraits< ExprT1 >::MaskPixelT MaskPixelT
ImagePixelT image() const
evaluate the image part of the expression
Pixel operator=(int const &rhs_image)
set the image part of a Pixel to rhs_image (the mask and variance are set to 0)
T1 operator()(T1 const &, T1 const &y, T1 const &vx) const
BinaryExpr(ExprT1 e1, double e2, ImageBinOp imageOp=ImageBinOp(), MaskBinOp maskOp=MaskBinOp(), VarianceBinOp varOp=VarianceBinOp())
A binary operation, with three functors to represent the image/mask/variance operations.
VariancePixelT variance() const
friend bool operator!=(Pixel const &lhs, T1 const &rhs)
Return true iff two pixels are unequal (in at least one of image, mask, and variance) ...
SinglePixel(double const image, int mask=0, double const variance=0)
ImagePixelT image() const
evaluate the image part of the expression
T1 operator()(T1 const &, T1 const &, T1 const &vx) const
SinglePixel< ImagePixelT, MaskPixelT, VariancePixelT > expr_type
Pixel(ImagePixelT const &image, MaskPixelT const &mask=0x0, VariancePixelT const &variance=0)
Construct a Pixel from references to its image/mask/variance components.
ExprT1 operator-=(ExprT1 &e1, ExprT2 e2)
Template to evaluate e1 -= e2.
VariancePixelT variance() const
evaluate the variance part of the expression
T1 operator()(T1 const &, T1 const &, T1 const &vx) const
A single pixel of the same type as a MaskedImage.
MaskPixelT mask() const
Return the mask part of a Pixel.
BinaryExpr(ExprT1 e1, ExprT2 e2, ImageBinOp imageOp=ImageBinOp(), MaskBinOp maskOp=MaskBinOp(), VarianceBinOp varOp=VarianceBinOp())
A binary operation, with three functors to represent the image/mask/variance operations.
exprTraits< ExprT1 >::expr_type _expr1
ImagePixelT image() const
evaluate the image part of the expression
exprTraits< ExprT1 >::MaskPixelT MaskPixelT
ExprT::ImagePixelT ImagePixelT
BinaryExpr< ExprT1, ExprT2, std::divides< typename exprTraits< ExprT1 >::ImagePixelT >, bitwise_or< typename exprTraits< ExprT1 >::MaskPixelT >, variance_divides< typename exprTraits< ExprT1 >::VariancePixelT > > operator/(ExprT1 e1, ExprT2 e2)
Template to evaluate (e1 / e2)
ExprT::MaskPixelT MaskPixelT
table::Key< table::Array< Kernel::Pixel > > image
MaskPixelT mask() const
evaluate the mask part of the expression
exprTraits< ExprT1 >::VariancePixelT VariancePixelT
exprTraits< ExprT1 >::expr_type _expr1
UnaryExpr(ExprT1 e1, ImageBinOp imageOp=ImageBinOp(), MaskBinOp maskOp=MaskBinOp(), VarianceBinOp varOp=VarianceBinOp())
a unary expression, with three functors to represent the image/mask/variance operations ...
static const PixelT padValue()
The quantity to use when a pixel value is undefined.
VariancePixelT variance() const
evaluate the variance part of the expression
exprTraits< ExprT2 >::expr_type _expr2
T1 operator()(T1 const &, T1 const &, T1 const &vx, T1 const &vy) const
SinglePixel< ImagePixelT, MaskPixelT, VariancePixelT > expr_type
exprTraits< double >::MaskPixelT MaskPixelT
Calculate the variance when we divide two Pixels.
variance_plus_covar(double alpha=0)
T1 operator()(T1 const &x, T1 const &y, T1 const &vx, T1 const &vy) const
ExprT1 plus(ExprT1 &lhs, ExprT2 const &rhs, float covariance)
Like operator+(), but assume that covariance's 2*alpha*sqrt(vx*vy)
ImagePixelT image() const
Return the image part of a Pixel.
T1 operator()(T1 const &x, T1 const &y, T1 const &vx, T1 const &vy) const
BinaryExpr(ExprT1 e1, double e2, double const alpha, ImageBinOp imageOp=ImageBinOp(), MaskBinOp maskOp=MaskBinOp(), VarianceBinOp=VarianceBinOp())
A binary operation, with three functors to represent the image/mask/variance operations and an extra ...
friend Pixel operator-=(Pixel const &e1, ExprT const &e2)
Evaluate e1 -= e2, and return e1.
Pixel operator=(rhsExpr const &rhs)
Assign a Pixel by evaluating an expression.
ImagePixelT image() const
MaskPixelT mask() const
evaluate the mask part of the expression
ExprT1 operator*=(ExprT1 &e1, ExprT2 e2)
Template to evaluate e1 *= e2.
ExprT1 operator/=(ExprT1 &e1, ExprT2 e2)
Template to evaluate e1 /= e2.
_VariancePixelT VariancePixelT
A pixel of a MaskedImage.
exprTraits< double >::VariancePixelT VariancePixelT
The variance of the sum of a pair of correlated pixels.
exprTraits< ExprT1 >::expr_type _expr1
exprTraits< ExprT1 >::VariancePixelT VariancePixelT
T1 operator()(T1 const &, T1 const &y, T1 const &vx) const
friend Pixel operator*=(Pixel const &e1, ExprT const &e2)
Evaluate e1 *= e2, and return e1.
exprTraits< ExprT1 >::ImagePixelT ImagePixelT
SinglePixel()
Default Ctor.
T1 operator()(const T1 &x, const T1 &y) const
exprTraits< ExprT1 >::ImagePixelT ImagePixelT
SinglePixel(rhsExpr const &rhs)
exprTraits< double >::VariancePixelT VariancePixelT
ExprT::VariancePixelT VariancePixelT
Pixel operator=(Pixel const &rhs)
VariancePixelT variance() const
evaluate the variance part of the expression
T1 operator()(const T1 &x) const
A traits class to return the types of the image/mask/variance.
exprTraits< ExprT1 >::MaskPixelT MaskPixelT
table::PointKey< int > pixel
SinglePixel(int const image, int mask=0, double const variance=0)
T1 operator()(T1 const &, T1 const &, T1 const &vx, T1 const &vy) const
SinglePixel< _ImagePixelT, _MaskPixelT, _VariancePixelT > PixelT
Pixel(SinglePixel< ImagePixelT, MaskPixelT, VariancePixelT > &rhs)
exprTraits< double >::MaskPixelT MaskPixelT
Class for representing Unary operations.
Calculate the variance when we multiply two Pixels.
A class used to identify classes that represent MaskedImage pixels.
UnaryExpr< ExprT1, std::negate< typename exprTraits< ExprT1 >::ImagePixelT >, noop< typename exprTraits< ExprT1 >::MaskPixelT >, noop< typename exprTraits< ExprT1 >::VariancePixelT > > operator-(ExprT1 e1)
Template for -e1.
BinaryExpr< ExprT1, ExprT2, std::plus< typename exprTraits< ExprT1 >::ImagePixelT >, bitwise_or< typename exprTraits< ExprT1 >::MaskPixelT >, variance_plus< typename exprTraits< ExprT1 >::VariancePixelT > > operator+(ExprT1 e1, ExprT2 e2)
Template for (e1 + e2)
static const PixelT padValue()
The quantity to use when a pixel value is undefined.
ExprT1 operator+=(ExprT1 &e1, ExprT2 e2)
template for e1 += e2
exprTraits< ExprT1 >::ImagePixelT ImagePixelT
Calculate the variance when we add (or subtract) two Pixels.
VariancePixelT & _variance
A noop functor (useful for e.g.
SinglePixel< ImagePixelT, MaskPixelT, VariancePixelT > expr_type
friend bool operator==(Pixel const &lhs, T1 const &rhs)
Return true iff two pixels are equal (in all three of image, mask, and variance)
exprTraits< double >::VariancePixelT VariancePixelT
_VariancePixelT VariancePixelT
friend Pixel operator+=(Pixel const &e1, ExprT const &e2)
Evaluate e1 += e2, and return e1.
T1 operator()(const T1 &x) const