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

Useful functions for working with images

Classes

class  mx::improc::sourceFinder< _realT >
 Find stars in an image by SNR thresholding. More...
 

Functions

template<typename realT >
int mx::improc::circleOuterpix (realT &x0, realT &y0, realT &avgr0, realT &avgx, realT &avgy, realT &avgr, eigenImage< realT > &circ, const eigenImage< realT > &masked)
 Find the center and the outermost pixels of a circular mask, giving an estimate of the radius. More...
 
template<typename realT >
int mx::improc::reflectImageCoords (int &x1, int &y1, int x0, int y0, realT xc, realT yc)
 Reflect pixel coordinates across the given center pixel. More...
 
template<class imageT , typename valueT >
void mx::improc::zeroNaNs (imageT &im, valueT val)
 Zero any NaNs in an image. More...
 
template<class imageT >
void mx::improc::zeroNaNs (imageT &im)
 Zero any NaNs in an image. More...
 
template<class cubeT >
void mx::improc::zeroNaNCube (cubeT &imc)
 Zero any NaNs in an image cube. More...
 
template<class imageT >
imageT::Scalar mx::improc::imageMean (imageT &im)
 Calculate the mean value of an image. More...
 
template<class imageT >
imageT::Scalar mx::improc::imageVariance (imageT &im, typename imageT::Scalar mean)
 Calculate the variance of an image w.r.t. a given value. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
void * mx::improc::imcpy (void *dest, void *src, size_t width, size_t height, size_t szof)
 Copy one image to another, with no transformation. More...
 
void * mx::improc::imcpy_flipUD (void *dest, void *src, size_t width, size_t height, size_t szof)
 Copy one image to another, flipping up-down. More...
 
void * mx::improc::imcpy_flipLR (void *dest, void *src, size_t width, size_t height, size_t szof)
 Copy one image to another, flipping left-right. More...
 
void * mx::improc::imcpy_flipUDLR (void *dest, void *src, size_t width, size_t height, size_t szof)
 Copy one image to another, flipping up-down and left-right. More...
 

Function Documentation

◆ circleOuterpix()

template<typename realT >
int mx::improc::circleOuterpix ( realT &  x0,
realT &  y0,
realT &  avgr0,
realT &  avgx,
realT &  avgy,
realT &  avgr,
eigenImage< realT > &  circ,
const eigenImage< realT > &  masked 
)

Find the center and the outermost pixels of a circular mask, giving an estimate of the radius.

Takes a 1/0 mask of a filled circle or annulus, and calculates the center coordinate by center-of-light, then finds the outermost 1 pixel in each row and column. Calculates the average radius of these pixels w.r.t. to the c.o.l. coords, as well as w.r.t. the average coords of the outer pixels themselves.

Also produces an image containing the outer pixels.

Returns
0 on success
Template Parameters
realTthe real floating-point type for calculations
Parameters
y0< [out] x coord of center of the mask by center-of-light
avgr0< [out] y coord of center of the mask by center-of-light
avgx< [out] average radius of edge pixels w.r.t. center-of-light
avgy< [out] x coord of center of the mask by average edge pixel
avgr< [out] y coord of center of the mask by average edge pixel
circ< [out] average radius of edge pixels w.r.t. to average edge pixel
masked< [out] image showing the edge pixels with value 1, all other pixels 0. Resized. < [in] an image with a (roughly) circular mask of 1s

Definition at line 56 of file circleOuterpix.hpp.

References mx::improc::imageCenterOfLight(), and mx::math::pi().

◆ 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 267 of file imageUtils.hpp.

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

◆ 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 163 of file imageUtils.hpp.

Referenced by mx::improc::circleOuterpix(), 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 239 of file imageUtils.hpp.

◆ 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 202 of file imageUtils.hpp.

References mx::improc::imageMagnify().

◆ imageMean()

template<class imageT >
imageT::Scalar 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 116 of file imageUtils.hpp.

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

◆ imageVariance()

template<class imageT >
imageT::Scalar mx::improc::imageVariance ( imageT &  im,
typename imageT::Scalar  mean 
)

Calculate the variance of an image w.r.t. a given value.

Returns
the variance of the input image
Parameters
[in]imthe image of which to calculate the variance
[in]meanthe value to calculate the variance with respect to

Definition at line 139 of file imageUtils.hpp.

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

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

◆ imcpy()

void * mx::improc::imcpy ( void *  dest,
void *  src,
size_t  width,
size_t  height,
size_t  szof 
)

Copy one image to another, with no transformation.

This is merely memcpy

Returns
dest
Parameters
[out]destthe address of the first pixel in the destination image
[in]srcthe address of the first pixel in the source image
[in]widththe width in pixels of size szof
[in]heightthe height in pixels of size szof
[in]szofthe size in bytes of a one pixel

Definition at line 35 of file imageUtils.cpp.

◆ imcpy_flipLR()

void * mx::improc::imcpy_flipLR ( void *  dest,
void *  src,
size_t  width,
size_t  height,
size_t  szof 
)

Copy one image to another, flipping left-right.

Returns
dest
Parameters
[out]destthe address of the first pixel in the destination image
[in]srcthe address of the first pixel in the source image
[in]widththe width in pixels of size szof
[in]heightthe height in pixels of size szof
[in]szofthe size in bytes of a one pixel

Definition at line 60 of file imageUtils.cpp.

◆ imcpy_flipUD()

void * mx::improc::imcpy_flipUD ( void *  dest,
void *  src,
size_t  width,
size_t  height,
size_t  szof 
)

Copy one image to another, flipping up-down.

This is a reversed row-by-row memcpy

Returns
dest
Parameters
[out]destthe address of the first pixel in the destination image
[in]srcthe address of the first pixel in the source image
[in]widththe width in pixels of size szof
[in]heightthe height in pixels of size szof
[in]szofthe size in bytes of a one pixel

Definition at line 45 of file imageUtils.cpp.

◆ imcpy_flipUDLR()

void * mx::improc::imcpy_flipUDLR ( void *  dest,
void *  src,
size_t  width,
size_t  height,
size_t  szof 
)

Copy one image to another, flipping up-down and left-right.

Returns
dest
Parameters
[out]destthe address of the first pixel in the destination image
[in]srcthe address of the first pixel in the source image
[in]widththe width in pixels of size szof
[in]heightthe height in pixels of size szof
[in]szofthe size in bytes of a one pixel

Definition at line 133 of file imageUtils.cpp.

◆ reflectImageCoords()

template<typename realT >
int mx::improc::reflectImageCoords ( int &  x1,
int &  y1,
int  x0,
int  y0,
realT  xc,
realT  yc 
)

Reflect pixel coordinates across the given center pixel.

Parameters
[out]x1the reflected x coordinate
[out]y1the reflected y coordinate
[in]x0the input x coordinate
[in]y0the input y coordinate
[in]xcthe center pixel x coordinate
[in]ycthe center pixel y coordinate

Definition at line 46 of file imageUtils.hpp.

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

◆ zeroNaNCube()

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 93 of file imageUtils.hpp.

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

Referenced by mx::improc::HCIobservation< _realT >::readFiles(), mx::improc::HCIobservation< _realT >::readPSFSub(), and mx::improc::HCIobservation< _realT >::readRDIFiles().

◆ 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 85 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 67 of file imageUtils.hpp.

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