LSST Applications g0f08755f38+82efc23009,g12f32b3c4e+e7bdf1200e,g1653933729+a8ce1bb630,g1a0ca8cf93+50eff2b06f,g28da252d5a+52db39f6a5,g2bbee38e9b+37c5a29d61,g2bc492864f+37c5a29d61,g2cdde0e794+c05ff076ad,g3156d2b45e+41e33cbcdc,g347aa1857d+37c5a29d61,g35bb328faa+a8ce1bb630,g3a166c0a6a+37c5a29d61,g3e281a1b8c+fb992f5633,g414038480c+7f03dfc1b0,g41af890bb2+11b950c980,g5fbc88fb19+17cd334064,g6b1c1869cb+12dd639c9a,g781aacb6e4+a8ce1bb630,g80478fca09+72e9651da0,g82479be7b0+04c31367b4,g858d7b2824+82efc23009,g9125e01d80+a8ce1bb630,g9726552aa6+8047e3811d,ga5288a1d22+e532dc0a0b,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+37c5a29d61,gcf0d15dbbd+2acd6d4d48,gd7358e8bfb+778a810b6e,gda3e153d99+82efc23009,gda6a2b7d83+2acd6d4d48,gdaeeff99f8+1711a396fd,ge2409df99d+6b12de1076,ge79ae78c31+37c5a29d61,gf0baf85859+d0a5978c5a,gf3967379c6+4954f8c433,gfb92a5be7c+82efc23009,gfec2e1e490+2aaed99252,w.2024.46
LSST Data Management Base Package
Loading...
Searching...
No Matches
Mask.h
Go to the documentation of this file.
1// -*- lsst-c++ -*-
2
3/*
4 * LSST Data Management System
5 * Copyright 2008, 2009, 2010 LSST Corporation.
6 *
7 * This product includes software developed by the
8 * LSST Project (http://www.lsst.org/).
9 *
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the LSST License Statement and
21 * the GNU General Public License along with this program. If not,
22 * see <http://www.lsstcorp.org/LegalNotices/>.
23 */
24
25/*
26 * LSST bitmasks
27 */
28
29#ifndef LSST_AFW_IMAGE_MASK_H
30#define LSST_AFW_IMAGE_MASK_H
31
32#include <list>
33#include <map>
34#include <string>
35
36#include <memory>
37
38#include "lsst/base.h"
40#include "lsst/pex/exceptions.h"
44
45namespace lsst {
46namespace afw {
47namespace image {
48
49namespace detail {
50class MaskDict; // forward declaration
51}
52
53// all masks will initially be instantiated with the same pixel type
54namespace detail {
56struct Mask_tag : public detail::basic_tag {};
57
59} // namespace detail
60
80template <typename MaskPixelT = lsst::afw::image::MaskPixel>
81class Mask : public ImageBase<MaskPixelT> {
82public:
84
86
88 template <typename MaskPT = MaskPixelT>
92 };
93
94 // Constructors
102 explicit Mask(unsigned int width, unsigned int height, MaskPlaneDict const& planeDefs = MaskPlaneDict());
111 explicit Mask(unsigned int width, unsigned int height, MaskPixelT initialValue,
119 explicit Mask(lsst::geom::Extent2I const& dimensions = lsst::geom::Extent2I(),
128 explicit Mask(lsst::geom::Extent2I const& dimensions, MaskPixelT initialValue,
136 explicit Mask(lsst::geom::Box2I const& bbox, MaskPlaneDict const& planeDefs = MaskPlaneDict());
144 explicit Mask(lsst::geom::Box2I const& bbox, MaskPixelT initialValue,
146
167 explicit Mask(std::string const& fileName, int hdu = fits::DEFAULT_HDU,
170 lsst::geom::Box2I const& bbox = lsst::geom::Box2I(), ImageOrigin origin = PARENT,
171 bool conformMasks = false, bool allowUnsafe = false);
172
193 explicit Mask(fits::MemFileManager& manager, int hdu = fits::DEFAULT_HDU,
196 lsst::geom::Box2I const& bbox = lsst::geom::Box2I(), ImageOrigin origin = PARENT,
197 bool conformMasks = false, bool allowUnsafe = false);
198
219 lsst::geom::Box2I const& bbox = lsst::geom::Box2I(), ImageOrigin origin = PARENT,
220 bool conformMasks = false, bool allowUnsafe = false);
221
222 // generalised copy constructor
223 template <typename OtherPixelT>
224 Mask(Mask<OtherPixelT> const& rhs, const bool deep)
225 : image::ImageBase<MaskPixelT>(rhs, deep), _maskDict(rhs._maskDict) {}
226
233 Mask(const Mask& src, const bool deep = false);
234 Mask(Mask&& src);
235 ~Mask() override;
244 Mask(const Mask& src, const lsst::geom::Box2I& bbox, ImageOrigin const origin = PARENT,
245 const bool deep = false);
246
247 explicit Mask(ndarray::Array<MaskPixelT, 2, 1> const& array, bool deep = false,
249
250 void swap(Mask& rhs);
251 // Operators
252
253 Mask& operator=(MaskPixelT const rhs);
254 Mask& operator=(const Mask& rhs);
255 Mask& operator=(Mask&& rhs);
256
258 Mask& operator|=(Mask const& rhs);
260 Mask& operator|=(MaskPixelT const rhs);
261
263 Mask& operator&=(Mask const& rhs);
265 Mask& operator&=(MaskPixelT const rhs);
266
280 Mask subset(lsst::geom::Box2I const& bbox, ImageOrigin origin = PARENT) const {
281 return Mask(*this, bbox, origin, false);
282 }
283
285 Mask operator[](lsst::geom::Box2I const& bbox) const { return subset(bbox); }
286
287 using ImageBase<MaskPixelT>::operator[];
288
294 static MaskPixelT getPlaneBitMask(const std::vector<std::string>& names);
295
297 Mask& operator^=(Mask const& rhs);
299 Mask& operator^=(MaskPixelT const rhs);
300
322 bool operator()(int x, int y, int plane) const;
330 typename ImageBase<MaskPixelT>::PixelReference operator()(int x, int y, CheckIndices const& check);
339 CheckIndices const& check) const;
348 bool operator()(int x, int y, int plane, CheckIndices const& check) const;
349
351
358 void writeFits(std::string const& fileName, daf::base::PropertySet const* metadata = nullptr,
359 std::string const& mode = "w") const;
361
363
370 void writeFits(fits::MemFileManager& manager, daf::base::PropertySet const* metadata = nullptr,
371 std::string const& mode = "w") const;
373
375
381 void writeFits(fits::Fits& fitsfile, daf::base::PropertySet const* metadata = nullptr) const;
383
385
394 std::string const& mode = "w", daf::base::PropertySet const* header = nullptr) const;
396
398
407 std::string const& mode = "w", daf::base::PropertySet const* header = nullptr) const;
409
411
419 daf::base::PropertySet const* header = nullptr) const;
421
430 static Mask readFits(std::string const& filename, int hdu = fits::DEFAULT_HDU) {
431 return Mask<MaskPixelT>(filename, hdu);
432 }
433
443 return Mask<MaskPixelT>(manager, hdu);
444 }
445
447 static std::string interpret(MaskPixelT value);
448 std::string getAsString(int x, int y) { return interpret((*this)(x, y)); }
449
450 // Mask Plane ops
451
453 void clearAllMaskPlanes();
455 void clearMaskPlane(int plane);
459 void setMaskPlaneValues(const int plane, const int x0, const int x1, const int y);
467 //
468 // Operations on the mask plane dictionary
469 //
471 static void clearMaskPlaneDict();
472 static int addMaskPlane(const std::string& name);
473 static void removeMaskPlane(const std::string& name);
483 void removeAndClearMaskPlane(const std::string& name, bool const removeFromDefault = false);
484
490 static int getMaskPlane(const std::string& name);
496 static MaskPixelT getPlaneBitMask(const std::string& name);
497
498 static int getNumPlanesMax() { return 8 * sizeof(MaskPixelT); }
499 static int getNumPlanesUsed();
503 MaskPlaneDict const& getMaskPlaneDict() const;
505 void printMaskPlanes() const;
506
511 //
512 // This one isn't static, it fixes up a given Mask's planes
528
529private:
530 friend class MaskFitsReader;
531
532 std::shared_ptr<detail::MaskDict> _maskDict; // our bitplane dictionary
533
534 static std::shared_ptr<detail::MaskDict> _maskPlaneDict();
535 static int _setMaskPlaneDict(MaskPlaneDict const& mpd);
536 static const std::string maskPlanePrefix;
537
546 static int addMaskPlane(std::string name, int plane);
547
549 static int getMaskPlaneNoThrow(const std::string& name);
551 static MaskPixelT getBitMaskNoThrow(int plane);
557 static MaskPixelT getBitMask(int plane);
558
562 void _initializePlanes(MaskPlaneDict const& planeDefs); // called by ctors
563
564 //
565 // Make names in templatized base class visible (Meyers, Effective C++, Item 43)
566 //
567 using ImageBase<MaskPixelT>::_getRawView;
568 using ImageBase<MaskPixelT>::swap;
569
575 void checkMaskDictionaries(Mask const& other);
576};
577
578template <typename PixelT>
580} // namespace image
581} // namespace afw
582} // namespace lsst
583
584#endif // LSST_AFW_IMAGE_MASK_H
AmpInfoBoxKey bbox
Definition Amplifier.cc:117
std::shared_ptr< RecordT > src
Definition Match.cc:48
int y
Definition SpanSet.cc:48
table::Key< int > b
Basic LSST definitions.
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition fits.h:308
Lifetime-management for memory that goes into FITS memory files.
Definition fits.h:125
A class used to request that array accesses be checked.
Definition ImageBase.h:74
The base class for all image classed (Image, Mask, MaskedImage, ...)
Definition ImageBase.h:102
typename Reference< PixelT >::type PixelReference
A Reference to a PixelT.
Definition ImageBase.h:117
typename ndarray::Array< PixelT, 2, 1 > Array
A mutable ndarray representation of the image.
Definition ImageBase.h:149
_view_t _getRawView() const
Definition ImageBase.h:465
typename ConstReference< PixelT >::type PixelConstReference
A ConstReference to a PixelT.
Definition ImageBase.h:119
A FITS reader class for Masks.
Represent a 2-dimensional array of bitmask pixels.
Definition Mask.h:81
void swap(Mask &rhs)
Definition Mask.cc:126
void writeFits(fits::MemFileManager &manager, fits::ImageWriteOptions const &options, std::string const &mode="w", daf::base::PropertySet const *header=nullptr) const
Write a mask to a FITS RAM file.
Mask & operator=(MaskPixelT const rhs)
Definition Mask.cc:152
void printMaskPlanes() const
print the mask plane dictionary to std::cout
Definition Mask.cc:642
static Mask readFits(std::string const &filename, int hdu=fits::DEFAULT_HDU)
Read a Mask from a regular FITS file.
Definition Mask.h:430
static int getMaskPlane(const std::string &name)
Return the mask plane number corresponding to a plane name.
Definition Mask.cc:354
detail::MaskPlaneDict MaskPlaneDict
Definition Mask.h:83
static std::string interpret(MaskPixelT value)
Interpret a mask value as a comma-separated list of mask plane names.
Definition Mask.cc:249
static void removeMaskPlane(const std::string &name)
Definition Mask.cc:302
void removeAndClearMaskPlane(const std::string &name, bool const removeFromDefault=false)
Clear all pixels of the specified mask and remove the plane from the mask plane dictionary; optionall...
Definition Mask.cc:313
Mask(Mask< OtherPixelT > const &rhs, const bool deep)
Definition Mask.h:224
static Mask readFits(fits::MemFileManager &manager, int hdu=fits::DEFAULT_HDU)
Read a Mask from a FITS RAM file.
Definition Mask.h:442
static void clearMaskPlaneDict()
Reset the maskPlane dictionary.
Definition Mask.cc:390
void setMaskPlaneValues(const int plane, const int x0, const int x1, const int y)
Set the bit specified by "planeId" for pixels (x0, y) ... (x1, y)
Definition Mask.cc:564
static void addMaskPlanesToMetadata(std::shared_ptr< lsst::daf::base::PropertySet >)
Given a PropertySet, replace any existing MaskPlane assignments with the current ones.
Definition Mask.cc:573
Mask subset(lsst::geom::Box2I const &bbox, ImageOrigin origin=PARENT) const
Return a subimage corresponding to the given box.
Definition Mask.h:280
ImageBase< MaskPixelT >::PixelReference operator()(int x, int y)
get a reference to the specified pixel
Definition Mask.cc:461
Mask & operator^=(Mask const &rhs)
XOR a Mask into a Mask.
Definition Mask.cc:550
static int addMaskPlane(const std::string &name)
Definition Mask.cc:264
Mask(std::string const &fileName, int hdu=fits::DEFAULT_HDU, std::shared_ptr< lsst::daf::base::PropertySet > metadata=std::shared_ptr< lsst::daf::base::PropertySet >(), lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool conformMasks=false, bool allowUnsafe=false)
Construct a Mask by reading a regular FITS file.
void writeFits(std::string const &filename, fits::ImageWriteOptions const &options, std::string const &mode="w", daf::base::PropertySet const *header=nullptr) const
Write a mask to a regular FITS file.
static MaskPixelT getPlaneBitMask(const std::vector< std::string > &names)
Return the bitmask corresponding to a vector of plane names OR'd together.
Definition Mask.cc:376
Mask(fits::MemFileManager &manager, int hdu=fits::DEFAULT_HDU, std::shared_ptr< lsst::daf::base::PropertySet > metadata=std::shared_ptr< lsst::daf::base::PropertySet >(), lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool conformMasks=false, bool allowUnsafe=false)
Construct a Mask by reading a FITS image in memory.
std::string getAsString(int x, int y)
Definition Mask.h:448
Mask(fits::Fits &fitsfile, std::shared_ptr< lsst::daf::base::PropertySet > metadata=std::shared_ptr< lsst::daf::base::PropertySet >(), lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool conformMasks=false, bool allowUnsafe=false)
Construct a Mask from an already-open FITS object.
void writeFits(fits::MemFileManager &manager, daf::base::PropertySet const *metadata=nullptr, std::string const &mode="w") const
Write a mask to a FITS RAM file.
MaskPlaneDict const & getMaskPlaneDict() const
Return the Mask's maskPlaneDict.
Definition Mask.cc:297
void conformMaskPlanes(const MaskPlaneDict &masterPlaneDict)
Adjust this mask to conform to the standard Mask class's mask plane dictionary, adding any new mask p...
Definition Mask.cc:405
Mask & operator|=(Mask const &rhs)
OR a Mask into a Mask.
Definition Mask.cc:509
Mask operator[](lsst::geom::Box2I const &bbox) const
Return a subimage corresponding to the given box (interpreted as PARENT coordinates).
Definition Mask.h:285
static MaskPlaneDict parseMaskPlaneMetadata(std::shared_ptr< lsst::daf::base::PropertySet const > metadata)
Given a PropertySet that contains the MaskPlane assignments, setup the MaskPlanes.
Definition Mask.cc:601
void clearAllMaskPlanes()
Clear all the pixels.
Definition Mask.cc:395
static int getNumPlanesUsed()
Definition Mask.cc:385
void writeFits(fits::Fits &fitsfile, daf::base::PropertySet const *metadata=nullptr) const
Write a mask to an open FITS file object.
void clearMaskPlane(int plane)
Clear the specified bit in all pixels.
Definition Mask.cc:400
static int getNumPlanesMax()
Definition Mask.h:498
void writeFits(std::string const &fileName, daf::base::PropertySet const *metadata=nullptr, std::string const &mode="w") const
Write a mask to a regular FITS file.
void writeFits(fits::Fits &fitsfile, fits::ImageWriteOptions const &options, daf::base::PropertySet const *header=nullptr) const
Write a mask to an open FITS file object.
Mask & operator&=(Mask const &rhs)
AND a Mask into a Mask.
Definition Mask.cc:529
Class for storing generic metadata.
Definition PropertySet.h:66
An integer coordinate rectangle.
Definition Box.h:55
const int DEFAULT_HDU
Specify that the default HDU should be read.
std::map< std::string, int > MaskPlaneDict
Definition Mask.h:58
void swap(Image< PixelT > &a, Image< PixelT > &b)
Definition Image.cc:443
Options for writing an image to FITS.
Definition fits.h:223
A templated class to return this classes' type (present in Image/Mask/MaskedImage)
Definition Mask.h:89
Mask< MaskPT > type
Return the desired type.
Definition Mask.h:91
g2d::python::Image< bool > Mask
Definition test_image.cc:16