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>
92 ImagePixelT
image()
const {
return _image; }
93 MaskPixelT
mask()
const {
return _mask; }
94 VariancePixelT
variance()
const {
return _variance; }
112 VariancePixelT _variance;
116 template <
typename PixelT>
125 template <
typename _ImagePixelT,
typename _MaskPixelT,
typename _VariancePixelT>
130 static inline const PixelT
padValue() {
return PixelT(); }
138 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
145 template <
typename _ImagePixelT,
typename _MaskPixelT,
typename _VariancePixelT =
double>
155 _image(image), _mask(mask), _variance(variance) {}
161 : _image(const_cast<ImagePixelT&>(image)),
162 _mask(const_cast<MaskPixelT&>(
mask)),
163 _variance(const_cast<VariancePixelT&>(
variance)) {}
167 : _image(rhs._image), _mask(rhs._mask), _variance(rhs._variance) {}
176 _image = rhs.
image();
186 template <
typename rhsExpr>
189 _image = rhs.image();
215 ImagePixelT
image()
const {
return _image; }
217 MaskPixelT
mask()
const {
return _mask; }
219 VariancePixelT
variance()
const {
return _variance; }
225 template <
typename T1>
227 return lhs.
image() == rhs.image() && lhs.
mask() == rhs.mask() && lhs.
variance() == rhs.variance();
231 template <
typename T1>
233 return !(lhs == rhs);
240 template <
typename ExprT>
249 template <
typename ExprT>
258 template <
typename ExprT>
267 template <
typename ExprT>
278 VariancePixelT& _variance;
282 template <
typename ExprT>
327 template <
typename T1>
337 template <
typename T1>
348 template <
typename T1>
350 T1
operator()(T1
const&
x, T1
const&
y, T1
const& vx, T1
const& vy)
const {
353 T1
const iy2 = 1.0 / y2;
354 return x2 * vy * iy2 * iy2 + vx * iy2;
357 T1
operator()(T1
const&, T1
const&
y, T1
const& vx)
const {
return vx / (y *
y); }
365 template <
typename T1>
367 T1
operator()(T1
const&
x, T1
const&
y, T1
const& vx, T1
const& vy)
const {
370 return x2 * vy + y2 * vx;
373 T1
operator()(T1
const&, T1
const&
y, T1
const& vx)
const {
return vx * y *
y; }
381 template <
typename T1>
383 T1
operator()(T1
const&, T1
const&, T1
const& vx, T1
const& vy)
const {
return vx + vy; }
385 T1
operator()(T1
const&, T1
const&, T1
const& vx)
const {
return vx; }
395 template <
typename T1>
399 T1
operator()(T1
const&, T1
const&, T1
const& vx, T1
const& vy)
const {
400 return vx + vy + 2 * _alpha * sqrt(vx * vy);
402 T1
operator()(T1
const&, T1
const&, T1
const& vx)
const {
return vx; }
409 template <
typename ExprT1,
typename ImageBinOp,
typename MaskBinOp,
typename VarianceBinOp>
416 UnaryExpr(ExprT1 e1, ImageBinOp imageOp = ImageBinOp(), MaskBinOp maskOp = MaskBinOp(),
417 VarianceBinOp varOp = VarianceBinOp())
418 : _expr1(e1), _imageOp(imageOp), _maskOp(maskOp), _varOp(varOp) {}
421 ImagePixelT
image()
const {
return _imageOp(_expr1.image()); }
424 MaskPixelT
mask()
const {
return _maskOp(_expr1.mask()); }
427 VariancePixelT
variance()
const {
return _varOp(_expr1.variance()); }
433 VarianceBinOp _varOp;
437 template <
typename ExprT1,
typename ExprT2,
typename ImageBinOp,
typename MaskBinOp,
typename VarianceBinOp>
444 BinaryExpr(ExprT1 e1, ExprT2 e2, ImageBinOp imageOp = ImageBinOp(), MaskBinOp maskOp = MaskBinOp(),
445 VarianceBinOp varOp = VarianceBinOp())
446 : _expr1(e1), _expr2(e2), _imageOp(imageOp), _maskOp(maskOp), _varOp(varOp) {}
450 BinaryExpr(ExprT1 e1, ExprT2 e2,
double const alpha, ImageBinOp imageOp = ImageBinOp(),
451 MaskBinOp maskOp = MaskBinOp(), VarianceBinOp = VarianceBinOp())
452 : _expr1(e1), _expr2(e2), _imageOp(imageOp), _maskOp(maskOp), _varOp(VarianceBinOp(alpha)) {}
454 ImagePixelT
image()
const {
return _imageOp(_expr1.image(), _expr2.image()); }
457 MaskPixelT
mask()
const {
return _maskOp(_expr1.mask(), _expr2.mask()); }
461 return _varOp(_expr1.image(), _expr2.image(), _expr1.variance(), _expr2.variance());
469 VarianceBinOp _varOp;
476 template <
typename ExprT1,
typename ImageBinOp,
typename MaskBinOp,
typename VarianceBinOp>
477 class BinaryExpr<ExprT1, double, ImageBinOp, MaskBinOp, VarianceBinOp> final {
483 BinaryExpr(ExprT1 e1,
double e2, ImageBinOp imageOp = ImageBinOp(), MaskBinOp maskOp = MaskBinOp(),
484 VarianceBinOp varOp = VarianceBinOp())
485 : _expr1(e1), _expr2(e2), _imageOp(imageOp), _maskOp(maskOp), _varOp(varOp) {}
489 BinaryExpr(ExprT1 e1,
double e2,
double const alpha, ImageBinOp imageOp = ImageBinOp(),
490 MaskBinOp maskOp = MaskBinOp(), VarianceBinOp = VarianceBinOp())
491 : _expr1(e1), _expr2(e2), _imageOp(imageOp), _maskOp(maskOp), _varOp(VarianceBinOp(alpha)) {}
493 ImagePixelT
image()
const {
return _imageOp(_expr1.image(), _expr2); }
496 MaskPixelT
mask()
const {
return _maskOp(_expr1.mask()); }
499 VariancePixelT
variance()
const {
return _varOp(_expr1.image(), _expr2, _expr1.variance()); }
506 VarianceBinOp _varOp;
510 template <
typename ExprT1>
515 noop<typename exprTraits<ExprT1>::MaskPixelT>,
521 template <
typename ExprT1,
typename ExprT2>
526 return BinaryExpr<ExprT1, ExprT2, std::plus<typename exprTraits<ExprT1>::ImagePixelT>,
527 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
532 template <
typename ExprT1,
typename ExprT2>
534 e1 = BinaryExpr<ExprT1, ExprT2, std::plus<typename exprTraits<ExprT1>::ImagePixelT>,
535 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
545 template <
typename ExprT1,
typename ExprT2>
546 ExprT1 doPlus(ExprT1 e1, ExprT2 e2,
double const, boost::mpl::true_) {
550 template <
typename ExprT1,
typename ExprT2>
551 BinaryExpr<ExprT1, ExprT2, std::plus<typename exprTraits<ExprT1>::ImagePixelT>,
552 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
554 doPlus(ExprT1 e1, ExprT2 e2,
double const alpha, boost::mpl::false_) {
555 return BinaryExpr<ExprT1, ExprT2, std::plus<typename exprTraits<ExprT1>::ImagePixelT>,
556 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
562 template <
typename ExprT1,
typename ExprT2>
573 template <
typename ExprT1,
typename ExprT2>
575 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
579 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
584 template <
typename ExprT1,
typename ExprT2>
587 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
594 template <
typename ExprT1,
typename ExprT2>
596 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
600 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
605 template <
typename ExprT1,
typename ExprT2>
608 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
615 template <
typename ExprT1,
typename ExprT2>
617 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
621 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
626 template <
typename ExprT1,
typename ExprT2>
629 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
635 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
636 std::ostream& operator<<(std::ostream& os, SinglePixel<ImagePixelT, MaskPixelT, VariancePixelT>
const& v) {
637 return os <<
"(" << v.image() <<
", " << v.mask() <<
", " << v.variance() <<
")";
641 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
642 std::ostream& operator<<(std::ostream& os, Pixel<ImagePixelT, MaskPixelT, VariancePixelT>
const& v) {
643 return os <<
"(" << v.image() <<
", " << v.mask() <<
", " << v.variance() <<
")";
647 template <
typename ExprT1,
typename ExprT2,
typename BinOp,
typename MaskBinOp,
typename VarBinOp>
648 std::ostream& operator<<(std::ostream& os, BinaryExpr<ExprT1, ExprT2, BinOp, MaskBinOp, VarBinOp>
const& v) {
649 return os <<
"(" << v.image() <<
", " << v.mask() <<
", " << v.variance() <<
")";
MaskPixelT mask() const
evaluate the mask part of the expression
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)
VariancePixelT variance() const
Return the variance part of a Pixel.
SinglePixel< ImagePixelT, MaskPixelT, VariancePixelT > expr_type
ImagePixelT image() const
evaluate the image part of the expression
exprTraits< ExprT1 >::VariancePixelT VariancePixelT
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.
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 &, 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.
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) ...
VariancePixelT variance() const
SinglePixel< ImagePixelT, MaskPixelT, VariancePixelT > expr_type
MaskPixelT mask() const
evaluate the mask part of the expression
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.
T1 operator()(const T1 &x) const
T1 operator()(T1 const &x, T1 const &y, T1 const &vx, T1 const &vy) const
Pixel operator=(Pixel &&rhs)
ExprT::ImagePixelT ImagePixelT
A single pixel of the same type as a MaskedImage.
T1 operator()(T1 const &, T1 const &, T1 const &vx) const
T1 operator()(T1 const &x, T1 const &y, T1 const &vx, T1 const &vy) const
exprTraits< ExprT1 >::MaskPixelT MaskPixelT
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 ...
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)
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 ...
ImagePixelT image() const
static const PixelT padValue()
The quantity to use when a pixel value is undefined.
ExprT::MaskPixelT MaskPixelT
SinglePixel< ImagePixelT, MaskPixelT, VariancePixelT > expr_type
exprTraits< double >::MaskPixelT MaskPixelT
A base class for image defects.
Calculate the variance when we divide two Pixels.
T1 operator()(T1 const &, T1 const &y, T1 const &vx) const
SinglePixel(rhsExpr const &rhs, typename std::enable_if<!std::is_fundamental< rhsExpr >::value, void *>::type dummy=nullptr)
variance_plus_covar(double alpha=0)
T1 operator()(T1 const &, T1 const &, T1 const &vx, T1 const &vy) const
MaskPixelT mask() const
Return the mask part of a Pixel.
ExprT1 plus(ExprT1 &lhs, ExprT2 const &rhs, float covariance)
Like operator+(), but assume that covariance's 2*alpha*sqrt(vx*vy)
T1 operator()(const T1 &x) const
ImagePixelT image() const
Return the image part of a Pixel.
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.
exprTraits< ExprT1 >::MaskPixelT MaskPixelT
ExprT1 operator*=(ExprT1 &e1, ExprT2 e2)
Template to evaluate e1 *= e2.
ExprT1 operator/=(ExprT1 &e1, ExprT2 e2)
Template to evaluate e1 /= e2.
T1 operator()(T1 const &, T1 const &y, T1 const &vx) const
_VariancePixelT VariancePixelT
VariancePixelT variance() const
evaluate the variance part of the expression
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
friend Pixel operator*=(Pixel const &e1, ExprT const &e2)
Evaluate e1 *= e2, and return e1.
exprTraits< ExprT1 >::ImagePixelT ImagePixelT
VariancePixelT variance() const
evaluate the variance part of the expression
VariancePixelT variance() const
evaluate the variance part of the expression
exprTraits< double >::VariancePixelT VariancePixelT
Pixel operator=(Pixel const &rhs)
T1 operator()(const T1 &x, const T1 &y) const
A traits class to return the types of the image/mask/variance.
exprTraits< ExprT1 >::MaskPixelT MaskPixelT
table::PointKey< int > pixel
exprTraits< ExprT1 >::ImagePixelT ImagePixelT
ImagePixelT image() const
evaluate the image part of the expression
T1 operator()(T1 const &, T1 const &, T1 const &vx, T1 const &vy) const
SinglePixel< _ImagePixelT, _MaskPixelT, _VariancePixelT > PixelT
Pixel(SinglePixel< ImagePixelT, MaskPixelT, VariancePixelT > &rhs)
ImagePixelT image() const
evaluate the image part of the expression
MaskPixelT mask() const
evaluate the mask part of the expression
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.
ExprT::VariancePixelT VariancePixelT
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< ExprT1 >::VariancePixelT VariancePixelT
exprTraits< double >::VariancePixelT VariancePixelT
_VariancePixelT VariancePixelT
friend Pixel operator+=(Pixel const &e1, ExprT const &e2)
Evaluate e1 += e2, and return e1.