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

Using the Eigen matrix library for image processing

Classes

class  mx::improc::eigenCube< dataT >
 An image cube with an Eigen-like API. More...
 
struct  mx::improc::is_eigenCube< T >
 Test whether a type is an eigenCube by testing whether it has a typedef of "is_eigenCube". More...
 
struct  mx::improc::eigenArrPlanes< arrT, isCube >
 Function object to return the number of planes for any Eigen like object, whether 2D or a 3D cube. More...
 

Typedefs

template<typename scalarT >
using mx::improc::eigenImage = Eigen::Array< scalarT, -1, -1 >
 Definition of the eigenImage type, which is an alias for Eigen::Array.
 
template<typename scalarT >
using mx::improc::eigenMap = Eigen::Map< Eigen::Array< scalarT, -1, -1 > >
 Definition of the eigenMap type, which is an alias for Eigen::Map<Array>.
 

Functions

template<class imageT , typename valueT >
void mx::improc::zeroNaNs (imageT &im, valueT val)
 Zero any NaNs in an image.
 
template<class imageT >
void mx::improc::zeroNaNs (imageT &im)
 Zero any NaNs in an image.
 
template<class cubeT , class maskCubeT >
void mx::improc::zeroNaNCube (cubeT &imc, maskCubeT *mask)
 Zero any NaNs in an image cube.
 
template<class cubeT >
void mx::improc::zeroNaNCube (cubeT &imc)
 Zero any NaNs in an image cube.
 
template<class calcT , class imageT >
calcT mx::improc::imageMean (imageT &im)
 Calculate the mean value of an image.
 
template<class calcT , class imageT , class maskT >
calcT mx::improc::imageMean (imageT &im, const maskT &mask)
 Calculate the mean value of an image over a mask.
 
template<typename calcT , class imageT >
calcT mx::improc::imageVariance (imageT &im, calcT mn)
 Calculate the variance of an image given its mean.
 
template<typename calcT , class imageT , class maskT >
calcT mx::improc::imageVariance (imageT &im, calcT mn, const maskT &mask)
 Calculate the variance of an image given its mean.
 
template<typename imageT , typename maskT = imageT>
imageT::Scalar mx::improc::imageMedian (const imageT &mat, const maskT *mask, std::vector< typename imageT::Scalar > *work=0)
 Calculate the median of an Eigen-like array.
 
template<typename imageT >
imageT::Scalar mx::improc::imageMedian (const imageT &mat, std::vector< typename imageT::Scalar > *work=0)
 Calculate the median of an Eigen-like array.
 
template<typename imageT >
int mx::improc::imageCenterOfLight (typename imageT::Scalar &x, typename imageT::Scalar &y, const imageT &im)
 Calculate the center of light of an image.
 
template<typename floatT , typename imageT , typename magImageT , typename transformT >
int mx::improc::imageMaxInterp (floatT &x, floatT &y, floatT &scale_x, floatT &scale_y, magImageT &magIm, const imageT &im, transformT trans)
 Find the maximum in an image at sub-pixel resolution by interpolation.
 
template<typename floatT , typename imageT , typename magImageT >
int mx::improc::imageMaxInterp (floatT &x, floatT &y, floatT &scale_x, floatT &scale_y, magImageT &magIm, const imageT &im)
 Find the maximum in an image at sub-pixel resolution by cubic convolution interpolation.
 
template<typename imageT , typename imageT1 , typename imageT2 , typename imageT3 , typename imageT4 >
void mx::improc::combine2ImagesMasked (imageT &combo, const imageT1 &im1, const imageT2 &mask1, const imageT3 &im2, const imageT4 &mask2)
 Combine two images, each with their own mask defining good pixels.
 
template<typename eigenT , typename eigenTin >
void mx::improc::removeRowsAndCols (eigenT &out, const eigenTin &in, int st, int w)
 Remove rows and columns.
 
template<typename eigenT , typename eigenTin >
void mx::improc::removeRows (eigenT &out, const eigenTin &in, int st, int w)
 Remove rows.
 
template<typename eigenT , typename eigenTin >
void mx::improc::removeCols (eigenT &out, const eigenTin &in, int st, int w)
 Remove columns.
 

Typedef Documentation

◆ eigenImage

template<typename scalarT >
using mx::improc::eigenImage = typedef Eigen::Array<scalarT, -1, -1>

Definition of the eigenImage type, which is an alias for Eigen::Array.

Definition at line 44 of file eigenImage.hpp.

◆ eigenMap

template<typename scalarT >
using mx::improc::eigenMap = typedef Eigen::Map<Eigen::Array<scalarT, -1, -1> >

Definition of the eigenMap type, which is an alias for Eigen::Map<Array>.

Definition at line 50 of file eigenImage.hpp.

Function Documentation

◆ combine2ImagesMasked()

template<typename imageT , typename imageT1 , typename imageT2 , typename imageT3 , typename imageT4 >
void mx::improc::combine2ImagesMasked ( imageT &  combo,
const imageT1 &  im1,
const imageT2 &  mask1,
const imageT3 &  im2,
const imageT4 &  mask2 
)

Combine two images, each with their own mask defining good pixels.

The combined image is made up of the pixels in im1 where mask1 is 1, and the pixels of im2 where mask2 is 1. If a pixel in both mask1 and mask2 has a value of 1, that pixel in the combo is the average of im1 and im2. All other pixels are set to 0 in the combined image.

Separate template types are used for each argument to allow references, etc.

Template Parameters
imageTthe eigen-like array type of the combined image
imageT1the eigen-like array type of image 1
imageT2the eigen-like array type of mask 1
imageT3the eigen-like array type of image 2
imageT4the eigen-like array type of mask 2
Parameters
[out]combothe combined image. will be resized.
[in]im1the first image
[in]mask1the mask for the first image
[in]im2the second image
[in]mask2the mask for the second image

Definition at line 458 of file imageUtils.hpp.

◆ imageCenterOfLight()

template<typename imageT >
int mx::improc::imageCenterOfLight ( typename imageT::Scalar &  x,
typename imageT::Scalar &  y,
const imageT &  im 
)

Calculate the center of light of an image.

Note that the sum of the image should be > 0.

Parameters
[out]xthe x coordinate of the center of light [pixels]
[out]ythe y coordinate of hte center of light [pixels]
[in]imthe image to centroid

Definition at line 349 of file imageUtils.hpp.

Referenced by mx::improc::circleOuterpix(), mx::improc::imageXCorrFFT< _realImageT >::findPeak(), mx::improc::imageXCorrDiscrete< _ccImT >::operator()(), SCENARIO(), and SCENARIO().

◆ imageMaxInterp() [1/2]

template<typename floatT , typename imageT , typename magImageT >
int mx::improc::imageMaxInterp ( floatT &  x,
floatT &  y,
floatT &  scale_x,
floatT &  scale_y,
magImageT &  magIm,
const imageT &  im 
)

Find the maximum in an image at sub-pixel resolution by cubic convolution interpolation.

Uses imageMagnify() to expand the image to the desired scale. Because of the scaling used in imageMagnify, the desired scale may not be exact. As a result the actual scale is returned in scale_x and scale_y.

Parameters
[out]xthe x-position of the maximum, in pixels of the input image
[out]ythe y-position of the maximum, in pixels of the input image
scale_x[in.out] the desired scale or resolution, in pixels < 1, in the x direction. On output contains the actual scale calculated.
scale_y[in.out] the desired scale or resolution, in pixels < 1, in the y direction. On output contains the actual scale calculated.
[in]magImthe magnified image. This is used as working memory, will be resized.
[in]imthe image to find the maximum of

Definition at line 429 of file imageUtils.hpp.

References mx::improc::imageMaxInterp().

◆ imageMaxInterp() [2/2]

template<typename floatT , typename imageT , typename magImageT , typename transformT >
int mx::improc::imageMaxInterp ( floatT &  x,
floatT &  y,
floatT &  scale_x,
floatT &  scale_y,
magImageT &  magIm,
const imageT &  im,
transformT  trans 
)

Find the maximum in an image at sub-pixel resolution by interpolation.

Uses imageMagnify() to expand the image to the desired scale. Because of the scaling used in imageMagnify, the desired scale may not be exact. As a result the actual scale is returned in scale_x and scale_y.

Parameters
[out]xthe x-position of the maximum, in pixels of the input image
[out]ythe y-position of the maximum, in pixels of the input image
scale_x[in.out] the desired scale or resolution, in pixels < 1, in the x direction. On output contains the actual scale calculated.
scale_y[in.out] the desired scale or resolution, in pixels < 1, in the y direction. On output contains the actual scale calculated.
[in]magImthe magnified image. This is used as working memory, will be resized.
[in]imthe image to find the maximum of
[in]transthe transform to use for interpolation

Definition at line 389 of file imageUtils.hpp.

References mx::improc::imageMagnify().

Referenced by mx::improc::imageMaxInterp().

◆ imageMean() [1/2]

template<class calcT , class imageT >
calcT mx::improc::imageMean ( imageT &  im)

Calculate the mean value of an image.

Returns
the mean of the input image
Parameters
[in]imthe image of which to calculate the mean

Definition at line 196 of file imageUtils.hpp.

Referenced by mx::improc::imageXCorrDiscrete< _ccImT >::operator()(), and mx::improc::imageXCorrDiscrete< _ccImT >::refIm().

◆ imageMean() [2/2]

template<class calcT , class imageT , class maskT >
calcT mx::improc::imageMean ( imageT &  im,
const maskT &  mask 
)

Calculate the mean value of an image over a mask.

Returns
the mean of the input image in the masked region
Parameters
[in]imthe image of which to calculate the mean
[in]maska 1/0 mask where 1 defines the good pixels

Definition at line 208 of file imageUtils.hpp.

◆ imageMedian() [1/2]

template<typename imageT , typename maskT = imageT>
imageT::Scalar mx::improc::imageMedian ( const imageT &  mat,
const maskT *  mask,
std::vector< typename imageT::Scalar > *  work = 0 
)

Calculate the median of an Eigen-like array.

Calculates the median of the entire array, allowing for some pixels to be ignored using a mask. Working memory can be retained between calls.

Template Parameters
imageTis an Eigen-like type
maskTis an Eigen-like type
Returns
the median of the unmasked pixels of mat, using vectorMedianInPlace().
Parameters
[in]matthe image to take the median of
[in]maskif non-0, a 1/0 mask where 0 pixels are ignored.
[in]work[optional] working memory can be retained and re-passed. Is resized.

Definition at line 259 of file imageUtils.hpp.

References mx::math::vectorMedianInPlace().

Referenced by mx::sigproc::basisAmplitudes(), mx::improc::imageMedian(), and mx::improc::eigenCube< dataT >::median().

◆ imageMedian() [2/2]

template<typename imageT >
imageT::Scalar mx::improc::imageMedian ( const imageT &  mat,
std::vector< typename imageT::Scalar > *  work = 0 
)

Calculate the median of an Eigen-like array.

Calculates the median of the entire array. Working memory can be retained between calls.

Template Parameters
imageTis an Eigen-like type
Returns
the median of the unmasked pixels of mat, using vectorMedianInPlace().
Parameters
[in]matthe image to take the median of
[in]work[optional] working memory can be retained and re-passed.

Definition at line 335 of file imageUtils.hpp.

References mx::improc::imageMedian().

◆ imageVariance() [1/2]

template<typename calcT , class imageT >
calcT mx::improc::imageVariance ( imageT &  im,
calcT  mn 
)

Calculate the variance of an image given its mean.

Returns
the variance of the input image
Parameters
[in]imthe image of which to calculate the variance
[in]mnthe mean value of the image w.r.t. which to calcualate the variance

Definition at line 222 of file imageUtils.hpp.

Referenced by mx::improc::imageXCorrDiscrete< _ccImT >::operator()(), and mx::improc::imageXCorrDiscrete< _ccImT >::refIm().

◆ imageVariance() [2/2]

template<typename calcT , class imageT , class maskT >
calcT mx::improc::imageVariance ( imageT &  im,
calcT  mn,
const maskT &  mask 
)

Calculate the variance of an image given its mean.

Returns
the variance of the input image
Parameters
[in]imthe image of which to calculate the variance
[in]mnthe mean value of the image w.r.t. which to calcualate the variance
[in]maska 1/0 mask where 1 defines the good pixels

Definition at line 237 of file imageUtils.hpp.

◆ removeCols()

template<typename eigenT , typename eigenTin >
void mx::improc::removeCols ( eigenT &  out,
const eigenTin &  in,
int  st,
int  w 
)

Remove columns.

Definition at line 522 of file imageUtils.hpp.

◆ removeRows()

template<typename eigenT , typename eigenTin >
void mx::improc::removeRows ( eigenT &  out,
const eigenTin &  in,
int  st,
int  w 
)

Remove rows.

Definition at line 507 of file imageUtils.hpp.

◆ removeRowsAndCols()

template<typename eigenT , typename eigenTin >
void mx::improc::removeRowsAndCols ( eigenT &  out,
const eigenTin &  in,
int  st,
int  w 
)

Remove rows and columns.

Definition at line 488 of file imageUtils.hpp.

◆ zeroNaNCube() [1/2]

template<class cubeT >
void mx::improc::zeroNaNCube ( cubeT &  imc)

Zero any NaNs in an image cube.

Parameters
imc[in.out] cube which will have any NaN pixels set to zero

Definition at line 183 of file imageUtils.hpp.

◆ zeroNaNCube() [2/2]

template<class cubeT , class maskCubeT >
void mx::improc::zeroNaNCube ( cubeT &  imc,
maskCubeT *  mask 
)

Zero any NaNs in an image cube.

This version fills in a mask with 1s where there were nans, 0s elsewhere.

Parameters
imc[in.out] cube which will have any NaN pixels set to zero
[out]maska 1/0 mask with 1 indicating which pixels where nan

Definition at line 149 of file imageUtils.hpp.

References mx::improc::IsNan().

◆ zeroNaNs() [1/2]

template<class imageT >
void mx::improc::zeroNaNs ( imageT &  im)

Zero any NaNs in an image.

Parameters
im[in.out] image which will have any NaN pixels set to zero

Definition at line 137 of file imageUtils.hpp.

◆ zeroNaNs() [2/2]

template<class imageT , typename valueT >
void mx::improc::zeroNaNs ( imageT &  im,
valueT  val 
)

Zero any NaNs in an image.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
im[in.out] image which will have any NaN pixels set to zero
[in]val[optional] The value to set NaN pixels too. Default is 0.

Definition at line 116 of file imageUtils.hpp.

References mx::improc::IsNan().