mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
Image Masks

Functions for masking images.

Functions

template<class eigenT >
void mx::improc::radiusImage (eigenT &m, typename eigenT::Scalar xc, typename eigenT::Scalar yc, typename eigenT::Scalar scale=1)
 Fills in the cells of an Eigen 2D Array with their radius from the center. More...
 
template<class eigenT >
void mx::improc::radiusImage (eigenT &m, typename eigenT::Scalar scale=1)
 Fills in the cells of Eigen-like 2D Array with their radius from the canonical center. More...
 
template<class angleT , class eigenT >
void mx::improc::angleImage (eigenT &m, typename angleT::realT xc, typename angleT::realT yc)
 Fills in the cells of an Eigen-like 2D Array with their angle relative to the center. More...
 
template<class angleT , class eigenT >
void mx::improc::angleImage (eigenT &m)
 Fills in the cells of Eigen 2D Array with their angle relative the canonical center. More...
 
template<class angleT , class eigenT1 , class eigenT2 >
void mx::improc::radAngImage (eigenT1 &rIm, eigenT2 &qIm, typename angleT::realT xc, typename angleT::realT yc, typename angleT::realT rscale=1)
 Fills in the cells of Eigen-like arrays with their radius amd angle relative to the center. More...
 
template<typename angleT , typename eigenT1 , typename eigenT2 , typename eigenT3 = eigenT1>
std::vector< size_t > mx::improc::annulusIndices (const eigenT1 &rIm, const eigenT2 &qIm, typename angleT::realT xcen, typename angleT::realT ycen, typename angleT::realT min_r, typename angleT::realT max_r, typename angleT::realT min_q, typename angleT::realT max_q, eigenT3 *mask=0)
 Get the vector indices of an annular region in an image. More...
 
template<typename angleT >
void mx::improc::annulusBoundingRect (int &x0, int &y0, int &x1, int &y1, typename angleT::realT xcen, typename angleT::realT ycen, typename angleT::realT min_r, typename angleT::realT max_r, typename angleT::realT min_q, typename angleT::realT max_q)
 Get the coordinates of the bounding rectangle of an annulus. More...
 
template<class eigenT >
void mx::improc::applyMask (eigenT &maskedIm, const std::vector< size_t > &idx, typename eigenT::Scalar maskval)
 Apply a mask to an image. More...
 
template<class arrayT >
void mx::improc::maskCircle (arrayT &m, typename arrayT::Scalar xcen, typename arrayT::Scalar ycen, typename arrayT::Scalar rad, typename arrayT::Scalar val, typename arrayT::Scalar pixbuf=0.5)
 Mask a circle in an image. More...
 
template<class arrayT >
void mx::improc::maskCircle (arrayT &m, typename arrayT::Scalar rad, typename arrayT::Scalar val, typename arrayT::Scalar pixbuf=0.5)
 Mask a circle in an image at the standard center. More...
 
template<class arrayT >
void mx::improc::maskEllipse (arrayT &m, typename arrayT::Scalar xcen, typename arrayT::Scalar ycen, typename arrayT::Scalar xrad, typename arrayT::Scalar yrad, typename arrayT::Scalar ang, typename arrayT::Scalar val=0, typename arrayT::Scalar pixbuf=0.5)
 Mask an ellipse in an image. More...
 
template<typename realT >
int mx::improc::drawLine (eigenImage< realT > &mask, realT x0, realT y0, realT x1, realT y1, realT val)
 Draw a thin (1-pixel) line from one point to another. More...
 
template<typename realT >
int mx::improc::drawLine (eigenImage< realT > &mask, realT x0, realT y0, realT x1, realT y1, realT width, realT val)
 Draw a thick line from one point to another. More...
 
template<typename imT >
int mx::improc::ccdBleedMask (imT &im, typename imT::Scalar x0, typename imT::Scalar y0, typename imT::Scalar rad, typename imT::Scalar height, typename imT::Scalar lwidth, typename imT::Scalar rwidth)
 Populate a mask based on a typical CCD bleeding pattern. More...
 
template<typename imageTout , typename imageTin >
void mx::improc::cutImageRegion (imageTout &imout, const imageTin &imin, const std::vector< size_t > &idx, bool resize=true)
 Cut out a region of an image specified by an index-mask. More...
 
template<typename imageTout , typename imageTin >
void mx::improc::insertImageRegion (imageTout imout, const imageTin &imin, const std::vector< size_t > &idx)
 Insert a region of an image specified by an index-mask. More...
 

Function Documentation

◆ angleImage() [1/2]

template<class angleT , class eigenT >
void mx::improc::angleImage ( eigenT &  m)

Fills in the cells of Eigen 2D Array with their angle relative the canonical center.

The center is \( (x_c, y_c) = (0.5*(dim_1-1), 0.5*(dim_2 -1)) \).

Template Parameters
angleTis the angle type, either radiansT<realT> or degreesT<realT>. Note that realT sets the type for all arithmetic.
eigenTis an Eigen-like 2D array type
Parameters
m< [out] the allocated angle array. Will be filled in with angle values.

Definition at line 135 of file imageMasks.hpp.

◆ angleImage() [2/2]

template<class angleT , class eigenT >
void mx::improc::angleImage ( eigenT &  m,
typename angleT::realT  xc,
typename angleT::realT  yc 
)

Fills in the cells of an Eigen-like 2D Array with their angle relative to the center.

Template Parameters
angleTis the angle type, either radiansT<realT> or degreesT<realT>. Note that realT sets the type for all arithmetic.
eigenTis an Eigen-like 2D array type
Parameters
[out]mthe allocated angle array. Will be filled in with angle values.
[in]xcthe x center
[in]ycthe y center

Definition at line 105 of file imageMasks.hpp.

◆ annulusBoundingRect()

template<typename angleT >
void mx::improc::annulusBoundingRect ( int &  x0,
int &  y0,
int &  x1,
int &  y1,
typename angleT::realT  xcen,
typename angleT::realT  ycen,
typename angleT::realT  min_r,
typename angleT::realT  max_r,
typename angleT::realT  min_q,
typename angleT::realT  max_q 
)

Get the coordinates of the bounding rectangle of an annulus.

Template Parameters
angleTis the angle type, either radiansT<realT> or degreesT<realT>. Note that realT sets the type for all arithmetic.
Parameters
[out]x0The lower left x-coordinate of the bounding rect.
[out]y0The lower left y-coordinate of the bounding rect.
[out]x1The upper right x-coordinate of the bounding rect.
[out]y1The upper right y-coordinate of the bounding rect.
[in]xcenthe x center of the image
[in]ycenthe y center of the image
[in]min_rthe minimum radius of the region
[in]max_rthe maximum radius of the region
[in]min_qthe minimum angle of the region.
[in]max_qthe maximum angle of the region.

Definition at line 268 of file imageMasks.hpp.

◆ annulusIndices()

template<typename angleT , typename eigenT1 , typename eigenT2 , typename eigenT3 = eigenT1>
std::vector<size_t> mx::improc::annulusIndices ( const eigenT1 &  rIm,
const eigenT2 &  qIm,
typename angleT::realT  xcen,
typename angleT::realT  ycen,
typename angleT::realT  min_r,
typename angleT::realT  max_r,
typename angleT::realT  min_q,
typename angleT::realT  max_q,
eigenT3 *  mask = 0 
)

Get the vector indices of an annular region in an image.

Template Parameters
angleTis the angle type, either radiansT<realT> or degreesT<realT>. Note that realT sets the type for all arithmetic.
eigenT1is an Eigen-like 2D array type. Should be resolved by compiler.
eigenT2is an Eigen-like 2D array type. Should be resolved by compiler.
eigenT3is an Eigen-like 2D array type. Should be resolved by compiler.
Returns
a vector containing the 1D indices of the region defined by the input parameters
Parameters
[in]rIma radius image of the type produced by radiusImage
[in]qIman angle image of the type produce by angleImage
[in]xcenthe x center of the image
[in]ycenthe y center of the image
[in]min_rthe minimum radius of the region
[in]max_rthe maximum radius of the region
[in]min_qthe minimum angle of the region.
[in]max_qthe maximum angle of the region.
[in]mask[optional] pointer to a mask image, only pixels of value 1 are included in the indices.

Definition at line 194 of file imageMasks.hpp.

◆ applyMask()

template<class eigenT >
void mx::improc::applyMask ( eigenT &  maskedIm,
const std::vector< size_t > &  idx,
typename eigenT::Scalar  maskval 
)

Apply a mask to an image.

The pixels indicated by the indices are set to a value.

Template Parameters
eigenTis an Eigen-like 2D array type
Parameters
[out]maskedImthe image to mask (will be modified)
[in]idxthe indices of the pixels to mask
[in]maskvalthe mask value.

Definition at line 385 of file imageMasks.hpp.

◆ ccdBleedMask()

template<typename imT >
int mx::improc::ccdBleedMask ( imT &  im,
typename imT::Scalar  x0,
typename imT::Scalar  y0,
typename imT::Scalar  rad,
typename imT::Scalar  height,
typename imT::Scalar  lwidth,
typename imT::Scalar  rwidth 
)

Populate a mask based on a typical CCD bleeding pattern.

Masks a circle for saturated pixels, as well as a horizontal bar for bleeding (in both directions if needed).

Returns
0 on success, -1 otherwise.
Template Parameters
imTis an Eigen-like 2D array type.
Parameters
[out]imthe mask, on output will be 1/0. Must be allocated prior to call.
[in]x0the x-coordinate of the center of the mask
[in]y0the y-coordinate of the center of the mask
[in]radthe radius of the central circle.
[in]heightthe half-height of the saturation bar.
[in]lwidththe length of the saturation bar to the left.
[in]rwidththe length of the saturation bar to the right.

Definition at line 732 of file imageMasks.hpp.

◆ cutImageRegion()

template<typename imageTout , typename imageTin >
void mx::improc::cutImageRegion ( imageTout &  imout,
const imageTin &  imin,
const std::vector< size_t > &  idx,
bool  resize = true 
)

Cut out a region of an image specified by an index-mask.

The output will be a row-image containing the pixel values.

Template Parameters
imageToutis the output image Eigen-like type.
imageTinis the input image Eigen-like type.
Parameters
[out]imouta row-image containing the pixel values specified by the indices.
[in]imina 2-D image
[in]idxthe linear indices of the pixel values
[in]resize[optional] flag controls whether imout is resized. It is if true.

Definition at line 777 of file imageMasks.hpp.

Referenced by mx::improc::KLIPreduction< _realT, _derotFunctObj, _evCalcT >::regions().

◆ drawLine() [1/2]

template<typename realT >
int mx::improc::drawLine ( eigenImage< realT > &  mask,
realT  x0,
realT  y0,
realT  x1,
realT  y1,
realT  val 
)

Draw a thin (1-pixel) line from one point to another.

Calculates the line connecting the two points and sets the pixels along that line to the supplied value.

Template Parameters
realTa real floating point type
Parameters
mask[in.out] [pre-allocated] The array in which to draw the line.
[in]x0The x coordinate of the first point
[in]y0The y coordinate of the first point
[in]x1The x coordinate of the second point
[in]y1The y coordinate of the second point
[in]valThe value to set on the pixels in the line

Definition at line 517 of file imageMasks.hpp.

◆ drawLine() [2/2]

template<typename realT >
int mx::improc::drawLine ( eigenImage< realT > &  mask,
realT  x0,
realT  y0,
realT  x1,
realT  y1,
realT  width,
realT  val 
)

Draw a thick line from one point to another.

Calculates the line connecting the two points and sets the pixels along that line to the supplied value. Makes the line thick by drawing lines perpindicular to each point with length equal to the specified width.

Template Parameters
realTa real floating point type
Parameters
mask[in.out] [pre-allocated] The array in which to draw the line.
[in]x0The x coordinate of the first point
[in]y0The y coordinate of the first point
[in]x1The x coordinate of the second point
[in]y1The y coordinate of the second point
[in]widthThe desired full-width of the line
[in]valThe value to set on the pixels in the line

Definition at line 611 of file imageMasks.hpp.

◆ insertImageRegion()

template<typename imageTout , typename imageTin >
void mx::improc::insertImageRegion ( imageTout  imout,
const imageTin &  imin,
const std::vector< size_t > &  idx 
)

Insert a region of an image specified by an index-mask.

Both the input and the output are row-images containing the pixel values.

Template Parameters
imageToutis the output image Eigen-like type.
imageTinis the input image Eigen-like type.
Parameters
[out]imouta row-image into which the pixel values specified by the indices are inserted.
[in]imina row-image containing the pixel values, same size as idx
[in]idxthe linear indices of the pixel values

Definition at line 805 of file imageMasks.hpp.

Referenced by mx::improc::KLIPreduction< _realT, _derotFunctObj, _evCalcT >::worker().

◆ maskCircle() [1/2]

template<class arrayT >
void mx::improc::maskCircle ( arrayT &  m,
typename arrayT::Scalar  rad,
typename arrayT::Scalar  val,
typename arrayT::Scalar  pixbuf = 0.5 
)

Mask a circle in an image at the standard center.

The circle is centered at 0.5*(rows-1) and 0.5*(cols-1), and described by its radius. Any value can be set for the mask.
Pixels outside the masked circle are not altered.

Template Parameters
arrayTis an Eigen-like type.
Parameters
m[in.out] the image to be masked, is modified.
[in]radthe radius of the circle
[in]valthe mask value.
[in]pixbuf[optional] buffer for radius comparison. Default is 0.5 pixels.

Definition at line 440 of file imageMasks.hpp.

◆ maskCircle() [2/2]

template<class arrayT >
void mx::improc::maskCircle ( arrayT &  m,
typename arrayT::Scalar  xcen,
typename arrayT::Scalar  ycen,
typename arrayT::Scalar  rad,
typename arrayT::Scalar  val,
typename arrayT::Scalar  pixbuf = 0.5 
)

Mask a circle in an image.

The circle is describe by its center coordinates and radius. Any value can be set for the mask. Pixels outside the masked circle are not altered.

Template Parameters
arrayTis an Eigen-like type.
Parameters
m[in.out] the image to be masked, is modified.
[in]xcenthe x coordinate of the center of the circle
[in]ycenthe y coordinate of the center of the circle
[in]radthe radius of the circle
[in]valthe mask value.
[in]pixbuf[optional] buffer for radius comparison. Default is 0.5 pixels.

Definition at line 406 of file imageMasks.hpp.

References mx::astro::constants::c().

◆ maskEllipse()

template<class arrayT >
void mx::improc::maskEllipse ( arrayT &  m,
typename arrayT::Scalar  xcen,
typename arrayT::Scalar  ycen,
typename arrayT::Scalar  xrad,
typename arrayT::Scalar  yrad,
typename arrayT::Scalar  ang,
typename arrayT::Scalar  val = 0,
typename arrayT::Scalar  pixbuf = 0.5 
)

Mask an ellipse in an image.

The ellipse is describe by its center coordinates and x and y direction radii (the semi-major and -minor axes, in either order). Any value can be set for the mask, with 0 being the default.

Template Parameters
arrayTis an Eigen-like type.
Parameters
m[in.out] the image to be masked, is modified.
[in]xcenthe x coordinate of the center of the ellipse
[in]ycenthe y coordinate of the center of the ellipse
[in]xradthe x radius of the ellipse
[in]yradthe y radius of the ellipse
[in]angthe c.c.w. angle to rotate the ellipse by
[in]val[optional] the mask value. Default is 0.
[in]pixbuf[optional] buffer for radius comparison. Default is 0.5 pixels.

Definition at line 458 of file imageMasks.hpp.

◆ radAngImage()

template<class angleT , class eigenT1 , class eigenT2 >
void mx::improc::radAngImage ( eigenT1 &  rIm,
eigenT2 &  qIm,
typename angleT::realT  xc,
typename angleT::realT  yc,
typename angleT::realT  rscale = 1 
)

Fills in the cells of Eigen-like arrays with their radius amd angle relative to the center.

Template Parameters
angleTis the angle type, either radiansT<realT> or degreesT<realT>. Note that realT sets the type for all arithmetic.
eigenT1is an Eigen-like 2D array type. Should be resolved by compiler.
eigenT2is an Eigen-like 2D array type. Should be resolved by compiler.
Parameters
[out]rImthe allocated radius array, will be filled in with radius values.
[out]qImthe angle array, will be re-sized to match rIm. Will be filled in with angle values.
[in]xcthe x center
[in]ycthe y center
[in]rscale[optional] a scaling to apply to each radius value. Default is 1.0.

Definition at line 155 of file imageMasks.hpp.

◆ radiusImage() [1/2]

template<class eigenT >
void mx::improc::radiusImage ( eigenT &  m,
typename eigenT::Scalar  scale = 1 
)

Fills in the cells of Eigen-like 2D Array with their radius from the canonical center.

The center is \( (x_c, y_c) = (0.5*(dim_1-1), 0.5*(dim_2 -1)) \).

Template Parameters
eigenTis an Eigen-like 2D array type
Parameters
[out]mthe allocated radius array, will be filled in with radius values.
[in]scale[optional] a scaling to apply to each value (default = 1)

Definition at line 84 of file imageMasks.hpp.

◆ radiusImage() [2/2]

template<class eigenT >
void mx::improc::radiusImage ( eigenT &  m,
typename eigenT::Scalar  xc,
typename eigenT::Scalar  yc,
typename eigenT::Scalar  scale = 1 
)

Fills in the cells of an Eigen 2D Array with their radius from the center.

Template Parameters
eigenTis an Eigen-like 2D array type
Parameters
[out]mthe allocated radius array, will be filled in with radius values.
[in]xcthe x center
[in]ycthe y center
[in]scale[optional] a scaling to apply to each value (default = 1)

Definition at line 49 of file imageMasks.hpp.

Referenced by mx::improc::radprof(), mx::improc::radprofim(), mx::improc::aperturePhotometer< realT >::resize(), mx::improc::stddevImage(), and mx::improc::stddevImageCube().