mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
|
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... | |
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.
realT | the real floating-point type for calculations |
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().
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.
imageT | the eigen-like array type of the combined image |
imageT1 | the eigen-like array type of image 1 |
imageT2 | the eigen-like array type of mask 1 |
imageT3 | the eigen-like array type of image 2 |
imageT4 | the eigen-like array type of mask 2 |
[out] | combo | the combined image. will be resized. |
[in] | im1 | the first image |
[in] | mask1 | the mask for the first image |
[in] | im2 | the second image |
[in] | mask2 | the mask for the second image |
Definition at line 267 of file imageUtils.hpp.
References mx::astro::constants::c().
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.
[out] | x | the x coordinate of the center of light [pixels] |
[out] | y | the y coordinate of hte center of light [pixels] |
[in] | im | the image to centroid |
Definition at line 163 of file imageUtils.hpp.
Referenced by mx::improc::circleOuterpix(), and SCENARIO().
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.
[out] | x | the x-position of the maximum, in pixels of the input image |
[out] | y | the 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] | magIm | the magnified image. This is used as working memory, will be resized. |
[in] | im | the image to find the maximum of |
Definition at line 239 of file imageUtils.hpp.
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.
[out] | x | the x-position of the maximum, in pixels of the input image |
[out] | y | the 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] | magIm | the magnified image. This is used as working memory, will be resized. |
[in] | im | the image to find the maximum of |
[in] | trans | the transform to use for interpolation |
Definition at line 202 of file imageUtils.hpp.
References mx::improc::imageMagnify().
imageT::Scalar mx::improc::imageMean | ( | imageT & | im | ) |
Calculate the mean value of an image.
[in] | im | the image of which to calculate the mean |
Definition at line 116 of file imageUtils.hpp.
References mx::astro::constants::c().
imageT::Scalar mx::improc::imageVariance | ( | imageT & | im, |
typename imageT::Scalar | mean | ||
) |
Calculate the variance of an image w.r.t. a given value.
[in] | im | the image of which to calculate the variance |
[in] | mean | the 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().
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
[out] | dest | the address of the first pixel in the destination image |
[in] | src | the address of the first pixel in the source image |
[in] | width | the width in pixels of size szof |
[in] | height | the height in pixels of size szof |
[in] | szof | the size in bytes of a one pixel |
Definition at line 35 of file imageUtils.cpp.
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.
[out] | dest | the address of the first pixel in the destination image |
[in] | src | the address of the first pixel in the source image |
[in] | width | the width in pixels of size szof |
[in] | height | the height in pixels of size szof |
[in] | szof | the size in bytes of a one pixel |
Definition at line 60 of file imageUtils.cpp.
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
[out] | dest | the address of the first pixel in the destination image |
[in] | src | the address of the first pixel in the source image |
[in] | width | the width in pixels of size szof |
[in] | height | the height in pixels of size szof |
[in] | szof | the size in bytes of a one pixel |
Definition at line 45 of file imageUtils.cpp.
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.
[out] | dest | the address of the first pixel in the destination image |
[in] | src | the address of the first pixel in the source image |
[in] | width | the width in pixels of size szof |
[in] | height | the height in pixels of size szof |
[in] | szof | the size in bytes of a one pixel |
Definition at line 133 of file imageUtils.cpp.
int mx::improc::reflectImageCoords | ( | int & | x1, |
int & | y1, | ||
int | x0, | ||
int | y0, | ||
realT | xc, | ||
realT | yc | ||
) |
Reflect pixel coordinates across the given center pixel.
[out] | x1 | the reflected x coordinate |
[out] | y1 | the reflected y coordinate |
[in] | x0 | the input x coordinate |
[in] | y0 | the input y coordinate |
[in] | xc | the center pixel x coordinate |
[in] | yc | the center pixel y coordinate |
Definition at line 46 of file imageUtils.hpp.
Referenced by mx::improc::reflectImageIndices().
void mx::improc::zeroNaNCube | ( | cubeT & | imc | ) |
Zero any NaNs in an image cube.
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().
void mx::improc::zeroNaNs | ( | imageT & | im | ) |
Zero any NaNs in an image.
im | [in.out] image which will have any NaN pixels set to zero |
Definition at line 85 of file imageUtils.hpp.
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.
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().