NPL
Neurological Programs and Libraries
ndarray_utils.h File Reference
#include "ndarray.h"
#include "npltypes.h"
#include "basic_functions.h"
#include <Eigen/Dense>
#include <memory>
#include <list>
#include <unordered_set>

Go to the source code of this file.

Namespaces

 npl
 

Functions

std::unordered_set< int64_t > npl::getLabels (ptr< const NDArray > in)
 Produces a std::unordered_set of labels within a labelmap. More...
 
bool npl::comparable (const NDArray *left, const NDArray *right, bool *elL=NULL, bool *elR=NULL)
 Returns whether two NDArrays have the same dimensions, and therefore can be element-by-element compared/operated on. elL is set to true if left is elevatable to right (ie all dimensions match or are missing or are unary). elR is the same but for the right. More...
 
ptr< NDArray > npl::derivative (ptr< const NDArray > in)
 Computes the derivative of the image. Computes all directional derivatives of the input image and the output image will have 1 higher dimension with derivative of 0 in the first volume 1 in the second and so on. More...
 
ptr< NDArray > npl::derivative (ptr< const NDArray > in, size_t dir)
 Computes the derivative of the image in the specified direction. More...
 
ptr< NDArray > npl::dilate (ptr< NDArray > in, size_t reps)
 Dilate an binary array repeatedly. More...
 
ptr< NDArray > npl::erode (ptr< NDArray > in, size_t reps)
 Erode an binary array repeatedly. More...
 
void npl::gaussianSmooth1D (ptr< NDArray > inout, size_t dim, double stddev)
 Smooths an image in 1 dimension. More...
 
void npl::shiftImageKern (ptr< NDArray > inout, size_t dd, double dist, double(*kern)(double, double)=npl::lanczosKern)
 Performs unidirectional shift in the direction of +dd, of distance (in units of pixels). Uses Lanczos interpolation. More...
 
void npl::shiftImageFFT (ptr< NDArray > inout, size_t dim, double dist, double(*window)(double, double)=npl::sincWindow)
 Performs unidirectional shift in the direction of +dd, of distance (in units of pixels), using FFT. More...
 
void npl::shearImageKern (ptr< NDArray > inout, size_t dim, size_t len, double *dist, double(*kern)(double, double)=npl::lanczosKern)
 Performs a shear on the image where the sheared dimension (dim) will be shifted depending on the index in other dimensions (dist). (in units of pixels). Uses Lanczos interpolation. More...
 
void npl::shearImageFFT (ptr< NDArray > inout, size_t dim, size_t len, double *dist, double(*window)(double, double)=npl::sincWindow)
 Performs a shear on the image where the sheared dimension (dim) will be shifted depending on the index in other dimensions (dist). (in units of pixels), using FFT. More...
 
int npl::shearDecompose (std::list< Eigen::Matrix3d > &bestshears, double Rx, double Ry, double Rz, double stepx=1, double stepy=1, double stepz=1)
 Decomposes a euler angle rotation using the rotation matrix made up of R = Rx*Ry*Rz. Note that this would be multiplying the input vector by Rz then Ry, then Rx. This does not support angles > PI/4. To do that, you should first do bulk rotation using 90 degree rotations (which requires not interpolation). More...
 
int npl::shearTest (double Rx, double Ry, double Rz, double sx=0, double sy=0, double sz=0)
 Tests shear results. If there is a solution (error is not NAN), then these should result small errors, so this checks that errors are small when possible. Note that the rotation matrix would be given by R = Rx*Ry*Rz. More...
 
ptr< NDArray > npl::linearRotate (double rx, double ry, double rz, ptr< const NDArray > in)
 Performs a rotation of the image first by rotating around z, then around y, then around x. (Rx*Ry*Rz) More...
 
void npl::rotateImageKern (ptr< NDArray > inout, double rx, double ry, double rz)
 Performs a rotation using 3D intperolation kernel (lanczos) More...
 
int npl::rotateImageShearKern (ptr< NDArray > inout, double rx, double ry, double rz, double(*kern)(double, double)=npl::lanczosKern)
 Performs a rotation using fourier shift and shears, using FFT for unidirectional shifts, using FFT. Rotation matrix R = Rx*Ry*Rz. More...
 
int npl::rotateImageShearFFT (ptr< NDArray > inout, double rx, double ry, double rz, double(*window)(double, double)=npl::sincWindow)
 Performs a rotation using fourier shift and shears, using FFT for unidirectional shifts, using FFT. Rotation matrix R = Rx*Ry*Rz. More...
 
ptr< NDArray > npl::pseudoPolar (ptr< const NDArray > in, size_t prdim)
 Computes the pseudopolar-gridded fourier transform on the input image, with prdim as the pseudo-radius direction. To sample the whole space you would need to call this once for each of the dimensions, or use the other function which does not take this argument, and returns a vector. More...
 
std::vector< ptr< NDArray > > npl::pseudoPolar (ptr< const NDArray > in)
 Computes the pseudopolar-gridded fourier transform on the input image returns a vector of pseudo-polar sampled image, one for each dimension as the pseudo-radius. More...
 
ptr< NDArray > npl::pseudoPolarZoom (ptr< const NDArray > inimg, size_t prdim)
 Computes the pseudopolar-gridded fourier transform on the input image, with prdim as the pseudo-radius direction. To sample the whole space you would need to call this once for each of the dimensions, or use the other function which does not take this argument, and returns a vector. This function skips the chirpz transform by interpolation-zooming. More...
 
void npl::fillCircle (ptr< NDArray > inout, double radius, double alpha)
 Sets the middle of the image += radius (in index space) to 1, everything else to 0. More...
 
void npl::fillLinear (ptr< NDArray > inout)
 Fills image with the linear index at each pixel. More...
 
void npl::fillZero (ptr< NDArray > inout)
 Fills image with the linear index at each pixel. More...
 
void npl::fillGaussian (ptr< NDArray > inout)
 Fills image with the linear index at each pixel. More...
 
ptr< NDArray > npl::concat (const vector< ptr< NDArray >> &images, size_t dir)
 Concatinates image in the direction specified by dir. So if dir is 0, and two images, sized [32, 32, 34] and [12, 32, 34] were passed in the input vector, then the output would be [44, 32, 34]. More...
 
ptr< NDArray > npl::concatElevate (const vector< ptr< NDArray >> &images)
 Concatinates images/arrays. 1 Extra dimension will be added, all the lower dimensions of the images must match. An example with lastdim = false would be 3 [32,32,32] images, which would result in 1 [32,32,32,3] image with the orienation matching from the first image. More...
 
ptr< NDArray > npl::sobelEdge (ptr< const NDArray > img)
 Increases the number of dimensions by 1 then places the edges in each dimension at indexes matching the direction of edge detection. So an input 3D image will produce a 4D image with volume 0 the x edges, volume 1 the y edges and volume 2 the z edges. More...
 
ptr< NDArray > npl::collapseSum (ptr< const NDArray > img, size_t dim, bool doabs=false)
 Creates a new image with the specified dimension collapsed and the values in each output point set to the sum of the values in the collapsed dimension. More...
 
ptr< NDArray > npl::relabelConnected (ptr< NDArray > input)
 Performs relabeling based on connected component using the two pass algorithm. More...
 
double npl::otsuThresh (ptr< const NDArray > in)
 Computes a threshold based on OTSU. More...
 
void npl::binarizeIP (ptr< NDArray > in, double t)
 Binarize an image to 0 or 1 based on whether it is greater than or less than the given threshold (t). In-place version (IP) More...
 
ptr< NDArray > npl::binarize (ptr< const NDArray > in, double t)
 Binarize an image to 0 or 1 based on whether it is greater than or less than the given threshold (t) More...
 
ptr< NDArray > npl::threshold (ptr< const NDArray > in, double t)
 Thresholds the image, changing everything below t to 0. More...
 
void npl::thresholdIP (ptr< NDArray > in, double t)
 Thresholds the image, changing everything below t to 0. More...
 
ptr< NDArray > npl::histEqualize (ptr< const NDArray > in)
 Computes a histogram, then spaces out intensities so that each intensity has equal volume/area in the image. More...
 
double npl::mse (ptr< const NDArray > a, ptr< const NDArray > b, ptr< const NDArray > mask=NULL)
 Computes the mean-squared-error between two images. They should be identically gridded. More...
 
double npl::dice (ptr< const NDArray > a, ptr< const NDArray > b, ptr< const NDArray > mask)
 Computes the dice coefficent between two labelmap images. They should be identically gridded. More...
 
double npl::corr (ptr< const NDArray > a, ptr< const NDArray > b, ptr< const NDArray > mask=NULL)
 Computes the correlation between two images. They should be identically gridded. More...
 
double npl::information (ptr< const NDArray > a, ptr< const NDArray > b, int bins=100, int krad=4, Metric m=METRIC_MI, ptr< const NDArray > mask=NULL)
 Computes the information based difference/similarity between two images. They should be identically gridded. More...
 
ptr< NDArray > npl::medianFilter (ptr< const NDArray > img)
 median filter More...
 
void npl::standardizeIP (ptr< NDArray > img)
 Standardizes image distribution (makes it mean = 0, variance = 1). This computation is done in place (IP) More...
 
ptr< NDArray > npl::standardize (ptr< const NDArray > img)
 Standardizes image distribution (makes it mean = 0, variance = 1). This computation is done in place (IP) More...
 
ptr< NDArray > npl::varianceT (ptr< const NDArray > img)
 Takes the variance of the higher dimensions and returns a 3D image. More...
 
ptr< NDArray > npl::createRandLabels (ptr< const NDArray > example, size_t nlabels, double sd)
 Create a random label map with the same size/orientation as the example image, and with nlabels unique labels, plus 0. More...
 
void npl::normalizeTS (ptr< NDArray > inout)
 Normalize timeseries' so that their mean is 1 and standard deviation is 0. More...