LSSTApplications  18.0.0+106,18.0.0+50,19.0.0,19.0.0+1,19.0.0+10,19.0.0+11,19.0.0+13,19.0.0+17,19.0.0+2,19.0.0-1-g20d9b18+6,19.0.0-1-g425ff20,19.0.0-1-g5549ca4,19.0.0-1-g580fafe+6,19.0.0-1-g6fe20d0+1,19.0.0-1-g7011481+9,19.0.0-1-g8c57eb9+6,19.0.0-1-gb5175dc+11,19.0.0-1-gdc0e4a7+9,19.0.0-1-ge272bc4+6,19.0.0-1-ge3aa853,19.0.0-10-g448f008b,19.0.0-12-g6990b2c,19.0.0-2-g0d9f9cd+11,19.0.0-2-g3d9e4fb2+11,19.0.0-2-g5037de4,19.0.0-2-gb96a1c4+3,19.0.0-2-gd955cfd+15,19.0.0-3-g2d13df8,19.0.0-3-g6f3c7dc,19.0.0-4-g725f80e+11,19.0.0-4-ga671dab3b+1,19.0.0-4-gad373c5+3,19.0.0-5-ga2acb9c+2,19.0.0-5-gfe96e6c+2,w.2020.01
LSSTDataManagementBasePackage
Pixel.h
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2008-2016 AURA/LSST.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <http://www.lsstcorp.org/LegalNotices/>.
21  */
22 
23 #if !defined(LSST_AFW_IMAGE_PIXEL_H)
24 #define LSST_AFW_IMAGE_PIXEL_H
25 
26 #include <cmath>
27 #include <functional>
28 #include <iostream>
29 #include <type_traits>
30 
31 #include "lsst/utils/hashCombine.h"
32 
33 namespace lsst {
34 namespace afw {
35 namespace image {
36 namespace pixel {
37 
38 template <typename, typename, typename, typename, typename>
39 class BinaryExpr;
40 
41 template <typename>
42 struct exprTraits;
43 
44 template <typename>
45 struct bitwise_or;
46 template <typename>
48 template <typename>
50 template <typename>
52 
53 /*
54  * Classes to provide utility functions for a "Pixel" to get at image/mask/variance operators
55  *
56  * These classes allow us to manipulate the tuples returned by MaskedImage iterators/locators as if they were
57  * POD. This provides convenient syntactic sugar, but it also permits us to write generic algorithms to
58  * manipulate MaskedImages as well as Images
59  *
60  * We need SinglePixel as well as Pixel as the latter is just a reference to a pixel in an image, and we need
61  * to be able to build temporary values too
62  *
63  * We use C++ template expressions to manipulate Pixel and SinglePixel; this permits us to avoid making
64  * SinglePixel inherit from Pixel (or vice versa) and allows the compiler to do a much better job of
65  * optimising mixed-mode expressions --- basically, it no longer needs to create SinglePixels as Pixels that
66  * have their own storage but use the reference members of Pixel to get work done. There may be better ways,
67  * but this way works, and g++ 4.0.1 (and maybe other compilers/versions) failed to optimise the previous
68  * solution very well.
69  */
70 
72 template <typename _ImagePixelT, typename _MaskPixelT, typename _VariancePixelT = double>
74 public:
75  template <typename, typename, typename>
76  friend class Pixel;
77  template <typename T>
78  friend class PixelTypeTraits;
79 
80  typedef _ImagePixelT ImagePixelT;
81  typedef _MaskPixelT MaskPixelT;
82  typedef _VariancePixelT VariancePixelT;
83 
84  SinglePixel(ImagePixelT image, MaskPixelT mask = 0, VariancePixelT variance = 0)
85  : _image(image), _mask(mask), _variance(variance) {}
86 
87  template <typename rhsExpr>
88  SinglePixel(rhsExpr const& rhs,
89  // ensure this ctor isn't invoked for simple numeric types, which should use
90  // the overload above.
91  typename std::enable_if<!std::is_fundamental<rhsExpr>::value, void*>::type dummy = nullptr)
92  : _image(rhs.image()), _mask(rhs.mask()), _variance(rhs.variance()) {}
93 
94  ImagePixelT image() const { return _image; }
95  MaskPixelT mask() const { return _mask; }
96  VariancePixelT variance() const { return _variance; }
97 
98 private:
103  SinglePixel()
106  : 0),
107  _mask(0),
110  : 0) {}
111 
112  ImagePixelT _image;
113  MaskPixelT _mask;
114  VariancePixelT _variance;
115 };
116 
118 template <typename PixelT>
121  static inline const PixelT padValue() {
123  }
124 };
125 
127 template <typename _ImagePixelT, typename _MaskPixelT, typename _VariancePixelT>
128 struct PixelTypeTraits<SinglePixel<_ImagePixelT, _MaskPixelT, _VariancePixelT> > {
130 
132  static inline const PixelT padValue() { return PixelT(); }
133 };
134 
140 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
142  VariancePixelT v) {
144 }
145 
147 template <typename _ImagePixelT, typename _MaskPixelT, typename _VariancePixelT = double>
149 public:
150  typedef _ImagePixelT ImagePixelT;
151  typedef _MaskPixelT MaskPixelT;
152  typedef _VariancePixelT VariancePixelT;
153 
155 #if 0
156  Pixel(ImagePixelT& image, MaskPixelT& mask, VariancePixelT& variance) :
157  _image(image), _mask(mask), _variance(variance) {}
158 #else
159  //
160  // This constructor casts away const. This should be fixed by making const Pixels.
161  //
162  Pixel(ImagePixelT const& image, MaskPixelT const& mask = 0x0, VariancePixelT const& variance = 0)
163  : _image(const_cast<ImagePixelT&>(image)),
164  _mask(const_cast<MaskPixelT&>(mask)),
165  _variance(const_cast<VariancePixelT&>(variance)) {}
166 #endif
167 
169  : _image(rhs._image), _mask(rhs._mask), _variance(rhs._variance) {}
170 
171  Pixel(Pixel const& rhs) = default;
172  Pixel(Pixel&& rhs) = default;
173  ~Pixel() = default;
174 
175  Pixel operator=(Pixel const& rhs) { // the following template won't stop the compiler trying to generate
176  // operator=
177  _variance = rhs.variance(); // evaluate before we update image()
178  _image = rhs.image();
179  _mask = rhs.mask();
180 
181  return *this;
182  }
188  template <typename rhsExpr>
189  Pixel operator=(rhsExpr const& rhs) {
190  _variance = rhs.variance(); // evaluate before we update image()
191  _image = rhs.image();
192  _mask = rhs.mask();
193 
194  return *this;
195  }
196  // Delegate to copy-assignment for backwards compatibility
197  Pixel operator=(Pixel&& rhs) { return *this = rhs; }
198 
200  Pixel operator=(double const& rhs_image) {
201  _image = rhs_image;
202  _mask = 0;
203  _variance = 0;
204 
205  return *this;
206  }
207 
209  Pixel operator=(int const& rhs_image) {
210  _image = rhs_image;
211  _mask = 0;
212  _variance = 0;
213 
214  return *this;
215  }
217  ImagePixelT image() const { return _image; }
219  MaskPixelT mask() const { return _mask; }
221  VariancePixelT variance() const { return _variance; }
222  //
223  // Logical operators. We don't need to construct BinaryExpr for them
224  // as efficiency isn't a concern.
225  //
227  template <typename T1>
228  friend bool operator==(Pixel const& lhs, T1 const& rhs) {
229  return lhs.image() == rhs.image() && lhs.mask() == rhs.mask() && lhs.variance() == rhs.variance();
230  }
231 
233  template <typename T1>
234  friend bool operator!=(Pixel const& lhs, T1 const& rhs) {
235  return !(lhs == rhs);
236  }
237 
239  std::size_t hash_value() const noexcept {
240  // Completely arbitrary seed
241  // Convert to double to avoid inconsistently hashing equal numbers of different types
242  return utils::hashCombine(17, static_cast<double>(image()), static_cast<double>(mask()),
243  static_cast<double>(variance()));
244  }
245 
246  //
247  // Provide friend versions of the op= operators to permit argument promotion on their first arguments
248  //
250  template <typename ExprT>
251  friend Pixel operator+=(Pixel const& e1, ExprT const& e2) {
252  Pixel tmp(e1); // n.b. shares storage with e1 but gets around "const" (which is required)
255  return tmp;
256  }
257 
259  template <typename ExprT>
260  friend Pixel operator-=(Pixel const& e1, ExprT const& e2) {
261  Pixel tmp(e1); // n.b. shares storage with e1 but gets around "const" (which is required)
264  return tmp;
265  }
266 
268  template <typename ExprT>
269  friend Pixel operator*=(Pixel const& e1, ExprT const& e2) {
270  Pixel tmp(e1); // n.b. shares storage with e1 but gets around "const" (which is required)
273  return tmp;
274  }
275 
277  template <typename ExprT>
278  friend Pixel operator/=(Pixel const& e1, ExprT const& e2) {
279  Pixel tmp(e1); // n.b. shares storage with e1 but gets around "const" (which is required)
282  return tmp;
283  }
284 
285 private:
286  ImagePixelT& _image;
287  MaskPixelT& _mask;
288  VariancePixelT& _variance;
289 };
290 
292 template <typename ExprT>
293 struct exprTraits {
294  typedef ExprT expr_type;
295  typedef typename ExprT::ImagePixelT ImagePixelT;
296  typedef typename ExprT::MaskPixelT MaskPixelT;
297  typedef typename ExprT::VariancePixelT VariancePixelT;
298 };
299 
301 template <>
302 struct exprTraits<double> {
303  typedef double ImagePixelT;
304  typedef int MaskPixelT;
305  typedef double VariancePixelT;
307 };
308 
310 template <>
311 struct exprTraits<float> {
312  typedef float ImagePixelT;
316 };
317 
319 template <>
320 struct exprTraits<int> {
321  typedef int ImagePixelT;
325 };
326 
328 template <>
329 struct exprTraits<unsigned short> {
330  typedef int ImagePixelT;
334 };
335 
337 template <typename T1>
338 struct noop : public std::unary_function<T1, T1> {
339  T1 operator()(const T1& x) const { return x; }
340 };
341 
347 template <typename T1>
348 struct bitwise_or : public std::binary_function<T1, T1, T1> {
349  T1 operator()(const T1& x, const T1& y) const { return (x | y); }
350  T1 operator()(const T1& x) const { return x; }
351 };
352 
358 template <typename T1>
359 struct variance_divides {
360  T1 operator()(T1 const& x, T1 const& y, T1 const& vx, T1 const& vy) const {
361  T1 const x2 = x * x;
362  T1 const y2 = y * y;
363  T1 const iy2 = 1.0 / y2;
364  return x2 * vy * iy2 * iy2 + vx * iy2;
365  }
366 
367  T1 operator()(T1 const&, T1 const& y, T1 const& vx) const { return vx / (y * y); }
368 };
369 
375 template <typename T1>
376 struct variance_multiplies {
377  T1 operator()(T1 const& x, T1 const& y, T1 const& vx, T1 const& vy) const {
378  T1 const x2 = x * x;
379  T1 const y2 = y * y;
380  return x2 * vy + y2 * vx;
381  }
382 
383  T1 operator()(T1 const&, T1 const& y, T1 const& vx) const { return vx * y * y; }
384 };
385 
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; }
394 
395  T1 operator()(T1 const&, T1 const&, T1 const& vx) const { return vx; }
396 };
397 
405 template <typename T1>
407  variance_plus_covar(double alpha = 0) : _alpha(alpha) {}
408 
409  T1 operator()(T1 const&, T1 const&, T1 const& vx, T1 const& vy) const {
410  return vx + vy + 2 * _alpha * sqrt(vx * vy);
411  }
412  T1 operator()(T1 const&, T1 const&, T1 const& vx) const { return vx; }
413 
414 private:
415  double _alpha;
416 };
417 
419 template <typename ExprT1, typename ImageBinOp, typename MaskBinOp, typename VarianceBinOp>
420 class UnaryExpr {
421 public:
426  UnaryExpr(ExprT1 e1, ImageBinOp imageOp = ImageBinOp(), MaskBinOp maskOp = MaskBinOp(),
427  VarianceBinOp varOp = VarianceBinOp())
428  : _expr1(e1), _imageOp(imageOp), _maskOp(maskOp), _varOp(varOp) {}
429 
431  ImagePixelT image() const { return _imageOp(_expr1.image()); }
432 
434  MaskPixelT mask() const { return _maskOp(_expr1.mask()); }
435 
437  VariancePixelT variance() const { return _varOp(_expr1.variance()); }
438 
439 private:
440  typename exprTraits<ExprT1>::expr_type _expr1;
441  ImageBinOp _imageOp;
442  MaskBinOp _maskOp;
443  VarianceBinOp _varOp;
444 };
445 
447 template <typename ExprT1, typename ExprT2, typename ImageBinOp, typename MaskBinOp, typename VarianceBinOp>
448 class BinaryExpr final {
449 public:
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) {}
457 
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)) {}
464  ImagePixelT image() const { return _imageOp(_expr1.image(), _expr2.image()); }
465 
467  MaskPixelT mask() const { return _maskOp(_expr1.mask(), _expr2.mask()); }
468 
470  VariancePixelT variance() const {
471  return _varOp(_expr1.image(), _expr2.image(), _expr1.variance(), _expr2.variance());
472  }
473 
474 private:
475  typename exprTraits<ExprT1>::expr_type _expr1;
476  typename exprTraits<ExprT2>::expr_type _expr2;
477  ImageBinOp _imageOp;
478  MaskBinOp _maskOp;
479  VarianceBinOp _varOp;
480 };
481 
486 template <typename ExprT1, typename ImageBinOp, typename MaskBinOp, typename VarianceBinOp>
487 class BinaryExpr<ExprT1, double, ImageBinOp, MaskBinOp, VarianceBinOp> final {
488 public:
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) {}
496 
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)) {}
503  ImagePixelT image() const { return _imageOp(_expr1.image(), _expr2); }
504 
506  MaskPixelT mask() const { return _maskOp(_expr1.mask()); }
507 
509  VariancePixelT variance() const { return _varOp(_expr1.image(), _expr2, _expr1.variance()); }
510 
511 private:
512  typename exprTraits<ExprT1>::expr_type _expr1;
513  double _expr2;
514  ImageBinOp _imageOp;
515  MaskBinOp _maskOp;
516  VarianceBinOp _varOp;
517 };
518 
520 template <typename ExprT1>
523 operator-(ExprT1 e1) {
525  noop<typename exprTraits<ExprT1>::MaskPixelT>,
527 }
528 
529 //------------------------------------------
531 template <typename ExprT1, typename ExprT2>
535 operator+(ExprT1 e1, ExprT2 e2) {
536  return BinaryExpr<ExprT1, ExprT2, std::plus<typename exprTraits<ExprT1>::ImagePixelT>,
537  bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
539 }
540 
542 template <typename ExprT1, typename ExprT2>
543 ExprT1 operator+=(ExprT1& e1, ExprT2 e2) {
544  e1 = BinaryExpr<ExprT1, ExprT2, std::plus<typename exprTraits<ExprT1>::ImagePixelT>,
545  bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
547  return e1;
548 }
549 
550 //
551 // Implementations of add that work for arithmetic or MaskedImage pixels
552 //
553 // The choice is made on the basis of std::is_arithmetic
554 namespace {
555 template <typename ExprT1, typename ExprT2>
556 ExprT1 doPlus(ExprT1 e1, ExprT2 e2, double const, boost::mpl::true_) {
557  return e1 + e2;
558 }
559 
560 template <typename ExprT1, typename ExprT2>
561 BinaryExpr<ExprT1, ExprT2, std::plus<typename exprTraits<ExprT1>::ImagePixelT>,
562  bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
564 doPlus(ExprT1 e1, ExprT2 e2, double const alpha, boost::mpl::false_) {
565  return BinaryExpr<ExprT1, ExprT2, std::plus<typename exprTraits<ExprT1>::ImagePixelT>,
566  bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
568 }
569 } // namespace
570 
572 template <typename ExprT1, typename ExprT2>
573 inline ExprT1 plus(
574  ExprT1& lhs,
575  ExprT2 const& rhs,
576  float covariance
577 ) {
578  return doPlus(lhs, rhs, covariance, typename std::is_arithmetic<ExprT1>::type());
579 }
580 
581 //------------------------------------------
583 template <typename ExprT1, typename ExprT2>
585  bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
587 operator-(ExprT1 e1, ExprT2 e2) {
589  bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
591 }
592 
594 template <typename ExprT1, typename ExprT2>
595 ExprT1 operator-=(ExprT1& e1, ExprT2 e2) {
597  bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
599  return e1;
600 }
601 
602 //------------------------------------------
604 template <typename ExprT1, typename ExprT2>
606  bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
608 operator*(ExprT1 e1, ExprT2 e2) {
610  bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
612 }
613 
615 template <typename ExprT1, typename ExprT2>
616 ExprT1 operator*=(ExprT1& e1, ExprT2 e2) {
618  bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
620  return e1;
621 }
622 
623 //------------------------------------------
625 template <typename ExprT1, typename ExprT2>
627  bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
629 operator/(ExprT1 e1, ExprT2 e2) {
631  bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
633 }
634 
636 template <typename ExprT1, typename ExprT2>
637 ExprT1 operator/=(ExprT1& e1, ExprT2 e2) {
639  bitwise_or<typename exprTraits<ExprT1>::MaskPixelT>,
641  return e1;
642 }
643 
645 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
646 std::ostream& operator<<(std::ostream& os, SinglePixel<ImagePixelT, MaskPixelT, VariancePixelT> const& v) {
647  return os << "(" << v.image() << ", " << v.mask() << ", " << v.variance() << ")";
648 }
649 
651 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
652 std::ostream& operator<<(std::ostream& os, Pixel<ImagePixelT, MaskPixelT, VariancePixelT> const& v) {
653  return os << "(" << v.image() << ", " << v.mask() << ", " << v.variance() << ")";
654 }
655 
657 template <typename ExprT1, typename ExprT2, typename BinOp, typename MaskBinOp, typename VarBinOp>
658 std::ostream& operator<<(std::ostream& os, BinaryExpr<ExprT1, ExprT2, BinOp, MaskBinOp, VarBinOp> const& v) {
659  return os << "(" << v.image() << ", " << v.mask() << ", " << v.variance() << ")";
660 }
661 } // namespace pixel
662 } // namespace image
663 } // namespace afw
664 } // namespace lsst
665 
666 namespace std {
667 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
668 struct hash<lsst::afw::image::pixel::Pixel<ImagePixelT, MaskPixelT, VariancePixelT>> {
671  size_t operator()(argument_type const& obj) const noexcept { return obj.hash_value(); }
672 };
673 
674 /*
675  * SinglePixel is an awkward case because Pixel == SinglePixel is a valid comparison
676  * but SinglePixel == SinglePixel is not.
677  * Give SinglePixel a hash consistent with Pixel's, just in case somebody tries something funny.
678  */
679 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
680 struct hash<lsst::afw::image::pixel::SinglePixel<ImagePixelT, MaskPixelT, VariancePixelT>> {
683  size_t operator()(argument_type const& obj) const noexcept {
684  // Don't want to define SinglePixel::hash_value when SinglePixel::operator== doesn't exist
686  // Work around Pixel needing references to external data
687  ImagePixelT image = obj.image();
688  MaskPixelT mask = obj.mask();
689  VariancePixelT variance = obj.variance();
690  return EquivalentPixel(image, mask, variance).hash_value();
691  }
692 };
693 } // namespace std
694 #endif
MaskPixelT mask() const
evaluate the mask part of the expression
Definition: Pixel.h:467
Pixel operator=(double const &rhs_image)
set the image part of a Pixel to rhs_image (the mask and variance are set to 0)
Definition: Pixel.h:200
exprTraits< double >::MaskPixelT MaskPixelT
Definition: Pixel.h:313
friend Pixel operator/=(Pixel const &e1, ExprT const &e2)
Evaluate e1 /= e2, and return e1.
Definition: Pixel.h:278
Class for representing binary operations.
Definition: Pixel.h:39
SinglePixel< ImagePixelT, MaskPixelT, VariancePixelT > makeSinglePixel(ImagePixelT x, MaskPixelT m, VariancePixelT v)
Return a SinglePixel.
Definition: Pixel.h:141
bitwise_or doesn&#39;t seem to be in std::
Definition: Pixel.h:45
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)
Definition: Pixel.h:608
VariancePixelT variance() const
Return the variance part of a Pixel.
Definition: Pixel.h:221
SinglePixel< ImagePixelT, MaskPixelT, VariancePixelT > expr_type
Definition: Pixel.h:333
ImagePixelT image() const
evaluate the image part of the expression
Definition: Pixel.h:431
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.
Definition: Pixel.h:454
Pixel operator=(int const &rhs_image)
set the image part of a Pixel to rhs_image (the mask and variance are set to 0)
Definition: Pixel.h:209
float Pixel
Typedefs to be used for pixel values.
Definition: common.h:37
T1 operator()(T1 const &, T1 const &, T1 const &vx) const
Definition: Pixel.h:412
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.
Definition: Pixel.h:493
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) ...
Definition: Pixel.h:234
VariancePixelT variance() const
Definition: Pixel.h:96
SinglePixel< ImagePixelT, MaskPixelT, VariancePixelT > expr_type
Definition: Pixel.h:315
MaskPixelT mask() const
evaluate the mask part of the expression
Definition: Pixel.h:434
Pixel(ImagePixelT const &image, MaskPixelT const &mask=0x0, VariancePixelT const &variance=0)
Construct a Pixel from references to its image/mask/variance components.
Definition: Pixel.h:162
int y
Definition: SpanSet.cc:49
ExprT1 operator-=(ExprT1 &e1, ExprT2 e2)
Template to evaluate e1 -= e2.
Definition: Pixel.h:595
STL namespace.
T1 operator()(const T1 &x) const
Definition: Pixel.h:339
T1 operator()(T1 const &x, T1 const &y, T1 const &vx, T1 const &vy) const
Definition: Pixel.h:377
Pixel operator=(Pixel &&rhs)
Definition: Pixel.h:197
ExprT::ImagePixelT ImagePixelT
Definition: Pixel.h:295
MaskPixelT mask() const
Definition: Pixel.h:95
A single pixel of the same type as a MaskedImage.
Definition: Pixel.h:73
MatrixQ covariance
Definition: simpleShape.cc:152
T1 operator()(T1 const &, T1 const &, T1 const &vx) const
Definition: Pixel.h:395
T1 operator()(T1 const &x, T1 const &y, T1 const &vx, T1 const &vy) const
Definition: Pixel.h:360
exprTraits< ExprT1 >::MaskPixelT MaskPixelT
Definition: Pixel.h:423
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 ...
Definition: Pixel.h:460
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)
Definition: Pixel.h:629
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 ...
Definition: Pixel.h:426
ImagePixelT image() const
Definition: Pixel.h:94
static const PixelT padValue()
The quantity to use when a pixel value is undefined.
Definition: Pixel.h:132
ExprT::MaskPixelT MaskPixelT
Definition: Pixel.h:296
SinglePixel< ImagePixelT, MaskPixelT, VariancePixelT > expr_type
Definition: Pixel.h:306
exprTraits< double >::MaskPixelT MaskPixelT
Definition: Pixel.h:322
A base class for image defects.
Calculate the variance when we divide two Pixels.
Definition: Pixel.h:47
table::Key< int > type
Definition: Detector.cc:163
T1 operator()(T1 const &, T1 const &y, T1 const &vx) const
Definition: Pixel.h:383
SinglePixel(rhsExpr const &rhs, typename std::enable_if<!std::is_fundamental< rhsExpr >::value, void *>::type dummy=nullptr)
Definition: Pixel.h:88
T1 operator()(T1 const &, T1 const &, T1 const &vx, T1 const &vy) const
Definition: Pixel.h:393
MaskPixelT mask() const
Return the mask part of a Pixel.
Definition: Pixel.h:219
ExprT1 plus(ExprT1 &lhs, ExprT2 const &rhs, float covariance)
Like operator+(), but assume that covariance&#39;s 2*alpha*sqrt(vx*vy)
Definition: Pixel.h:573
T1 operator()(const T1 &x) const
Definition: Pixel.h:350
ImagePixelT image() const
Return the image part of a Pixel.
Definition: Pixel.h:217
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 ...
Definition: Pixel.h:499
friend Pixel operator-=(Pixel const &e1, ExprT const &e2)
Evaluate e1 -= e2, and return e1.
Definition: Pixel.h:260
Pixel operator=(rhsExpr const &rhs)
Assign a Pixel by evaluating an expression.
Definition: Pixel.h:189
exprTraits< ExprT1 >::MaskPixelT MaskPixelT
Definition: Pixel.h:451
double x
ExprT1 operator*=(ExprT1 &e1, ExprT2 e2)
Template to evaluate e1 *= e2.
Definition: Pixel.h:616
std::size_t hash_value() const noexcept
Return a hash of this object.
Definition: Pixel.h:239
ExprT1 operator/=(ExprT1 &e1, ExprT2 e2)
Template to evaluate e1 /= e2.
Definition: Pixel.h:637
_ImagePixelT ImagePixelT
Definition: Pixel.h:150
T1 operator()(T1 const &, T1 const &y, T1 const &vx) const
Definition: Pixel.h:367
_VariancePixelT VariancePixelT
Definition: Pixel.h:152
VariancePixelT variance() const
evaluate the variance part of the expression
Definition: Pixel.h:470
A pixel of a MaskedImage.
Definition: Pixel.h:148
SinglePixel(ImagePixelT image, MaskPixelT mask=0, VariancePixelT variance=0)
Definition: Pixel.h:84
exprTraits< double >::VariancePixelT VariancePixelT
Definition: Pixel.h:323
The variance of the sum of a pair of correlated pixels.
Definition: Pixel.h:406
exprTraits< ExprT1 >::VariancePixelT VariancePixelT
Definition: Pixel.h:424
friend Pixel operator*=(Pixel const &e1, ExprT const &e2)
Evaluate e1 *= e2, and return e1.
Definition: Pixel.h:269
VariancePixelT variance() const
evaluate the variance part of the expression
Definition: Pixel.h:437
VariancePixelT variance() const
evaluate the variance part of the expression
Definition: Pixel.h:509
exprTraits< double >::VariancePixelT VariancePixelT
Definition: Pixel.h:332
Pixel operator=(Pixel const &rhs)
Definition: Pixel.h:175
T1 operator()(const T1 &x, const T1 &y) const
Definition: Pixel.h:349
A traits class to return the types of the image/mask/variance.
Definition: Pixel.h:42
int m
Definition: SpanSet.cc:49
table::PointKey< int > pixel
exprTraits< ExprT1 >::ImagePixelT ImagePixelT
Definition: Pixel.h:450
T quiet_NaN(T... args)
ImagePixelT image() const
evaluate the image part of the expression
Definition: Pixel.h:464
std::size_t hashCombine(std::size_t seed) noexcept
Combine hashes.
Definition: hashCombine.h:35
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...
T1 operator()(T1 const &, T1 const &, T1 const &vx, T1 const &vy) const
Definition: Pixel.h:409
Pixel(SinglePixel< ImagePixelT, MaskPixelT, VariancePixelT > &rhs)
Definition: Pixel.h:168
ImagePixelT image() const
evaluate the image part of the expression
Definition: Pixel.h:503
MaskPixelT mask() const
evaluate the mask part of the expression
Definition: Pixel.h:506
exprTraits< double >::MaskPixelT MaskPixelT
Definition: Pixel.h:331
Class for representing Unary operations.
Definition: Pixel.h:420
Calculate the variance when we multiply two Pixels.
Definition: Pixel.h:49
A class used to identify classes that represent MaskedImage pixels.
Definition: MaskedImage.h:52
std::ostream * os
Definition: Schema.cc:746
UnaryExpr< ExprT1, std::negate< typename exprTraits< ExprT1 >::ImagePixelT >, noop< typename exprTraits< ExprT1 >::MaskPixelT >, noop< typename exprTraits< ExprT1 >::VariancePixelT > > operator-(ExprT1 e1)
Template for -e1.
Definition: Pixel.h:523
STL class.
ExprT::VariancePixelT VariancePixelT
Definition: Pixel.h:297
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)
Definition: Pixel.h:535
static const PixelT padValue()
The quantity to use when a pixel value is undefined.
Definition: Pixel.h:121
ExprT1 operator+=(ExprT1 &e1, ExprT2 e2)
template for e1 += e2
Definition: Pixel.h:543
exprTraits< ExprT1 >::ImagePixelT ImagePixelT
Definition: Pixel.h:422
Calculate the variance when we add (or subtract) two Pixels.
Definition: Pixel.h:51
A noop functor (useful for e.g. masks and variances when changing the sign of the image) ...
Definition: Pixel.h:338
SinglePixel< ImagePixelT, MaskPixelT, VariancePixelT > expr_type
Definition: Pixel.h:324
friend bool operator==(Pixel const &lhs, T1 const &rhs)
Return true iff two pixels are equal (in all three of image, mask, and variance)
Definition: Pixel.h:228
exprTraits< ExprT1 >::VariancePixelT VariancePixelT
Definition: Pixel.h:452
exprTraits< double >::VariancePixelT VariancePixelT
Definition: Pixel.h:314
_VariancePixelT VariancePixelT
Definition: Pixel.h:82
friend Pixel operator+=(Pixel const &e1, ExprT const &e2)
Evaluate e1 += e2, and return e1.
Definition: Pixel.h:251
friend class Pixel
Typedefs to be used for pixel values.
Definition: Pixel.h:76