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

Functions for transforming images by rotating, translating, and magnifying.

Classes

struct  mx::improc::bilinearTransform< _arithT >
 Transformation by bi-linear interpolation. More...
 
struct  mx::improc::cubicConvolTransform< _arithT >
 Transformation by cubic convolution interpolation. More...
 

Typedefs

typedef bilinearTransform< float > mx::improc::bilinearTransf
 Typedef for bilinearTransform with single precision. More...
 
typedef bilinearTransform< double > mx::improc::bilinearTransd
 Typedef for bilinearTransform with double precision. More...
 
typedef cubicConvolTransform< float > mx::improc::cubicConvolTransf
 Typedef for cubicConvolTransform with single precision. More...
 
typedef cubicConvolTransform< double > mx::improc::cubicConvolTransd
 Typedef for cubicConvolTransform with double precision. More...
 
template<typename transformT , typename arrT , typename arrT2 , typename floatT >
void mx::improc::imageRotate (arrT &transim, const arrT2 &im, floatT dq, transformT trans)
 Rotate an image represented as an eigen array. More...
 
template<typename outputArrT , typename inputArrT >
void mx::improc::imageShiftWP (outputArrT &out, inputArrT &in, int dx, int dy, bool wrap=true)
 Shift an image by whole pixels with (optional) wrapping. More...
 
template<typename outputArrT , typename inputArrT , typename scaleArrT >
void mx::improc::imageShiftWPScale (outputArrT &out, inputArrT &in, scaleArrT &scale, int dx, int dy)
 Shift an image by whole pixels, wrapping around, with a scaling image applied to the shifted image. More...
 
template<typename arrOutT , typename arrInT , typename floatT1 , typename floatT2 , typename transformT >
void mx::improc::imageShift (arrOutT &transim, const arrInT &im, floatT1 dx, floatT2 dy, transformT trans)
 Shift an image. More...
 
template<typename arrOutT , typename arrInT , typename transformT >
void mx::improc::imageMagnify (arrOutT &transim, const arrInT &im, transformT trans)
 Magnify an image. More...
 
template<typename arrOutT , typename arrInT >
void mx::improc::imageMagnify (arrOutT &transim, const arrInT &im)
 Magnify an image with the cubic convolution interpolator. More...
 
template<typename imageOutT , typename imageInT >
int mx::improc::imageRebinSum (imageOutT &imout, const imageInT &imin, bool mean=false)
 Re-bin an image using the sum, reducing its size while conserving the total flux. More...
 
template<typename imageOutT , typename imageInT >
int mx::improc::imageRebinSum (imageOutT &imout, int &xMax, int &yMax, typename imageOutT::Scalar &pMax, const imageInT &imin, bool mean=false)
 Re-bin an image using the sum, reducing its size while conserving the total flux. Records the value and position of the re-binned max pixel. More...
 
template<typename imageOutT , typename imageInT >
int mx::improc::imageRebinMean (imageOutT &imout, const imageInT &imin)
 Re-bin an image using the mean. More...
 
template<typename imageOutT , typename imageInT >
int mx::improc::imageRebinMean (imageOutT &imout, int &xMax, int &yMax, typename imageOutT::Scalar &pMax, const imageInT &imin, bool mean=false)
 Re-bin an image using the mean. Records the value and position of the re-binned max pixel. More...
 
template<typename imageOutT , typename imageInT >
int mx::improc::imageRebinMeanReject (imageOutT &imout, const imageInT &imin)
 Re-bin an image, takes the mean with a min/max rejection. More...
 
template<typename imageOutT , typename imageInT >
int mx::improc::imageRebinMeanReject (imageOutT &imout, int &xMax, int &yMax, typename imageOutT::Scalar &pMax, const imageInT &imin)
 Re-bin an image, takes the mean with a min/max rejection. Records the value and position of the re-binned max pixel. More...
 
template<typename imageOutT , typename imageInT >
void mx::improc::imageDownSample (imageOutT &imout, const imageInT &imin)
 Down-sample an image, reducing its size while conserving the total flux. More...
 

Typedef Documentation

◆ bilinearTransd

Typedef for bilinearTransform with double precision.

Definition at line 73 of file imageTransforms.hpp.

◆ bilinearTransf

Typedef for bilinearTransform with single precision.

Definition at line 68 of file imageTransforms.hpp.

◆ cubicConvolTransd

Typedef for cubicConvolTransform with double precision.

Definition at line 178 of file imageTransforms.hpp.

◆ cubicConvolTransf

Typedef for cubicConvolTransform with single precision.

Definition at line 173 of file imageTransforms.hpp.

Function Documentation

◆ imageDownSample()

template<typename imageOutT , typename imageInT >
void mx::improc::imageDownSample ( imageOutT &  imout,
const imageInT &  imin 
)

Down-sample an image, reducing its size while conserving the total flux.

If the old size is an integer multiple of the new size, this is just a re-bin. If not an integer multiple, the image is interpolated after performing the closest re-bin, and then re-normalized to conserve flux.

Todo:
Allow selection of interpolator, providing a default version.

Definition at line 851 of file imageTransforms.hpp.

Referenced by mx::AO::sim::pywfsSlopeReconstructor< _floatT >::calcMeasurement(), and mx::AO::sim::ccdDetector< _realT >::exposeImage().

◆ imageMagnify() [1/2]

template<typename arrOutT , typename arrInT >
void mx::improc::imageMagnify ( arrOutT &  transim,
const arrInT &  im 
)

Magnify an image with the cubic convolution interpolator.

Uses the cubic convolution interpolator to magnify the input image to the size of the output image.

This is a wrapper for imageMagnify with the transform type specified.

Template Parameters
arrOutTis the eigen array type of the output.
arrInTis the eigen array type of the input.

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

Parameters
[out]transimcontains the magnified image. Must be pre-allocated.
[in]imis the image to be magnified.

Definition at line 652 of file imageTransforms.hpp.

◆ imageMagnify() [2/2]

template<typename arrOutT , typename arrInT , typename transformT >
void mx::improc::imageMagnify ( arrOutT &  transim,
const arrInT &  im,
transformT  trans 
)

Magnify an image.

Uses the given transformation type to magnify the input image to the size of the output image.

Here we assume that the image center is the mxlib standard:

x_center = 0.5*(im.rows()-1);
y_center = 0.5*(im.cols()-1);

Some care is necessary to prevent magnification from shifting the image with respect to this center. The main result is that the magnification factors (which can be different in x and y) are defined thus:

x_mag = (transim.rows()-1.0) / (im.rows()-1.0);
y_mag = (transim.cols()-1.0) / (im.cols()-1.0);

Example:

im1.resize(512,512);
//add image to im1
im2.resize(1024,1024);
imageMagnify(im2,im1, cubicConvolTransform<double>());
void imageMagnify(arrOutT &transim, const arrInT &im, transformT trans)
Magnify an image.

In this exmple, the image in im1 will be magnified by 1023.0/511.0 = 2.002x and placed in im2.

This transform function does not handle edges. If treatment of edges is desired, you must pad the input image using the desired strategy before calling this function. Note that the padded-size of the input image will affect the magnification factor.

Template Parameters
arrOutTis the eigen array type of the output.
arrInTis the eigen array type of the input.
transformTspecifies the transformation to use.
Parameters
[out]transimcontains the magnified image. Must be pre-allocated.
[in]imis the image to be magnified.
[in]transis the transformation to use

Definition at line 561 of file imageTransforms.hpp.

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

◆ imageRebinMean() [1/2]

template<typename imageOutT , typename imageInT >
int mx::improc::imageRebinMean ( imageOutT &  imout,
const imageInT &  imin 
)

Re-bin an image using the mean.

This is a wrapper for imageRebinSum with mean=true.

Parameters
[out]imoutthe re-binned image. Must be allocated to size which is an integer factor smaller than imin.
[in]iminthe image to rebin

Definition at line 730 of file imageTransforms.hpp.

References mx::improc::imageRebinSum().

◆ imageRebinMean() [2/2]

template<typename imageOutT , typename imageInT >
int mx::improc::imageRebinMean ( imageOutT &  imout,
int &  xMax,
int &  yMax,
typename imageOutT::Scalar &  pMax,
const imageInT &  imin,
bool  mean = false 
)

Re-bin an image using the mean. Records the value and position of the re-binned max pixel.

This is a wrapper for imageRebinSum with mean=true.

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

Parameters
[out]imoutthe re-binned image. Must be allocated to size which is an integer factor smaller than imin.
[out]xMaxthe x-locatioin of the max pixel
[out]yMaxthe y-locatioin of the max pixel
[out]pMaxthe value of the max pixel
[in]iminthe image to rebin
[in]meanif true the output is the mean rather than the sum.

Definition at line 743 of file imageTransforms.hpp.

References mx::improc::imageRebinSum().

◆ imageRebinMeanReject() [1/2]

template<typename imageOutT , typename imageInT >
int mx::improc::imageRebinMeanReject ( imageOutT &  imout,
const imageInT &  imin 
)

Re-bin an image, takes the mean with a min/max rejection.

The mean is calculated after rejecting the minimuma and maximum value.

Parameters
[out]imoutthe re-binned image. Must be allocated to size which is an integer factor smaller than imin.
[in]iminthe image to rebin

Definition at line 758 of file imageTransforms.hpp.

References mx::astro::constants::k().

◆ imageRebinMeanReject() [2/2]

template<typename imageOutT , typename imageInT >
int mx::improc::imageRebinMeanReject ( imageOutT &  imout,
int &  xMax,
int &  yMax,
typename imageOutT::Scalar &  pMax,
const imageInT &  imin 
)

Re-bin an image, takes the mean with a min/max rejection. Records the value and position of the re-binned max pixel.

The mean is calculated after rejecting the minimuma and maximum value.

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

Parameters
[out]imoutthe re-binned image. Must be allocated to size which is an integer factor smaller than imin.
[out]xMaxthe x-locatioin of the max pixel
[out]yMaxthe y-locatioin of the max pixel
[out]pMaxthe value of the max pixel
[in]iminthe image to rebin

Definition at line 797 of file imageTransforms.hpp.

References mx::astro::constants::k().

◆ imageRebinSum() [1/2]

template<typename imageOutT , typename imageInT >
int mx::improc::imageRebinSum ( imageOutT &  imout,
const imageInT &  imin,
bool  mean = false 
)

Re-bin an image using the sum, reducing its size while conserving the total flux.

Optionally this can be the mean instead of the sum filter, in which case total flux is not conserved.

Parameters
[out]imoutthe re-binned image. Must be allocated to size which is an integer factor smaller than imin.
[in]iminthe image to rebin
[in]meanif true the output is the mean rather than the sum.

Definition at line 663 of file imageTransforms.hpp.

◆ imageRebinSum() [2/2]

template<typename imageOutT , typename imageInT >
int mx::improc::imageRebinSum ( imageOutT &  imout,
int &  xMax,
int &  yMax,
typename imageOutT::Scalar &  pMax,
const imageInT &  imin,
bool  mean = false 
)

Re-bin an image using the sum, reducing its size while conserving the total flux. Records the value and position of the re-binned max pixel.

Optionally this can be the mean instead of the sum filter, in which case total flux is not conserved.

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

Parameters
[out]imoutthe re-binned image. Must be allocated to size which is an integer factor smaller than imin.
[out]xMaxthe x-locatioin of the max pixel
[out]yMaxthe y-locatioin of the max pixel
[out]pMaxthe value of the max pixel
[in]iminthe image to rebin
[in]meanif true the output is the mean rather than the sum.

Definition at line 690 of file imageTransforms.hpp.

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

◆ imageRotate()

template<typename transformT , typename arrT , typename arrT2 , typename floatT >
void mx::improc::imageRotate ( arrT &  transim,
const arrT2 &  im,
floatT  dq,
transformT  trans 
)

Rotate an image represented as an eigen array.

Uses the given transformation type to rotate an image.

Template Parameters
transformTspecifies the transformation to use [will be resolved by compiler]
arrTis the eigen array type of the output [will be resolved by compiler]
arrT2is the eigen array type of the input [will be resolved by compiler]
floatTis a floating point type [will be resolved by compiler in most cases]
Parameters
[out]transimThe rotated image. Must be pre-allocated.
[in]imThe image to be rotated.
[in]dqthe angle, in radians, by which to rotate in the c.c.w. direction
[in]transis the transformation to use

Definition at line 195 of file imageTransforms.hpp.

Referenced by mx::improc::ADIobservation< _realT, _derotFunctObj >::derotate(), and mx::improc::rotateMask().

◆ imageShift()

template<typename arrOutT , typename arrInT , typename floatT1 , typename floatT2 , typename transformT >
void mx::improc::imageShift ( arrOutT &  transim,
const arrInT &  im,
floatT1  dx,
floatT2  dy,
transformT  trans 
)

Shift an image.

Uses the given transformation type to shift an image such that objects move by (dx,dy) pixels.
The shift is such that an object located at the coordinate (-dx, -dy) from the center of the image will be moved to the center of the image. So to move an object located 2 pixels right (dx) and 2 pixels up (dy) from the center to be at the center, use dx = -2, dy = -2.

Note that this does not treat the edges of the image, determined by the buffer width (lbuff) of the kernel and the size of shift. If you wish to treat the edges, you must pad the image by at least lbuff+abs(shift) pixels in each direction, and implement a strategy (zeros, mirror, wrap) prior to calling this function.

Template Parameters
arrOutTis the Eigen-like array type of the output [will be resolved by compiler]
arrInTis the Eigen-like array type of the input [will be resolved by compiler]
floatT1is a floating point type [will be resolved by compiler]
floatT2is a floating point type [will be resolved by compiler]
transformTspecifies the transformation to use [will be resolved by compiler]
Test:
Scenario: Verify direction and accuracy of various image shifts [test doc]
Parameters
[out]transimWill contain the shifted image. Will be allocated.
[in]imthe image to be shifted.
[in]dxthe amount to shift in the x direction
[in]dythe amount to shift in the y direction
[in]transtrans is the transformation to use

Definition at line 453 of file imageTransforms.hpp.

References mx::improc::imageShiftWP().

Referenced by SCENARIO(), mx::AO::sim::turbLayer< _aoSystemT >::shift(), and mx::AO::sim::turbLayer< _aoSystemT >::shiftRandom().

◆ imageShiftWP()

template<typename outputArrT , typename inputArrT >
void mx::improc::imageShiftWP ( outputArrT &  out,
inputArrT &  in,
int  dx,
int  dy,
bool  wrap = true 
)

Shift an image by whole pixels with (optional) wrapping.

The output image can be smaller than the input image, in which case the wrapping (if enabled) still occurs for the input image, but only output images worth of pixels are actually shifted. This is useful, for instance, when propagating large turbulence phase screens where one only needs a small section at a time.

Template Parameters
outputArrTis the eigen array type of the output [will be resolved by compiler]
inputArrTis the eigen array type of the input [will be resolved by compiler]
Test:
Scenario: Verify direction and accuracy of various image shifts [test doc]
Parameters
[out]outcontains the shifted image. Must be pre-allocated, but can be smaller than the in array.
[in]inthe image to be shifted.
[in]dxthe amount to shift in the x direction
[in]dythe amount to shift in the y direction
[in]wrapflag controlling whether or not to wrap around

Definition at line 296 of file imageTransforms.hpp.

Referenced by mx::improc::imageShift(), mx::improc::imageXCorrFFT< _ccImT >::refIm(), mx::AO::sim::turbLayer< _aoSystemT >::shift(), and mx::AO::sim::turbLayer< _aoSystemT >::shiftRandom().

◆ imageShiftWPScale()

template<typename outputArrT , typename inputArrT , typename scaleArrT >
void mx::improc::imageShiftWPScale ( outputArrT &  out,
inputArrT &  in,
scaleArrT &  scale,
int  dx,
int  dy 
)

Shift an image by whole pixels, wrapping around, with a scaling image applied to the shifted image.

The output image can be smaller than the input image, in which case the wrapping still occurs for the input image, but only output images worth of pixels are actually shifted. This is useful, for instance, when propagating large turbulence phase screens where one only needs a small section at a time.

The scaling is applied to the output image. The scale image must be the same size as the output image.

Template Parameters
outputArrTis the eigen array type of the output [will be resolved by compiler]
inputArrTis the eigen array type of the input [will be resolved by compiler]
scaleArrTis the eigen array type of the scale image [will be resolved by compiler]
Parameters
[out]outcontains the shifted image. Must be pre-allocated, but can be smaller than the in array.
[in]inthe image to be shifted.
[in]scaleimage of scale values applied per-pixel to the output (shifted) image, same size as out
[in]dxthe amount to shift in the x direction
[in]dythe amount to shift in the y direction

Definition at line 389 of file imageTransforms.hpp.