27#ifndef imageXCorrFFT_hpp
28#define imageXCorrFFT_hpp
79template <
class _realImageT>
85 typedef typename _realImageT::Scalar
realT;
94 typedef realT fftOutT;
526 template <
class im0T,
class imT>
537template <
class realImageT>
543template <
class realImageT>
549template <
class realImageT>
555template <
class realImageT>
575template <
class realImageT>
581template <
class realImageT>
587template <
class realImageT>
593template <
class realImageT>
625 m_ftWorkIn.resize( 0, 0 );
698template <
class realImageT>
704template <
class realImageT>
715template <
class realImageT>
721template <
class realImageT>
727template <
class realImageT>
736template <
class realImageT>
742template <
class realImageT>
748template <
class realImageT>
759template <
class realImageT>
765template <
class realImageT>
771template <
class realImageT>
780template <
class realImageT>
786template <
class realImageT>
792template <
class realImageT>
802template <
class realImageT>
808template <
class realImageT>
841 im0 = ( im - m ) / sqrt( v );
876 m_ftWork = im0.template cast<complexT>();
884 for(
int c = 0; c <
m_ftIm0.cols(); ++c )
886 for(
int r = 0; r <
m_ftIm0.rows(); ++r )
907template <
class realImageT>
913template <
class realImageT>
919template <
class realImageT>
925template <
class realImageT>
932template <
class realImageT>
938template <
class realImageT>
944template <
class realImageT>
958template <
class realImageT>
961 if( xpm != m_peakMethod )
971template <
class realImageT>
977template <
class realImageT>
983template <
class realImageT>
989template <
class realImageT>
995template <
class realImageT>
1001template <
class realImageT>
1007template <
class realImageT>
1013template <
class realImageT>
1051 m_magIm.maxCoeff( &xLag0, &yLag0 );
1056 x0 = ( m_fitter.x0() + x0 );
1057 y0 = ( m_fitter.y0() + y0 );
1058 xcPeak = m_fitter.G();
1069 xcPeak =
m_magIm.maxCoeff( &x, &y );
1070 x0 = ( x * ( 1.0 /
m_mag ) + x0 );
1071 y0 = ( y * ( 1.0 /
m_mag ) + y0 );
1073 else if(
m_peakMethod == xcorrPeakMethod::centerOfLight )
1085 else if(
m_peakMethod == xcorrPeakMethod::mftOversamp )
1088 m_ccIm.maxCoeff( &x, &y );
1127 xcPeak =
m_magIm.maxCoeff( &xf, &yf );
1138 xcPeak =
m_ccIm.maxCoeff( &x, &y );
1152template <
class realImageT>
1161 if( im.rows() !=
m_rows )
1166 if( im.cols() !=
m_cols )
1208 m_ftWorkIn =
m_normIm.template cast<complexT>();
1237 findPeak( xShift, yShift, xcPeak );
1242template <
class realImageT>
1243template <
class im0T,
class imT>
1246 setReference( im0 );
1247 return operator()( xShift, yShift, xcPeak, im );
Augments an exception with the source file and line.
realT padFactor()
Get the padding factor.
int m_cols
The number of columns in the images.
realImageT m_refACIm
The auto-correlation image of the reference.
int m_rowsPadded
The number of rows in the padded CC.
int colsPadded()
Get the number of rows in the padded cross-correlation.
eigenImage< complexT > complexArrayT
Complex eigen array type with Scalar==complexT.
int m_maxLag
The maximum lag to consider in the initial cross-correlation. Default is 5.
void findPeak(realT &xShift, realT &yShift, realT &xcPeak)
complexArrayT m_mtWorkPadded
Working memory for the MFT for xcorrPeakMethod::mftOversamp.
bool haveMask()
Get the value of the haveMask flag.
bool haveWindow()
Get the value of the haveWindow flag.
int m_rows
The number of rows in the images.
math::ft::fftT< fftOutT, fftInT, 2 > m_fft_fwd
FFT object for the forward transform.
const realImageT & maskIm()
Get a reference to the mask image.
const realImageT & refIm()
Get a reference to the reference image.
realImageT m_refIm
The normalized reference image.
bool haveRefMask()
Get the value of the haveRefMask flag.
int resize(int nrows, int ncols, realT padFactor)
Set the size of the cross-correlation problem based on input image size.
int maxLag()
Get the current maximum lag.
realImageT m_magIm
The magnified image, used if m_peakMethod == xcorrPeakMethod::interpPeak.
std::complex< realT > complexT
Complex floating point type.
realT m_padFactor
The padding factor for the CC.
int operator()(realT &xShift, realT &yShift, realT &xcPeak, const imT &im)
Conduct the cross correlation to a specified tolerance.
bool m_haveMask
Flag indicating that a mask has been provided.
complexArrayT m_ftWorkPadded
Working memory for the padded inverse FFT input.
complexArrayT m_ftIm0
Working memory for the FT of the reference image.
complexArrayT m_ftWork
Working memory for the FFT.
const realImageT & refWinIm()
Get a reference to the reference window image.
void maxLag(int ml)
Set the maximum lag.
bool haveRefWindow()
Get the value of the haveRefWindow flag.
math::ft::mftT< complexT, complexT, 2 > m_mft_bwd
const realImageT & refACIm()
Get a reference to the reference auto-correlation image.
void tol(realT nt)
Set the tolerance of the interpolated-magnified image, in pixels.
const realImageT & ccIm()
Get a reference to the cross correlation image.
complexArrayT m_ftWorkPaddedOut
Working memory for the FFT and MFT output.
int m_colsPadded
The number of columns in the padded CC.
int rowsPadded()
Get the number of rows in the padded cross-correlation.
realT refX0()
Get the x-shift of the reference image to itself.
imageXCorrFFT()
Default c'tor.
bool refValid()
Get the value of the reference valid flag.
math::ft::fftT< fftInT, fftOutT, 2 > m_fft_bwd
FFT object for the backward transform.
int refIm(const realImageT &im0, realT padFactor)
Set the reference image.
bool normalize()
Get the current value of the normalize flag.
realImageT m_refWinIm
Window image to use for the reference.
int padFactor(realT os)
Set the padding factor.
realT tol()
Get the tolerance of the interpolated-magnified image, in pixels.
const realImageT & refMaskIm()
Get a reference to the reference mask image.
bool m_haveRefWindow
Flag indicating that a window has been provided for the reference.
const realImageT & magIm()
Get a reference to the magnified image.
realT refY0()
Get the y-shift of the reference image to itself.
_realImageT::Scalar realT
the scalar type of the image type
bool m_haveRefMask
Flag indicating that a referece mask has been provided.
realImageT m_ccIm
The cross-correlation image.
realImageT m_winIm
Window image for the target image.
realImageT m_normIm
The normalized image.
int rows()
Get the number of rows in the input images.
bool m_haveWindow
Flag indicating that a window has been provided.
const realImageT & winIm()
Get a reference to the window image.
const realImageT & normIm()
Get a reference to the normalized image.
xcorrPeakMethod m_peakMethod
The peak finding method to use.
int cols()
Get the number of columns in the input images.
_realImageT realImageT
the Eigen-like array type used for image processing
Class to manage fitting a 2D Gaussian to data via the levmarInterface.
Tools for using the eigen library for image processing.
The Fast Fourier Transform interface.
Declares and defines the fftwEnvironment manager.
Tools for fitting Gaussians to data.
Fourier Transform Utilities.
Eigen::Array< scalarT, -1, -1 > eigenImage
Definition of the eigenImage type, which is an alias for Eigen::Array.
calcT imageVariance(imageT &im, calcT mn)
Calculate the variance of an image given its mean.
int imageCenterOfLight(typename imageT::Scalar &x, typename imageT::Scalar &y, const imageT &im)
Calculate the center of light of an image.
calcT imageMean(imageT &im)
Calculate the mean value of an image.
@ sizeerr
A size was invalid or calculated incorrectly.
@ invalidconfig
A config setting was invalid.
@ invalidarg
An argument was invalid.
error_t mxlib_error_report(const error_t &code, const std::string &expl, const std::source_location &loc=std::source_location::current())
Print a report to stderr given an mxlib error_t code and explanation and return the code.
void augmentR2CFFTOutput(eigenArrOutT &aout, eigenArrInT &ain)
void padR2CFFTOutput(eigenArrOutT &aout, eigenArrInT &ain)
Add padding to the output of a real-to-complex (R2C) FFT.
void padC2CFFTOutput(eigenArrOutT &aout, eigenArrInT &ain)
Add padding to the output of a complex-to-complex (C2C) FFT.
@ backward
Specifies the backward transform.
@ forward
Specifies the forward transform.
xcorrPeakMethod
Methods for finding the cross-correlation peak.
Header for the image processing utilities.
CRTP base class to register images.
The Matrix Fourier Transform interface.
Declarations of some libarary wide utilities.