mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
mx::improc::imageXCorrDiscrete< _ccImT > Class Template Reference

template<class _ccImT>
class mx::improc::imageXCorrDiscrete< _ccImT >

Find the optimum shift to align two images using the discrete cross correlation.

The reference image must be smaller than the target image. Both the reference image and the section of target image being analyzed are mean subtracted and variance normalized. An optional mask can be supplied, which limits the pixels used for the mean and variance calculation.

Typical usage will be to set the mask, then the reference, then repeatedly call operator() to determine the shifts for a sequence of imaages. No new heap allocations take place on these calls to operator(), and the reference image is not re-normalized on each call.

The shift is reported in pixels such that if the mxlib imageShift function is used to shift the input image by the negative of the shifts, it will align with the reference at the center of the array.

Three peak finding methods are provided. xcorrPeakMethod::centroid uses center of light, xcorrPeakMethod::centroid uses Gaussian centroiding, and xcorrPeakMethod::interp uses interpolation to find the peak to a given tolerance.

Template Parameters
_ccImTis the Eigen-like array type used for image processing. See typedefs.

Definition at line 63 of file imageXCorrDiscrete.hpp.

#include <improc/imageXCorrDiscrete.hpp>

Public Types

typedef _ccImT ccImT
 the Eigen-like array type used for image processing More...
 
typedef _ccImT::Scalar Scalar
 the scalar type of the image type More...
 

Public Member Functions

 imageXCorrDiscrete ()
 Default c'tor. More...
 
 imageXCorrDiscrete (int maxLag)
 Construct seeting maxLag. More...
 
int maxLag ()
 Get the current maximum lag. More...
 
void maxLag (int ml)
 Set the maximum lag. More...
 
Scalar tol ()
 Get the tolerance of the interpolated-magnified image, in pixels. More...
 
void tol (Scalar nt)
 Set the tolerance of the interpolated-magnified image, in pixels. More...
 
int resize (int nrows, int ncols)
 Set the size of the cross-correlation images. More...
 
int maskIm (const ccImT &mask)
 Set the mask image. More...
 
const ccImTmaskIm ()
 Get a reference to the mask image. More...
 
int refIm (const ccImT &im0)
 Set the reference image. More...
 
const ccImTrefIm ()
 Get a reference to the reference image. More...
 
const ccImTnormIm ()
 Get a reference to the normalized image. More...
 
const ccImTccIm ()
 Get a reference to the cross correlation image. More...
 
const ccImTmagIm ()
 Get a reference to the magnified image. More...
 
template<class imT >
int operator() (Scalar &xShift, Scalar &yShift, const imT &im)
 Conduct the cross correlation to a specified tolerance. More...
 

Public Attributes

int m_maxLag {0}
 The maximum lag to consider in the initial cross-correlation.
More...
 
Scalar m_tol {0.1}
 The tolerance of the interpolated-magnified image, in pixels. More...
 
Scalar m_magSize {0}
 Magnified size of the ccIm when using interp. Set as function of m_tol and m_maxLag. More...
 
Working Memory
ccImT m_refIm
 The normalized reference image. More...
 
ccImT m_maskIm
 Mask image to use, may be needed for proper normalization even if refIm has 0 mask applied. More...
 
bool m_haveMask {false}
 
ccImT m_normIm
 The normalized image. More...
 
ccImT m_ccIm
 The cross-correlation image. More...
 
ccImT m_magIm
 The magnified image, used if m_peakMethod == xcorrPeakMethod::interp. More...
 

Member Typedef Documentation

◆ ccImT

template<class _ccImT >
typedef _ccImT mx::improc::imageXCorrDiscrete< _ccImT >::ccImT

the Eigen-like array type used for image processing

Definition at line 66 of file imageXCorrDiscrete.hpp.

◆ Scalar

template<class _ccImT >
typedef _ccImT::Scalar mx::improc::imageXCorrDiscrete< _ccImT >::Scalar

the scalar type of the image type

Definition at line 67 of file imageXCorrDiscrete.hpp.

Constructor & Destructor Documentation

◆ imageXCorrDiscrete() [1/2]

Default c'tor.

Definition at line 195 of file imageXCorrDiscrete.hpp.

◆ imageXCorrDiscrete() [2/2]

template<class ccImT >
mx::improc::imageXCorrDiscrete< ccImT >::imageXCorrDiscrete ( int  maxLag)
explicit

Construct seeting maxLag.

Definition at line 200 of file imageXCorrDiscrete.hpp.

Member Function Documentation

◆ ccIm()

template<class ccImT >
const ccImT & mx::improc::imageXCorrDiscrete< ccImT >::ccIm

Get a reference to the cross correlation image.

Returns
a const referent to m_ccIm.

Definition at line 290 of file imageXCorrDiscrete.hpp.

◆ magIm()

template<class ccImT >
const ccImT & mx::improc::imageXCorrDiscrete< ccImT >::magIm

Get a reference to the magnified image.

Returns
a const referent to m_magIm.

Definition at line 296 of file imageXCorrDiscrete.hpp.

◆ maskIm() [1/2]

template<class ccImT >
const ccImT & mx::improc::imageXCorrDiscrete< ccImT >::maskIm

Get a reference to the mask image.

Returns
a const referance to the mask image.

Definition at line 246 of file imageXCorrDiscrete.hpp.

◆ maskIm() [2/2]

template<class ccImT >
int mx::improc::imageXCorrDiscrete< ccImT >::maskIm ( const ccImT mask)

Set the mask image.

Returns
0 on success
-1 on error
Parameters
[in]maskthe new mask image

Definition at line 237 of file imageXCorrDiscrete.hpp.

◆ maxLag() [1/2]

template<class ccImT >
int mx::improc::imageXCorrDiscrete< ccImT >::maxLag

Get the current maximum lag.

Returns
the current value of m_maxLag

Definition at line 206 of file imageXCorrDiscrete.hpp.

◆ maxLag() [2/2]

template<class ccImT >
void mx::improc::imageXCorrDiscrete< ccImT >::maxLag ( int  ml)

Set the maximum lag.

Parameters
[in]mlthe new maximum lag

Definition at line 212 of file imageXCorrDiscrete.hpp.

◆ normIm()

template<class ccImT >
const ccImT & mx::improc::imageXCorrDiscrete< ccImT >::normIm

Get a reference to the normalized image.

Returns
a const referent to m_normIm.

Definition at line 284 of file imageXCorrDiscrete.hpp.

◆ operator()()

template<class ccImT >
template<class imT >
int mx::improc::imageXCorrDiscrete< ccImT >::operator() ( Scalar xShift,
Scalar yShift,
const imT &  im 
)

Conduct the cross correlation to a specified tolerance.

Returns
0 on success
-1 on error
Parameters
[out]xShiftthe x shift of im w.r.t. im0, in pixels
[out]yShiftthe y shift of im w.r.t. im0, in pixels
[in]imthe image to cross-correlate with the reference

Definition at line 303 of file imageXCorrDiscrete.hpp.

References mx::improc::HCI::imageMean, and mx::improc::imageVariance().

◆ refIm() [1/2]

template<class ccImT >
const ccImT & mx::improc::imageXCorrDiscrete< ccImT >::refIm

Get a reference to the reference image.

Returns
a const referent to m_refIm.

Definition at line 278 of file imageXCorrDiscrete.hpp.

◆ refIm() [2/2]

template<class ccImT >
int mx::improc::imageXCorrDiscrete< ccImT >::refIm ( const ccImT im0)

Set the reference image.

Normalizes the reference image by mean subtraction and variance division. Applies the mask first if supplied.

Returns
0 on success
-1 on error

Definition at line 252 of file imageXCorrDiscrete.hpp.

References mx::improc::HCI::imageMean, and mx::improc::imageVariance().

Referenced by SCENARIO().

◆ resize()

template<class _ccImT >
int mx::improc::imageXCorrDiscrete< _ccImT >::resize ( int  nrows,
int  ncols 
)

Set the size of the cross-correlation images.

This resizes all working memory.

Returns
0 on success
-1 on error
Parameters
[in]nrowsthe number of rows in the images to register
[in]ncolsthe number of columns in the images to register

◆ tol() [1/2]

template<class ccImT >
ccImT::Scalar mx::improc::imageXCorrDiscrete< ccImT >::tol

Get the tolerance of the interpolated-magnified image, in pixels.

Returns
the current value of m_tol.

Definition at line 219 of file imageXCorrDiscrete.hpp.

◆ tol() [2/2]

template<class ccImT >
void mx::improc::imageXCorrDiscrete< ccImT >::tol ( Scalar  nt)

Set the tolerance of the interpolated-magnified image, in pixels.

Parameters
[in]ntThe new value of the interpolation tolerance.

Definition at line 226 of file imageXCorrDiscrete.hpp.

Member Data Documentation

◆ m_ccIm

template<class _ccImT >
ccImT mx::improc::imageXCorrDiscrete< _ccImT >::m_ccIm

The cross-correlation image.

Definition at line 83 of file imageXCorrDiscrete.hpp.

◆ m_magIm

template<class _ccImT >
ccImT mx::improc::imageXCorrDiscrete< _ccImT >::m_magIm

The magnified image, used if m_peakMethod == xcorrPeakMethod::interp.

Definition at line 85 of file imageXCorrDiscrete.hpp.

◆ m_magSize

template<class _ccImT >
Scalar mx::improc::imageXCorrDiscrete< _ccImT >::m_magSize {0}

Magnified size of the ccIm when using interp. Set as function of m_tol and m_maxLag.

Definition at line 95 of file imageXCorrDiscrete.hpp.

◆ m_maskIm

template<class _ccImT >
ccImT mx::improc::imageXCorrDiscrete< _ccImT >::m_maskIm

Mask image to use, may be needed for proper normalization even if refIm has 0 mask applied.

Definition at line 77 of file imageXCorrDiscrete.hpp.

◆ m_maxLag

template<class _ccImT >
int mx::improc::imageXCorrDiscrete< _ccImT >::m_maxLag {0}

The maximum lag to consider in the initial cross-correlation.

Definition at line 91 of file imageXCorrDiscrete.hpp.

◆ m_normIm

template<class _ccImT >
ccImT mx::improc::imageXCorrDiscrete< _ccImT >::m_normIm

The normalized image.

Definition at line 81 of file imageXCorrDiscrete.hpp.

◆ m_refIm

template<class _ccImT >
ccImT mx::improc::imageXCorrDiscrete< _ccImT >::m_refIm

The normalized reference image.

Definition at line 75 of file imageXCorrDiscrete.hpp.

◆ m_tol

template<class _ccImT >
Scalar mx::improc::imageXCorrDiscrete< _ccImT >::m_tol {0.1}

The tolerance of the interpolated-magnified image, in pixels.

Definition at line 93 of file imageXCorrDiscrete.hpp.


The documentation for this class was generated from the following file: