23 #if !defined(LSST_AFW_IMAGE_PIXEL_H)
24 #define LSST_AFW_IMAGE_PIXEL_H
30 namespace lsst {
namespace afw {
namespace image {
namespace pixel {
32 template <
typename,
typename,
typename,
typename,
typename>
class BinaryExpr;
61 template<
typename _ImagePixelT,
typename _MaskPixelT,
typename _VariancePixelT=
double>
65 template<
typename,
typename,
typename>
friend class Pixel;
77 template<
typename rhsExpr>
89 _image(std::numeric_limits<_ImagePixelT>::has_quiet_NaN ?
90 std::numeric_limits<_ImagePixelT>::quiet_NaN() : 0),
92 _variance(std::numeric_limits<_VariancePixelT>::has_quiet_NaN ?
93 std::numeric_limits<_VariancePixelT>::quiet_NaN() : 0)
102 template<
typename PixelT>
108 std::numeric_limits<PixelT>::has_quiet_NaN ?
109 std::numeric_limits<PixelT>::quiet_NaN()
115 template<
typename _ImagePixelT,
typename _MaskPixelT,
typename _VariancePixelT>
130 template<
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
136 template<
typename _ImagePixelT,
typename _MaskPixelT,
typename _VariancePixelT=
double>
172 template<
typename rhsExpr>
209 template<
typename T1>
211 return lhs.
image() == rhs.image() && lhs.
mask() == rhs.mask() && lhs.
variance() == rhs.variance();
215 template<
typename T1>
217 return !(lhs == rhs);
224 template<
typename ExprT>
233 template<
typename ExprT>
242 template<
typename ExprT>
251 template<
typename ExprT>
267 template <
typename ExprT>
315 template <
typename T1>
316 struct noop :
public std::unary_function<T1, T1> {
328 template <
typename T1>
329 struct bitwise_or :
public std::binary_function<T1, T1, T1> {
344 template <
typename T1>
345 struct variance_divides {
346 T1
operator()(T1
const&
x, T1
const&
y, T1
const& vx, T1
const& vy)
const {
349 T1
const iy2 = 1.0/y2;
350 return x2*vy*iy2*iy2 + vx*iy2;
363 template <
typename T1>
364 struct variance_multiplies {
365 T1
operator()(T1
const&
x, T1
const&
y, T1
const& vx, T1
const& vy)
const {
368 return x2*vy + y2*vx;
381 template <
typename T1>
382 struct variance_plus {
383 T1
operator()(T1
const&, T1
const&, T1
const& vx, T1
const& vy)
const {
399 template <
typename T1>
403 T1
operator()(T1
const&, T1
const&, T1
const& vx, T1
const& vy)
const {
404 return vx + vy + 2*
_alpha*sqrt(vx*vy);
415 template <
typename ExprT1,
typename ImageBinOp,
typename MaskBinOp,
typename VarianceBinOp>
423 ImageBinOp imageOp=ImageBinOp(), MaskBinOp maskOp=MaskBinOp(), VarianceBinOp varOp=VarianceBinOp()) :
448 template <
typename ExprT1,
typename ExprT2,
typename ImageBinOp,
typename MaskBinOp,
typename VarianceBinOp>
456 ImageBinOp imageOp=ImageBinOp(), MaskBinOp maskOp=MaskBinOp(), VarianceBinOp varOp=VarianceBinOp()) :
461 ImageBinOp imageOp=ImageBinOp(), MaskBinOp maskOp=MaskBinOp(), VarianceBinOp =VarianceBinOp()) :
488 template <
typename ExprT1,
typename ImageBinOp,
typename MaskBinOp,
typename VarianceBinOp>
489 class BinaryExpr<ExprT1, double, ImageBinOp, MaskBinOp, VarianceBinOp> {
496 ImageBinOp imageOp=ImageBinOp(), MaskBinOp maskOp=MaskBinOp(), VarianceBinOp varOp=VarianceBinOp()) :
501 ImageBinOp imageOp=ImageBinOp(), MaskBinOp maskOp=MaskBinOp(), VarianceBinOp=VarianceBinOp()) :
527 template <
typename ExprT1>
529 std::negate<typename exprTraits<ExprT1>::ImagePixelT>,
533 std::negate<typename exprTraits<ExprT1>::ImagePixelT>,
540 template <
typename ExprT1,
typename ExprT2>
541 BinaryExpr<ExprT1, ExprT2,
542 std::plus<typename exprTraits<ExprT1>::ImagePixelT>,
543 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
546 std::plus<typename exprTraits<ExprT1>::ImagePixelT>,
552 template <
typename ExprT1,
typename ExprT2>
555 std::plus<typename exprTraits<ExprT1>::ImagePixelT>,
566 template <
typename ExprT1,
typename ExprT2>
567 ExprT1 doPlus(ExprT1 e1, ExprT2 e2,
573 template <
typename ExprT1,
typename ExprT2>
574 BinaryExpr<ExprT1, ExprT2,
575 std::plus<typename exprTraits<ExprT1>::ImagePixelT>,
576 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
577 variance_plus_covar<typename exprTraits<ExprT1>::VariancePixelT> > doPlus(ExprT1 e1, ExprT2 e2,
579 boost::mpl::false_) {
580 return BinaryExpr<ExprT1, ExprT2,
581 std::plus<typename exprTraits<ExprT1>::ImagePixelT>,
582 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
583 variance_plus_covar<typename exprTraits<ExprT1>::VariancePixelT> >(e1, e2,
alpha);
588 template<
typename ExprT1,
typename ExprT2>
589 inline ExprT1
plus(ExprT1& lhs,
593 return doPlus(lhs, rhs, covariance,
typename boost::is_arithmetic<ExprT1>::type());
598 template <
typename ExprT1,
typename ExprT2>
599 BinaryExpr<ExprT1, ExprT2,
600 std::minus<typename exprTraits<ExprT1>::ImagePixelT>,
601 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
604 std::minus<typename exprTraits<ExprT1>::ImagePixelT>,
610 template <
typename ExprT1,
typename ExprT2>
613 std::minus<typename exprTraits<ExprT1>::ImagePixelT>,
621 template <
typename ExprT1,
typename ExprT2>
622 BinaryExpr<ExprT1, ExprT2,
623 std::multiplies<typename exprTraits<ExprT1>::ImagePixelT>,
624 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
627 std::multiplies<typename exprTraits<ExprT1>::ImagePixelT>,
633 template <
typename ExprT1,
typename ExprT2>
636 std::multiplies<typename exprTraits<ExprT1>::ImagePixelT>,
644 template <
typename ExprT1,
typename ExprT2>
645 BinaryExpr<ExprT1, ExprT2,
646 std::divides<typename exprTraits<ExprT1>::ImagePixelT>,
647 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
650 std::divides<typename exprTraits<ExprT1>::ImagePixelT>,
656 template <
typename ExprT1,
typename ExprT2>
659 std::divides<typename exprTraits<ExprT1>::ImagePixelT>,
667 template<
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
668 std::ostream& operator<<(std::ostream &os, SinglePixel<ImagePixelT, MaskPixelT, VariancePixelT>
const& v) {
669 return os <<
"(" << v.image() <<
", " << v.mask() <<
", " << v.variance() <<
")";
673 template<
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
674 std::ostream& operator<<(std::ostream &os, Pixel<ImagePixelT, MaskPixelT, VariancePixelT>
const& v) {
675 return os <<
"(" << v.image() <<
", " << v.mask() <<
", " << v.variance() <<
")";
679 template <
typename ExprT1,
typename ExprT2,
typename BinOp,
typename MaskBinOp,
typename VarBinOp>
680 std::ostream& operator<<(std::ostream &os, BinaryExpr<ExprT1, ExprT2, BinOp, MaskBinOp, VarBinOp>
const& v) {
681 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)
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)
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
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. masks and variances when changing the sign of the image) ...
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