mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
|
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.
_ccImT | is 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 ccImT & | maskIm () |
Get a reference to the mask image. More... | |
int | refIm (const ccImT &im0) |
Set the reference image. More... | |
const ccImT & | refIm () |
Get a reference to the reference image. More... | |
const ccImT & | normIm () |
Get a reference to the normalized image. More... | |
const ccImT & | ccIm () |
Get a reference to the cross correlation image. More... | |
const ccImT & | magIm () |
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... | |
typedef _ccImT mx::improc::imageXCorrDiscrete< _ccImT >::ccImT |
the Eigen-like array type used for image processing
Definition at line 66 of file imageXCorrDiscrete.hpp.
typedef _ccImT::Scalar mx::improc::imageXCorrDiscrete< _ccImT >::Scalar |
the scalar type of the image type
Definition at line 67 of file imageXCorrDiscrete.hpp.
mx::improc::imageXCorrDiscrete< ccImT >::imageXCorrDiscrete |
Default c'tor.
Definition at line 195 of file imageXCorrDiscrete.hpp.
|
explicit |
Construct seeting maxLag.
Definition at line 200 of file imageXCorrDiscrete.hpp.
const ccImT & mx::improc::imageXCorrDiscrete< ccImT >::ccIm |
Get a reference to the cross correlation image.
Definition at line 290 of file imageXCorrDiscrete.hpp.
const ccImT & mx::improc::imageXCorrDiscrete< ccImT >::magIm |
Get a reference to the magnified image.
Definition at line 296 of file imageXCorrDiscrete.hpp.
const ccImT & mx::improc::imageXCorrDiscrete< ccImT >::maskIm |
Get a reference to the mask image.
Definition at line 246 of file imageXCorrDiscrete.hpp.
int mx::improc::imageXCorrDiscrete< ccImT >::maskIm | ( | const ccImT & | mask | ) |
Set the mask image.
[in] | mask | the new mask image |
Definition at line 237 of file imageXCorrDiscrete.hpp.
int mx::improc::imageXCorrDiscrete< ccImT >::maxLag |
Get the current maximum lag.
Definition at line 206 of file imageXCorrDiscrete.hpp.
void mx::improc::imageXCorrDiscrete< ccImT >::maxLag | ( | int | ml | ) |
Set the maximum lag.
[in] | ml | the new maximum lag |
Definition at line 212 of file imageXCorrDiscrete.hpp.
const ccImT & mx::improc::imageXCorrDiscrete< ccImT >::normIm |
Get a reference to the normalized image.
Definition at line 284 of file imageXCorrDiscrete.hpp.
int mx::improc::imageXCorrDiscrete< ccImT >::operator() | ( | Scalar & | xShift, |
Scalar & | yShift, | ||
const imT & | im | ||
) |
Conduct the cross correlation to a specified tolerance.
[out] | xShift | the x shift of im w.r.t. im0, in pixels |
[out] | yShift | the y shift of im w.r.t. im0, in pixels |
[in] | im | the image to cross-correlate with the reference |
Definition at line 303 of file imageXCorrDiscrete.hpp.
References mx::improc::HCI::imageMean, and mx::improc::imageVariance().
const ccImT & mx::improc::imageXCorrDiscrete< ccImT >::refIm |
Get a reference to the reference image.
Definition at line 278 of file imageXCorrDiscrete.hpp.
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.
Definition at line 252 of file imageXCorrDiscrete.hpp.
References mx::improc::HCI::imageMean, and mx::improc::imageVariance().
Referenced by SCENARIO().
int mx::improc::imageXCorrDiscrete< _ccImT >::resize | ( | int | nrows, |
int | ncols | ||
) |
Set the size of the cross-correlation images.
This resizes all working memory.
[in] | nrows | the number of rows in the images to register |
[in] | ncols | the number of columns in the images to register |
ccImT::Scalar mx::improc::imageXCorrDiscrete< ccImT >::tol |
Get the tolerance of the interpolated-magnified image, in pixels.
Definition at line 219 of file imageXCorrDiscrete.hpp.
void mx::improc::imageXCorrDiscrete< ccImT >::tol | ( | Scalar | nt | ) |
Set the tolerance of the interpolated-magnified image, in pixels.
[in] | nt | The new value of the interpolation tolerance. |
Definition at line 226 of file imageXCorrDiscrete.hpp.
ccImT mx::improc::imageXCorrDiscrete< _ccImT >::m_ccIm |
The cross-correlation image.
Definition at line 83 of file imageXCorrDiscrete.hpp.
ccImT mx::improc::imageXCorrDiscrete< _ccImT >::m_magIm |
The magnified image, used if m_peakMethod == xcorrPeakMethod::interp.
Definition at line 85 of file imageXCorrDiscrete.hpp.
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.
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.
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.
ccImT mx::improc::imageXCorrDiscrete< _ccImT >::m_normIm |
The normalized image.
Definition at line 81 of file imageXCorrDiscrete.hpp.
ccImT mx::improc::imageXCorrDiscrete< _ccImT >::m_refIm |
The normalized reference image.
Definition at line 75 of file imageXCorrDiscrete.hpp.
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.