23 #if !defined(LSST_AFW_IMAGE_PIXEL_H)
24 #define LSST_AFW_IMAGE_PIXEL_H
29 #include <type_traits>
36 template <
typename,
typename,
typename,
typename,
typename>
70 template <
typename _ImagePixelT,
typename _MaskPixelT,
typename _VariancePixelT =
double>
73 template <
typename,
typename,
typename>
85 template <
typename rhsExpr>
89 typename std::enable_if<!std::is_fundamental<rhsExpr>::value,
void*>::type dummy =
nullptr)
102 : _image(std::numeric_limits<_ImagePixelT>::has_quiet_NaN
103 ? std::numeric_limits<_ImagePixelT>::quiet_NaN()
106 _variance(std::numeric_limits<_VariancePixelT>::has_quiet_NaN
107 ? std::numeric_limits<_VariancePixelT>::quiet_NaN()
116 template <
typename PixelT>
120 return std::numeric_limits<PixelT>::has_quiet_NaN ? std::numeric_limits<PixelT>::quiet_NaN() : 0;
125 template <
typename _ImagePixelT,
typename _MaskPixelT,
typename _VariancePixelT>
138 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
145 template <
typename _ImagePixelT,
typename _MaskPixelT,
typename _VariancePixelT =
double>
155 _image(image), _mask(mask), _variance(variance) {}
167 : _image(rhs._image), _mask(rhs._mask), _variance(rhs._variance) {}
172 _image = rhs.
image();
182 template <
typename rhsExpr>
184 _variance = rhs.variance();
185 _image = rhs.image();
219 template <
typename T1>
221 return lhs.
image() == rhs.image() && lhs.
mask() == rhs.mask() && lhs.
variance() == rhs.variance();
225 template <
typename T1>
227 return !(lhs == rhs);
234 template <
typename ExprT>
243 template <
typename ExprT>
252 template <
typename ExprT>
261 template <
typename ExprT>
276 template <
typename ExprT>
321 template <
typename T1>
322 struct noop :
public std::unary_function<T1, T1> {
331 template <
typename T1>
332 struct bitwise_or :
public std::binary_function<T1, T1, T1> {
342 template <
typename T1>
343 struct variance_divides {
344 T1
operator()(T1
const&
x, T1
const& y, T1
const& vx, T1
const& vy)
const {
347 T1
const iy2 = 1.0 / y2;
348 return x2 * vy * iy2 * iy2 + vx * iy2;
351 T1
operator()(T1
const&, T1
const& y, T1
const& vx)
const {
return vx / (y * y); }
359 template <
typename T1>
360 struct variance_multiplies {
361 T1
operator()(T1
const&
x, T1
const& y, T1
const& vx, T1
const& vy)
const {
364 return x2 * vy + y2 * vx;
367 T1
operator()(T1
const&, T1
const& y, T1
const& vx)
const {
return vx * y * y; }
375 template <
typename T1>
376 struct variance_plus {
377 T1
operator()(T1
const&, T1
const&, T1
const& vx, T1
const& vy)
const {
return vx + vy; }
379 T1
operator()(T1
const&, T1
const&, T1
const& vx)
const {
return vx; }
389 template <
typename T1>
393 T1
operator()(T1
const&, T1
const&, T1
const& vx, T1
const& vy)
const {
394 return vx + vy + 2 * _alpha * sqrt(vx * vy);
396 T1
operator()(T1
const&, T1
const&, T1
const& vx)
const {
return vx; }
403 template <
typename ExprT1,
typename ImageBinOp,
typename MaskBinOp,
typename VarianceBinOp>
410 UnaryExpr(ExprT1 e1, ImageBinOp imageOp = ImageBinOp(), MaskBinOp maskOp = MaskBinOp(),
411 VarianceBinOp varOp = VarianceBinOp())
412 : _expr1(e1), _imageOp(imageOp), _maskOp(maskOp), _varOp(varOp) {}
427 VarianceBinOp _varOp;
431 template <
typename ExprT1,
typename ExprT2,
typename ImageBinOp,
typename MaskBinOp,
typename VarianceBinOp>
438 BinaryExpr(ExprT1 e1, ExprT2 e2, ImageBinOp imageOp = ImageBinOp(), MaskBinOp maskOp = MaskBinOp(),
439 VarianceBinOp varOp = VarianceBinOp())
440 : _expr1(e1), _expr2(e2), _imageOp(imageOp), _maskOp(maskOp), _varOp(varOp) {}
444 BinaryExpr(ExprT1 e1, ExprT2 e2,
double const alpha, ImageBinOp imageOp = ImageBinOp(),
445 MaskBinOp maskOp = MaskBinOp(), VarianceBinOp = VarianceBinOp())
446 : _expr1(e1), _expr2(e2), _imageOp(imageOp), _maskOp(maskOp), _varOp(VarianceBinOp(alpha)) {}
455 return _varOp(_expr1.image(), _expr2.image(), _expr1.variance(), _expr2.variance());
463 VarianceBinOp _varOp;
470 template <
typename ExprT1,
typename ImageBinOp,
typename MaskBinOp,
typename VarianceBinOp>
471 class BinaryExpr<ExprT1, double, ImageBinOp, MaskBinOp, VarianceBinOp> {
477 BinaryExpr(ExprT1 e1,
double e2, ImageBinOp imageOp = ImageBinOp(), MaskBinOp maskOp = MaskBinOp(),
478 VarianceBinOp varOp = VarianceBinOp())
479 : _expr1(e1), _expr2(e2), _imageOp(imageOp), _maskOp(maskOp), _varOp(varOp) {}
483 BinaryExpr(ExprT1 e1,
double e2,
double const alpha, ImageBinOp imageOp = ImageBinOp(),
484 MaskBinOp maskOp = MaskBinOp(), VarianceBinOp = VarianceBinOp())
485 : _expr1(e1), _expr2(e2), _imageOp(imageOp), _maskOp(maskOp), _varOp(VarianceBinOp(alpha)) {}
500 VarianceBinOp _varOp;
504 template <
typename ExprT1>
505 UnaryExpr<ExprT1, std::negate<typename exprTraits<ExprT1>::ImagePixelT>,
506 noop<typename exprTraits<ExprT1>::MaskPixelT>, noop<typename exprTraits<ExprT1>::VariancePixelT> >
515 template <
typename ExprT1,
typename ExprT2>
516 BinaryExpr<ExprT1, ExprT2, std::plus<typename exprTraits<ExprT1>::ImagePixelT>,
517 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
518 variance_plus<typename exprTraits<ExprT1>::VariancePixelT> >
526 template <
typename ExprT1,
typename ExprT2>
539 template <
typename ExprT1,
typename ExprT2>
540 ExprT1 doPlus(ExprT1 e1, ExprT2 e2,
double const, boost::mpl::true_) {
544 template <
typename ExprT1,
typename ExprT2>
545 BinaryExpr<ExprT1, ExprT2, std::plus<typename exprTraits<ExprT1>::ImagePixelT>,
546 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
547 variance_plus_covar<typename exprTraits<ExprT1>::VariancePixelT> >
548 doPlus(ExprT1 e1, ExprT2 e2,
double const alpha, boost::mpl::false_) {
549 return BinaryExpr<ExprT1, ExprT2, std::plus<typename exprTraits<ExprT1>::ImagePixelT>,
550 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
551 variance_plus_covar<typename exprTraits<ExprT1>::VariancePixelT> >(e1, e2, alpha);
556 template <
typename ExprT1,
typename ExprT2>
562 return doPlus(lhs, rhs, covariance,
typename std::is_arithmetic<ExprT1>::type());
567 template <
typename ExprT1,
typename ExprT2>
568 BinaryExpr<ExprT1, ExprT2, std::minus<typename exprTraits<ExprT1>::ImagePixelT>,
569 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
570 variance_plus<typename exprTraits<ExprT1>::VariancePixelT> >
578 template <
typename ExprT1,
typename ExprT2>
588 template <
typename ExprT1,
typename ExprT2>
589 BinaryExpr<ExprT1, ExprT2, std::multiplies<typename exprTraits<ExprT1>::ImagePixelT>,
590 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
591 variance_multiplies<typename exprTraits<ExprT1>::VariancePixelT> >
599 template <
typename ExprT1,
typename ExprT2>
609 template <
typename ExprT1,
typename ExprT2>
610 BinaryExpr<ExprT1, ExprT2, std::divides<typename exprTraits<ExprT1>::ImagePixelT>,
611 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
612 variance_divides<typename exprTraits<ExprT1>::VariancePixelT> >
620 template <
typename ExprT1,
typename ExprT2>
629 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
630 std::ostream& operator<<(std::ostream& os, SinglePixel<ImagePixelT, MaskPixelT, VariancePixelT>
const& v) {
631 return os <<
"(" << v.image() <<
", " << v.mask() <<
", " << v.variance() <<
")";
635 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
636 std::ostream& operator<<(std::ostream& os, Pixel<ImagePixelT, MaskPixelT, VariancePixelT>
const& v) {
637 return os <<
"(" << v.image() <<
", " << v.mask() <<
", " << v.variance() <<
")";
641 template <
typename ExprT1,
typename ExprT2,
typename BinOp,
typename MaskBinOp,
typename VarBinOp>
642 std::ostream& operator<<(std::ostream& os, BinaryExpr<ExprT1, ExprT2, BinOp, MaskBinOp, VarBinOp>
const& v) {
643 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) ...
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.
ImagePixelT image() const
evaluate the image part of the expression
exprTraits< ExprT1 >::MaskPixelT MaskPixelT
SinglePixel(rhsExpr const &rhs, typename std::enable_if<!std::is_fundamental< rhsExpr >::value, void * >::type dummy=nullptr)
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
MaskPixelT mask() const
evaluate the mask part of the expression
exprTraits< ExprT1 >::VariancePixelT VariancePixelT
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
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.
SinglePixel(ImagePixelT image, MaskPixelT mask=0, VariancePixelT variance=0)
exprTraits< double >::VariancePixelT VariancePixelT
The variance of the sum of a pair of correlated pixels.
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
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
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.
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