Loading [MathJax]/extensions/tex2jax.js
LSST Applications g04a91732dc+2945638123,g07dc498a13+7e3c5f68a2,g12483e3c20+e0fa9c8503,g1409bbee79+7e3c5f68a2,g1a7e361dbc+7e3c5f68a2,g1fd858c14a+9f35e23ec3,g35bb328faa+fcb1d3bbc8,g3ad4f90e5c+e0fa9c8503,g3bd4b5ce2c+36fb6ead7f,g4e0f332c67+5d362be553,g53246c7159+fcb1d3bbc8,g5477a8d5ce+db04660fe6,g60b5630c4e+e0fa9c8503,g75b6c65c88+55830bd904,g78460c75b0+2f9a1b4bcd,g786e29fd12+cf7ec2a62a,g7b71ed6315+fcb1d3bbc8,g8852436030+4639f750a5,g89139ef638+7e3c5f68a2,g8f1d76f86f+11a01f47f4,g9125e01d80+fcb1d3bbc8,g919ac25b3e+28db628500,g95236ca021+f7a31438ed,g989de1cb63+7e3c5f68a2,g9f33ca652e+d1e6496fea,ga365f290ef+26a6f9aaf0,gaaedd4e678+7e3c5f68a2,gabe3b4be73+1e0a283bba,gb1101e3267+c09b629e83,gb4a253aaf5+0122250889,gb58c049af0+f03b321e39,gbaa7868d32+e0fa9c8503,gc99c83e5f0+76d20ab76d,gcf25f946ba+4639f750a5,gd6cbbdb0b4+c8606af20c,gde0f65d7ad+021d0de224,ge278dab8ac+932305ba37,gfba249425e+fcb1d3bbc8,w.2025.08
LSST Data Management Base Package
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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
81template <typename MaskPixelT = lsst::afw::image::MaskPixel>
82class Mask : public ImageBase<MaskPixelT> {
83public:
85
87
89 template <typename MaskPT = MaskPixelT>
93 };
94
95 // Constructors
103 explicit Mask(unsigned int width, unsigned int height, MaskPlaneDict const& planeDefs = MaskPlaneDict());
112 explicit Mask(unsigned int width, unsigned int height, MaskPixelT initialValue,
113 MaskPlaneDict const& planeDefs = MaskPlaneDict());
120 explicit Mask(lsst::geom::Extent2I const& dimensions = lsst::geom::Extent2I(),
121 MaskPlaneDict const& planeDefs = MaskPlaneDict());
129 explicit Mask(lsst::geom::Extent2I const& dimensions, MaskPixelT initialValue,
130 MaskPlaneDict const& planeDefs = MaskPlaneDict());
137 explicit Mask(lsst::geom::Box2I const& bbox, MaskPlaneDict const& planeDefs = MaskPlaneDict());
145 explicit Mask(lsst::geom::Box2I const& bbox, MaskPixelT initialValue,
146 MaskPlaneDict const& planeDefs = MaskPlaneDict());
147
168 explicit Mask(std::string const& fileName, int hdu = fits::DEFAULT_HDU,
171 lsst::geom::Box2I const& bbox = lsst::geom::Box2I(), ImageOrigin origin = PARENT,
172 bool conformMasks = false, bool allowUnsafe = false);
173
194 explicit Mask(fits::MemFileManager& manager, int hdu = fits::DEFAULT_HDU,
197 lsst::geom::Box2I const& bbox = lsst::geom::Box2I(), ImageOrigin origin = PARENT,
198 bool conformMasks = false, bool allowUnsafe = false);
199
217 explicit Mask(fits::Fits& fitsfile,
220 lsst::geom::Box2I const& bbox = lsst::geom::Box2I(), ImageOrigin origin = PARENT,
221 bool conformMasks = false, bool allowUnsafe = false);
222
223 // generalised copy constructor
224 template <typename OtherPixelT>
225 Mask(Mask<OtherPixelT> const& rhs, const bool deep)
226 : image::ImageBase<MaskPixelT>(rhs, deep), _maskDict(rhs._maskDict) {}
227
234 Mask(const Mask& src, const bool deep = false);
235 Mask(Mask&& src);
236 ~Mask() override;
245 Mask(const Mask& src, const lsst::geom::Box2I& bbox, ImageOrigin const origin = PARENT,
246 const bool deep = false);
247
248 explicit Mask(ndarray::Array<MaskPixelT, 2, 1> const& array, bool deep = false,
250
251 void swap(Mask& rhs);
252 // Operators
253
254 Mask& operator=(MaskPixelT const rhs);
255 Mask& operator=(const Mask& rhs);
257
259 Mask& operator|=(Mask const& rhs);
261 Mask& operator|=(MaskPixelT const rhs);
262
264 Mask& operator&=(Mask const& rhs);
266 Mask& operator&=(MaskPixelT const rhs);
267
281 Mask subset(lsst::geom::Box2I const& bbox, ImageOrigin origin = PARENT) const {
282 return Mask(*this, bbox, origin, false);
283 }
284
286 Mask operator[](lsst::geom::Box2I const& bbox) const { return subset(bbox); }
287
288 using ImageBase<MaskPixelT>::operator[];
289
295 static MaskPixelT getPlaneBitMask(const std::vector<std::string>& names);
296
298 Mask& operator^=(Mask const& rhs);
300 Mask& operator^=(MaskPixelT const rhs);
301
323 bool operator()(int x, int y, int plane) const;
340 CheckIndices const& check) const;
349 bool operator()(int x, int y, int plane, CheckIndices const& check) const;
350
352
359 void writeFits(std::string const& fileName, daf::base::PropertySet const* metadata = nullptr,
360 std::string const& mode = "w") const;
362
364
371 void writeFits(fits::MemFileManager& manager, daf::base::PropertySet const* metadata = nullptr,
372 std::string const& mode = "w") const;
374
376
382 void writeFits(fits::Fits& fitsfile, daf::base::PropertySet const* metadata = nullptr) const;
384
386
395 std::string const& mode = "w", daf::base::PropertySet const* header = nullptr) const;
397
399
408 std::string const& mode = "w", daf::base::PropertySet const* header = nullptr) const;
410
412
420 daf::base::PropertySet const* header = nullptr) const;
422
431 static Mask readFits(std::string const& filename, int hdu = fits::DEFAULT_HDU) {
432 return Mask<MaskPixelT>(filename, hdu);
433 }
434
444 return Mask<MaskPixelT>(manager, hdu);
445 }
446
448 static std::string interpret(MaskPixelT value);
449 std::string getAsString(int x, int y) { return interpret((*this)(x, y)); }
450
451 // Mask Plane ops
452
456 void clearMaskPlane(int plane);
460 void setMaskPlaneValues(const int plane, const int x0, const int x1, const int y);
468 //
469 // Operations on the mask plane dictionary
470 //
472 static void clearMaskPlaneDict();
473 static int addMaskPlane(const std::string& name);
474 static void removeMaskPlane(const std::string& name);
484 void removeAndClearMaskPlane(const std::string& name, bool const removeFromDefault = false);
485
491 static int getMaskPlane(const std::string& name);
497 static MaskPixelT getPlaneBitMask(const std::string& name);
498
499 static int getNumPlanesMax() { return 8 * sizeof(MaskPixelT); }
500 static int getNumPlanesUsed();
506 void printMaskPlanes() const;
507
512 //
513 // This one isn't static, it fixes up a given Mask's planes
528 void conformMaskPlanes(const MaskPlaneDict& masterPlaneDict);
529
530private:
531 friend class MaskFitsReader;
532
533 std::shared_ptr<detail::MaskDict> _maskDict; // our bitplane dictionary
534
535 static std::shared_ptr<detail::MaskDict> _maskPlaneDict();
536 static int _setMaskPlaneDict(MaskPlaneDict const& mpd);
537 static const std::string maskPlanePrefix;
538
547 static int addMaskPlane(std::string name, int plane);
548
550 static int getMaskPlaneNoThrow(const std::string& name);
552 static MaskPixelT getBitMaskNoThrow(int plane);
558 static MaskPixelT getBitMask(int plane);
559
563 void _initializePlanes(MaskPlaneDict const& planeDefs); // called by ctors
564
565 //
566 // Make names in templatized base class visible (Meyers, Effective C++, Item 43)
567 //
568 using ImageBase<MaskPixelT>::_getRawView;
569 using ImageBase<MaskPixelT>::swap;
570
576 void checkMaskDictionaries(Mask const& other);
577};
578
579template <typename PixelT>
580void swap(Mask<PixelT>& a, Mask<PixelT>& b);
581} // namespace image
582} // namespace afw
583} // namespace lsst
584
585#endif // LSST_AFW_IMAGE_MASK_H
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 ConstReference< PixelT >::type PixelConstReference
A ConstReference to a PixelT.
Definition ImageBase.h:119
Represent a 2-dimensional array of bitmask pixels.
Definition Mask.h:82
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:431
ImageBase< MaskPixelT >::PixelConstReference operator()(int x, int y) const
get the specified pixel (const version)
Definition Mask.cc:472
Mask & operator|=(MaskPixelT const rhs)
OR a bitmask into a Mask.
Definition Mask.cc:502
static int getMaskPlane(const std::string &name)
Return the mask plane number corresponding to a plane name.
Definition Mask.cc:354
static MaskPixelT getPlaneBitMask(const std::string &name)
Return the bitmask corresponding to a plane name.
Definition Mask.cc:371
detail::MaskPlaneDict MaskPlaneDict
Definition Mask.h:84
Mask(lsst::geom::Box2I const &bbox, MaskPlaneDict const &planeDefs=MaskPlaneDict())
Construct a Mask initialized to 0x0.
Definition Mask.cc:92
static std::string interpret(MaskPixelT value)
Interpret a mask value as a comma-separated list of mask plane names.
Definition Mask.cc:249
Mask(const Mask &src, const bool deep=false)
Construct a Mask from another Mask.
Definition Mask.cc:111
static void removeMaskPlane(const std::string &name)
Definition Mask.cc:302
Mask & operator^=(MaskPixelT const rhs)
XOR a bitmask into a Mask.
Definition Mask.cc:543
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:225
static Mask readFits(fits::MemFileManager &manager, int hdu=fits::DEFAULT_HDU)
Read a Mask from a FITS RAM file.
Definition Mask.h:443
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:281
Mask & operator&=(MaskPixelT const rhs)
AND a bitmask into a Mask.
Definition Mask.cc:523
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
bool operator()(int x, int y, int plane, CheckIndices const &check) const
is the specified mask plane set in the specified pixel, checking array bounds?
Definition Mask.cc:489
Mask(lsst::geom::Extent2I const &dimensions=lsst::geom::Extent2I(), MaskPlaneDict const &planeDefs=MaskPlaneDict())
Construct a Mask initialized to 0x0.
Definition Mask.cc:77
Mask(const Mask &src, const lsst::geom::Box2I &bbox, ImageOrigin const origin=PARENT, const bool deep=false)
Construct a Mask from a subregion of another Mask.
Definition Mask.cc:106
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.
Mask & operator=(Mask &&rhs)
Definition Mask.cc:147
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.
Mask(unsigned int width, unsigned int height, MaskPixelT initialValue, MaskPlaneDict const &planeDefs=MaskPlaneDict())
Construct a Mask initialized to a specified value.
Definition Mask.cc:69
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(lsst::geom::Extent2I const &dimensions, MaskPixelT initialValue, MaskPlaneDict const &planeDefs=MaskPlaneDict())
Construct a Mask initialized to a specified value.
Definition Mask.cc:84
Mask(ndarray::Array< MaskPixelT, 2, 1 > const &array, bool deep=false, lsst::geom::Point2I const &xy0=lsst::geom::Point2I())
Definition Mask.cc:121
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.
Mask(unsigned int width, unsigned int height, MaskPlaneDict const &planeDefs=MaskPlaneDict())
Construct a Mask initialized to 0x0.
Definition Mask.cc:62
std::string getAsString(int x, int y)
Definition Mask.h:449
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.
Mask(Mask &&src)
Definition Mask.cc:115
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
Mask(lsst::geom::Box2I const &bbox, MaskPixelT initialValue, MaskPlaneDict const &planeDefs=MaskPlaneDict())
Construct a Mask initialized to a specified value.
Definition Mask.cc:99
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:286
ImageBase< MaskPixelT >::PixelReference operator()(int x, int y, CheckIndices const &check)
get a reference to the specified pixel checking array bounds
Definition Mask.cc:466
bool operator()(int x, int y, int plane) const
is the specified mask plane set in the specified pixel?
Definition Mask.cc:483
detail::Mask_tag image_category
Definition Mask.h:86
ImageBase< MaskPixelT >::PixelConstReference operator()(int x, int y, CheckIndices const &check) const
get the specified pixel with array checking (const version)
Definition Mask.cc:477
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.
Mask & operator=(const Mask &rhs)
Definition Mask.cc:139
void clearMaskPlane(int plane)
Clear the specified bit in all pixels.
Definition Mask.cc:400
static int getNumPlanesMax()
Definition Mask.h:499
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:67
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
Extent< int, 2 > Extent2I
Definition Extent.h:397
Point< int, 2 > Point2I
Definition Point.h:321
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:90
Mask< MaskPT > type
Return the desired type.
Definition Mask.h:92
g2d::python::Image< bool > Mask
Definition test_image.cc:16