mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
Loading...
Searching...
No Matches

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.
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.
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<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.
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<typename vecT, typename angleT, typename eigenT1, typename eigenT2, typename eigenT3 = eigenT1>
vecT mx::improc::annulusCoordsWorker (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, typename angleT::realT pixbuf=0)
 Get the coordinates of an annular region in an image.
template<typename angleT, typename eigenT1, typename eigenT2, typename eigenT3 = eigenT1>
std::vector< std::vector< int > > mx::improc::annulusCoords (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, typename angleT::realT pixbuf=0)
 Get the array coordinates of an annular region in an image.
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, typename angleT::realT pixbuf=0)
 Get the vector indices of an annular region in an image.
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, typename angleT::realT pixbuf=0)
 Get the coordinates of the bounding rectangle of an annulus.
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.
template<class eigenT>
void mx::improc::applyMask (eigenT &maskedIm, const std::vector< std::vector< int > > &coord, typename eigenT::Scalar maskval)
 Apply a mask to an image.
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.
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.
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.
template<class arrayT>
void mx::improc::maskWedge (arrayT &m, typename arrayT::Scalar xcen, typename arrayT::Scalar ycen, typename arrayT::Scalar angCen, typename arrayT::Scalar angHW, typename arrayT::Scalar val=0)
 Mask a wedge in an image.
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.
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.
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.
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.
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.

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 133 of file imageMasks.hpp.

References angleImage().

◆ 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 104 of file imageMasks.hpp.

References mx::math::two_pi().

Referenced by angleImage().

◆ 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,
typename angleT::realT pixbuf = 0 )

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.
[in]pixbuf[optional] the pixel buffer for radius comparisons

Definition at line 409 of file imageMasks.hpp.

References mx::math::angleMean().

◆ annulusCoords()

template<typename angleT, typename eigenT1, typename eigenT2, typename eigenT3 = eigenT1>
std::vector< std::vector< int > > mx::improc::annulusCoords ( 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,
typename angleT::realT pixbuf = 0 )

Get the array coordinates 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 vectors of the 2D 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.
[in]pixbuf[optional] amount subtracted from the inclusive inner radius and added to the exclusive outer radius

Definition at line 323 of file imageMasks.hpp.

References annulusCoordsWorker().

Referenced by TEST_CASE().

◆ annulusCoordsWorker()

template<typename vecT, typename angleT, typename eigenT1, typename eigenT2, typename eigenT3 = eigenT1>
vecT mx::improc::annulusCoordsWorker ( 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,
typename angleT::realT pixbuf = 0 )

Get the coordinates 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 coordinates formatted bt maskCoordFormat 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.
[in]pixbuf[optional] amount subtracted from the inclusive inner radius and added to the exclusive outer radius

Definition at line 214 of file imageMasks.hpp.

References mx::math::angleDiff(), and mx::math::angleMod().

Referenced by annulusCoords(), and annulusIndices().

◆ 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,
typename angleT::realT pixbuf = 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.
[in]pixbuf[optional] amount subtracted from the inclusive inner radius and added to the exclusive outer radius

Definition at line 368 of file imageMasks.hpp.

References annulusCoordsWorker().

Referenced by TEST_CASE(), and TEST_CASE().

◆ applyMask() [1/2]

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 518 of file imageMasks.hpp.

◆ applyMask() [2/2]

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

Apply a mask to an image.

The pixels indicated by the coordinates in a vector are set to a value.

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

Definition at line 538 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 927 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 972 of file imageMasks.hpp.

Referenced by TEST_CASE().

◆ 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 720 of file imageMasks.hpp.

Referenced by drawLine().

◆ 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 814 of file imageMasks.hpp.

References drawLine(), and mx::math::pi().

◆ 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 999 of file imageMasks.hpp.

Referenced by TEST_CASE().

◆ 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 593 of file imageMasks.hpp.

References maskCircle().

◆ 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 558 of file imageMasks.hpp.

Referenced by maskCircle(), TEST_CASE(), TEST_CASE(), TEST_CASE(), and TEST_CASE().

◆ 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,cwith 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 612 of file imageMasks.hpp.

◆ maskWedge()

template<class arrayT>
void mx::improc::maskWedge ( arrayT & m,
typename arrayT::Scalar xcen,
typename arrayT::Scalar ycen,
typename arrayT::Scalar angCen,
typename arrayT::Scalar angHW,
typename arrayT::Scalar val = 0 )

Mask a wedge in an image.

The wedge is describe by its center coordinate, central angle, and angular half-width. 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]angCenthe central angle of the wedge, in degrees
[in]angHWthe angular half-wdith of the wedge, in degrees
[in]val[optional] the mask value. Default is 0.

Definition at line 681 of file imageMasks.hpp.

References mx::math::angleDiff(), and mx::math::rtod().

Referenced by TEST_CASE().

◆ 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 152 of file imageMasks.hpp.

References mx::math::two_pi().

Referenced by TEST_CASE(), TEST_CASE(), and TEST_CASE().

◆ 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 82 of file imageMasks.hpp.

References radiusImage().

◆ 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 48 of file imageMasks.hpp.

Referenced by radiusImage(), radprof(), radprof(), radprofim(), mx::improc::aperturePhotometer< realT >::resize(), stddevImage(), stddevImageCube(), and unitTest::improcTest::imageFiltersTest::TEST_CASE().