LSSTApplications
20.0.0
LSSTDataManagementBasePackage
|
Go to the documentation of this file.
23 #if !defined(LSST_AFW_IMAGE_PIXEL_H)
24 #define LSST_AFW_IMAGE_PIXEL_H
29 #include <type_traits>
38 template <
typename,
typename,
typename,
typename,
typename>
72 template <
typename _ImagePixelT,
typename _MaskPixelT,
typename _VariancePixelT =
double>
75 template <
typename,
typename,
typename>
87 template <
typename rhsExpr>
104 : _image(
std::numeric_limits<_ImagePixelT>::has_quiet_NaN
105 ?
std::numeric_limits<_ImagePixelT>::quiet_NaN()
108 _variance(
std::numeric_limits<_VariancePixelT>::has_quiet_NaN
109 ?
std::numeric_limits<_VariancePixelT>::quiet_NaN()
118 template <
typename PixelT>
127 template <
typename _ImagePixelT,
typename _MaskPixelT,
typename _VariancePixelT>
140 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
147 template <
typename _ImagePixelT,
typename _MaskPixelT,
typename _VariancePixelT =
double>
169 : _image(rhs._image), _mask(rhs._mask), _variance(rhs._variance) {}
178 _image = rhs.
image();
188 template <
typename rhsExpr>
190 _variance = rhs.variance();
191 _image = rhs.image();
227 template <
typename T1>
229 return lhs.
image() == rhs.image() && lhs.
mask() == rhs.mask() && lhs.
variance() == rhs.variance();
233 template <
typename T1>
235 return !(lhs == rhs);
250 template <
typename ExprT>
259 template <
typename ExprT>
268 template <
typename ExprT>
277 template <
typename ExprT>
292 template <
typename ExprT>
337 template <
typename T1>
347 template <
typename T1>
358 template <
typename T1>
359 struct variance_divides {
360 T1
operator()(T1
const&
x, T1
const&
y, T1
const& vx, T1
const& vy)
const {
363 T1
const iy2 = 1.0 / y2;
364 return x2 * vy * iy2 * iy2 + vx * iy2;
367 T1
operator()(T1
const&, T1
const&
y, T1
const& vx)
const {
return vx / (
y *
y); }
375 template <
typename T1>
376 struct variance_multiplies {
377 T1
operator()(T1
const&
x, T1
const&
y, T1
const& vx, T1
const& vy)
const {
380 return x2 * vy + y2 * vx;
383 T1
operator()(T1
const&, T1
const&
y, T1
const& vx)
const {
return vx *
y *
y; }
391 template <
typename T1>
392 struct variance_plus {
393 T1
operator()(T1
const&, T1
const&, T1
const& vx, T1
const& vy)
const {
return vx + vy; }
395 T1
operator()(T1
const&, T1
const&, T1
const& vx)
const {
return vx; }
405 template <
typename T1>
409 T1
operator()(T1
const&, T1
const&, T1
const& vx, T1
const& vy)
const {
410 return vx + vy + 2 * _alpha * sqrt(vx * vy);
412 T1
operator()(T1
const&, T1
const&, T1
const& vx)
const {
return vx; }
419 template <
typename ExprT1,
typename ImageBinOp,
typename MaskBinOp,
typename VarianceBinOp>
426 UnaryExpr(ExprT1 e1, ImageBinOp imageOp = ImageBinOp(), MaskBinOp maskOp = MaskBinOp(),
427 VarianceBinOp varOp = VarianceBinOp())
428 : _expr1(e1), _imageOp(imageOp), _maskOp(maskOp), _varOp(varOp) {}
443 VarianceBinOp _varOp;
447 template <
typename ExprT1,
typename ExprT2,
typename ImageBinOp,
typename MaskBinOp,
typename VarianceBinOp>
448 class BinaryExpr final {
454 BinaryExpr(ExprT1 e1, ExprT2 e2, ImageBinOp imageOp = ImageBinOp(), MaskBinOp maskOp = MaskBinOp(),
455 VarianceBinOp varOp = VarianceBinOp())
456 : _expr1(e1), _expr2(e2), _imageOp(imageOp), _maskOp(maskOp), _varOp(varOp) {}
460 BinaryExpr(ExprT1 e1, ExprT2 e2,
double const alpha, ImageBinOp imageOp = ImageBinOp(),
461 MaskBinOp maskOp = MaskBinOp(), VarianceBinOp = VarianceBinOp())
462 : _expr1(e1), _expr2(e2), _imageOp(imageOp), _maskOp(maskOp), _varOp(VarianceBinOp(alpha)) {}
471 return _varOp(_expr1.image(), _expr2.image(), _expr1.variance(), _expr2.variance());
479 VarianceBinOp _varOp;
486 template <
typename ExprT1,
typename ImageBinOp,
typename MaskBinOp,
typename VarianceBinOp>
487 class BinaryExpr<ExprT1, double, ImageBinOp, MaskBinOp, VarianceBinOp> final {
493 BinaryExpr(ExprT1 e1,
double e2, ImageBinOp imageOp = ImageBinOp(), MaskBinOp maskOp = MaskBinOp(),
494 VarianceBinOp varOp = VarianceBinOp())
495 : _expr1(e1), _expr2(e2), _imageOp(imageOp), _maskOp(maskOp), _varOp(varOp) {}
499 BinaryExpr(ExprT1 e1,
double e2,
double const alpha, ImageBinOp imageOp = ImageBinOp(),
500 MaskBinOp maskOp = MaskBinOp(), VarianceBinOp = VarianceBinOp())
501 : _expr1(e1), _expr2(e2), _imageOp(imageOp), _maskOp(maskOp), _varOp(VarianceBinOp(alpha)) {}
516 VarianceBinOp _varOp;
520 template <
typename ExprT1>
522 noop<typename exprTraits<ExprT1>::MaskPixelT>, noop<typename exprTraits<ExprT1>::VariancePixelT> >
531 template <
typename ExprT1,
typename ExprT2>
533 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
534 variance_plus<typename exprTraits<ExprT1>::VariancePixelT> >
542 template <
typename ExprT1,
typename ExprT2>
555 template <
typename ExprT1,
typename ExprT2>
556 ExprT1 doPlus(ExprT1 e1, ExprT2 e2,
double const, boost::mpl::true_) {
560 template <
typename ExprT1,
typename ExprT2>
562 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
563 variance_plus_covar<typename exprTraits<ExprT1>::VariancePixelT> >
564 doPlus(ExprT1 e1, ExprT2 e2,
double const alpha, boost::mpl::false_) {
566 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
567 variance_plus_covar<typename exprTraits<ExprT1>::VariancePixelT> >(e1, e2, alpha);
572 template <
typename ExprT1,
typename ExprT2>
583 template <
typename ExprT1,
typename ExprT2>
585 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
586 variance_plus<typename exprTraits<ExprT1>::VariancePixelT> >
594 template <
typename ExprT1,
typename ExprT2>
604 template <
typename ExprT1,
typename ExprT2>
606 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
607 variance_multiplies<typename exprTraits<ExprT1>::VariancePixelT> >
615 template <
typename ExprT1,
typename ExprT2>
625 template <
typename ExprT1,
typename ExprT2>
627 bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
628 variance_divides<typename exprTraits<ExprT1>::VariancePixelT> >
636 template <
typename ExprT1,
typename ExprT2>
645 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
651 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
657 template <
typename ExprT1,
typename ExprT2,
typename BinOp,
typename MaskBinOp,
typename VarBinOp>
659 return os <<
"(" << v.image() <<
", " << v.mask() <<
", " << v.variance() <<
")";
667 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
679 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
680 struct hash<
lsst::afw::image::pixel::SinglePixel<ImagePixelT, MaskPixelT, VariancePixelT>> {
688 MaskPixelT
mask = obj.mask();
689 VariancePixelT
variance = obj.variance();
friend bool operator==(Pixel const &lhs, T1 const &rhs)
Return true iff two pixels are equal (in all three of image, mask, and variance)
Pixel operator=(int const &rhs_image)
set the image part of a Pixel to rhs_image (the mask and variance are set to 0)
MaskPixelT mask() const
Return the mask part of a Pixel.
Class for representing Unary operations.
exprTraits< double >::MaskPixelT MaskPixelT
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)
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
SinglePixel< ImagePixelT, MaskPixelT, VariancePixelT > expr_type
SinglePixel(ImagePixelT image, MaskPixelT mask=0, VariancePixelT variance=0)
size_t operator()(argument_type const &obj) const noexcept
exprTraits< ExprT1 >::ImagePixelT ImagePixelT
T1 operator()(const T1 &x, const T1 &y) const
Pixel(Pixel const &rhs)=default
VariancePixelT variance() const
evaluate the variance part of the expression
T1 operator()(const T1 &x) const
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)
A pixel of a MaskedImage.
bitwise_or doesn't seem to be in std::
SinglePixel< ImagePixelT, MaskPixelT, VariancePixelT > expr_type
T1 operator()(const T1 &x) const
ExprT1 operator*=(ExprT1 &e1, ExprT2 e2)
Template to evaluate e1 *= e2.
A single pixel of the same type as a MaskedImage.
VariancePixelT variance() const
evaluate the variance part of the expression
float Pixel
Typedefs to be used for pixel values.
A noop functor (useful for e.g. masks and variances when changing the sign of the image)
T1 operator()(T1 const &, T1 const &, T1 const &vx) const
std::size_t hash_value() const noexcept
Return a hash of this object.
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.
ExprT::VariancePixelT VariancePixelT
_VariancePixelT VariancePixelT
friend Pixel operator+=(Pixel const &e1, ExprT const &e2)
Evaluate e1 += e2, and return e1.
friend Pixel operator*=(Pixel const &e1, ExprT const &e2)
Evaluate e1 *= e2, and return e1.
Pixel operator=(double const &rhs_image)
set the image part of a Pixel to rhs_image (the mask and variance are set to 0)
static const PixelT padValue()
The quantity to use when a pixel value is undefined.
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 ...
exprTraits< double >::MaskPixelT MaskPixelT
Pixel operator=(rhsExpr const &rhs)
Assign a Pixel by evaluating an expression.
T1 operator()(T1 const &x, T1 const &y, T1 const &vx, T1 const &vy) const
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 ...
VariancePixelT variance() const
Return the variance part of a Pixel.
ExprT::MaskPixelT MaskPixelT
MaskPixelT mask() const
evaluate the mask part of the expression
Pixel operator=(Pixel const &rhs)
exprTraits< ExprT1 >::VariancePixelT VariancePixelT
exprTraits< ExprT1 >::MaskPixelT MaskPixelT
Pixel(SinglePixel< ImagePixelT, MaskPixelT, VariancePixelT > &rhs)
ExprT1 operator+=(ExprT1 &e1, ExprT2 e2)
template for e1 += e2
UnaryExpr< ExprT1, std::negate< typename exprTraits< ExprT1 >::ImagePixelT >, noop< typename exprTraits< ExprT1 >::MaskPixelT >, noop< typename exprTraits< ExprT1 >::VariancePixelT > > operator-(ExprT1 e1)
Template for -e1.
exprTraits< ExprT1 >::ImagePixelT ImagePixelT
T1 operator()(T1 const &, T1 const &, T1 const &vx) const
ExprT1 operator-=(ExprT1 &e1, ExprT2 e2)
Template to evaluate e1 -= e2.
friend Pixel operator-=(Pixel const &e1, ExprT const &e2)
Evaluate e1 -= e2, and return e1.
std::ostream & operator<<(std::ostream &os, SinglePixel< ImagePixelT, MaskPixelT, VariancePixelT > const &v)
Print a SinglePixel.
MaskPixelT mask() const
evaluate the mask part of the expression
Calculate the variance when we add (or subtract) two Pixels.
size_t operator()(argument_type const &obj) const noexcept
SinglePixel< ImagePixelT, MaskPixelT, VariancePixelT > makeSinglePixel(ImagePixelT x, MaskPixelT m, VariancePixelT v)
Return a SinglePixel.
VariancePixelT variance() const
evaluate the variance part of the expression
Class for representing binary operations.
exprTraits< ExprT1 >::MaskPixelT MaskPixelT
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(Pixel &&rhs)=default
A class used to identify classes that represent MaskedImage pixels.
exprTraits< double >::VariancePixelT VariancePixelT
Calculate the variance when we divide two Pixels.
Pixel operator=(Pixel &&rhs)
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.
exprTraits< ExprT1 >::MaskPixelT MaskPixelT
SinglePixel< ImagePixelT, MaskPixelT, VariancePixelT > expr_type
exprTraits< ExprT1 >::VariancePixelT VariancePixelT
T1 operator()(T1 const &, T1 const &, T1 const &vx, T1 const &vy) const
table::PointKey< int > pixel
exprTraits< double >::VariancePixelT VariancePixelT
A base class for image defects.
ImagePixelT image() const
evaluate the image part of the expression
T1 operator()(T1 const &x, T1 const &y, T1 const &vx, T1 const &vy) const
ImagePixelT image() const
evaluate the image part of the expression
MaskPixelT mask() const
evaluate the mask part of the expression
std::size_t hashCombine(std::size_t seed) noexcept
Combine hashes.
ImagePixelT image() const
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)
T1 operator()(T1 const &, T1 const &, T1 const &vx, T1 const &vy) const
Calculate the variance when we multiply two Pixels.
variance_plus_covar(double alpha=0)
_VariancePixelT VariancePixelT
exprTraits< double >::VariancePixelT VariancePixelT
T1 operator()(T1 const &, T1 const &y, T1 const &vx) 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
evaluate the image part of the expression
VariancePixelT variance() const
ExprT::ImagePixelT ImagePixelT
exprTraits< double >::MaskPixelT MaskPixelT
ExprT1 operator/=(ExprT1 &e1, ExprT2 e2)
Template to evaluate e1 /= e2.
A traits class to return the types of the image/mask/variance.
T1 operator()(T1 const &, T1 const &y, T1 const &vx) const
exprTraits< ExprT1 >::ImagePixelT ImagePixelT
friend Pixel operator/=(Pixel const &e1, ExprT const &e2)
Evaluate e1 /= e2, and return e1.
SinglePixel< _ImagePixelT, _MaskPixelT, _VariancePixelT > PixelT
The variance of the sum of a pair of correlated pixels.
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
SinglePixel(rhsExpr const &rhs, typename std::enable_if<!std::is_fundamental< rhsExpr >::value, void * >::type dummy=nullptr)
exprTraits< ExprT1 >::VariancePixelT VariancePixelT
ImagePixelT image() const
Return the image part of a Pixel.
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.