NPL
Neurological Programs and Libraries
npl Namespace Reference

Classes

class  Armijo
 Implementation of Armijo approximate line search algorithm. More...
 
class  BFGSOpt
 
class  BSplineView
 This is a specialized viewer for computing the value of a cubic B-Spline interpolation from the parameters. Thus the input to the constructor or setArray must be a parameter image. More...
 
union  Bytes
 
struct  cdouble_t
 
struct  cfloat_t
 
class  ChunkConstIter
 Constant iterator for NDArray. This is slightly different from order iterator in that the ROI may be broken down into chunks. When the end of a chunk is reached, no more iteration can be performed until nextChunk() is called. isEnd() will return false until nextChunk() is called while the current chunk is at the last available. Note that if setBreaks uses an array that is smaller than input dimension, then the whole of the dimension will be used. More...
 
class  ChunkIter
 This class is used to iterate through an N-Dimensional array. More...
 
class  ChunkSlicer
 This class is used to step through an ND array in order of dimensions, but unlike Slicer it breaks the NDArray into chunks. Iteration stops at the end of each chunk until nextChunk is called. By default only one chunk is used, equal to the entire image. Use setBreaks() to set the frequency of chunks. The input to setBreaks() is an array of integers, where the next chunk occurs when distbreak == 0, with the special property that break=0 indicates no breaks for the dimension. So for a 3D image, setBreaks({1,0,0}) will stop every time a new x-values is reached. Note that the affects the order of iteration, so x cannot be the fastest iterator. setChunkSize() is an alias for setBreaks. Note that in cases where breaksize != 0, for example image size = 5 and break = 3, chunk sizes will differ during the course of iteration! More...
 
class  Classifier
 Base class for all ND classifiers. More...
 
struct  Counter
 Very basic counter that iterates over an ND region. More...
 
struct  cquad_t
 
class  DistCorrInfoComp
 The distortion correction MI Computer is used to compute the mutual information and gradient of mutual information between two images using nonrigid, unidirectional, B-spline transform. More...
 
class  ExpMax
 Expectation Maximization With Gaussian Mixture Model. More...
 
class  FlatConstIter
 Flat iterator iterator for NDArray. No information is kept about the current index. Just goes through all data. This casts the output to the type specified using T. More...
 
class  FlatIter
 Flat iterator for NDArray. No information is kept about the current ND index. Just goes through all data. This casts the output to the type specified using T. More...
 
class  GradientOpt
 
class  Graph
 
class  KDTree
 
class  KDTreeNode
 
class  KernelIter
 Iterator for an image, that allows for easy access to the neighbors of the current element/pixel. Neighbors can be accessed through offset(i) which simply provides the value of the i'th neighbor. To get that neighbors index you can use it.offset_index(i). For the center use it.center()/it.center_index(). [] may also be used in place of offset. To get the number of neighbors in the kernel use ksize(), so it.offset(0), it.offset(1), ..., it.offset(ksize()-1) are valid calls. More...
 
class  KMeans
 K-means classifier. More...
 
class  KSlicer
 This class is used to slice an image in along a dimension, and to step an arbitrary direction in an image. Order may be any size from 0 to the number of dimensions. The first member of order will be the fastest moving, and the last will be the slowest. Any not dimensions not included in the order vector will be slower than the last member of order. More...
 
class  LanczosInterp3DView
 The purpose of this class is to view an image as a continuous 3D+vector dimension image rather than a 4+D image. Therefore all dimensions above the third are cast as a vector and interpolation is only performed between 3D points, with the 4th dimension assumed to be non-spatial. The would be applicable if the upper dimensions are of a different type than the first 3. More...
 
class  LanczosInterpNDView
 The purpose of this class is to view an image as a continuous 3D+vector dimension image rather than a 4+D image. Therefore all dimensions above the third are cast as a vector and interpolation is only performed between 3D points, with the 4th dimension assumed to be non-spatial. The would be applicable if the upper dimensions are of a different type than the first 3. More...
 
class  LBFGSOpt
 Limited-Memory Broyden–Fletcher–Goldfarb–Shanno Algorithm based on "A Limited Memory Algorithm for Bound Constrained Optimization" Richard H. Byrd, Peihuang Lu, Jorge Nocedal, and Ciyou Zhu http://dx.doi.org/10.1137/0916069. More...
 
class  LinInterp3DView
 The purpose of this class is to view an image as a continuous 3D+vector dimension image rather than a 4+D image. Therefore all dimensions above the third are cast as a vector and interpolation is only performed between 3D points, with the 4th dimension assumed to be non-spatial. The would be applicable if the upper dimensions are of a different type than the first 3. More...
 
class  LinInterpNDView
 The purpose of this class is to view an image as a continuous ND image and to sample at a continuous ND-position within. More...
 
class  MatMap
 
class  Matrix
 
class  MatrixP
 
class  MatrixReorg
 Reorganizes input images into tall and wide matrices (matrices that span the total rows and cols, respectively). More...
 
class  MemMap
 Memory map class. The basic gyst is that this works like a malloc except that data may be initialized by file contents or left empty. This is useful for matrix manipulation where files need to be opened and closed a good bit. More...
 
class  MRImage
 MRImage can basically be used like an NDArray, with the addition of orientation related additions. More...
 
class  MRImageStore
 MRImageStore is a version of NDArray that has an orientation matrix. Right now it also has additional data that is unique to nifti. Eventually this class will be forked into a subclass, and this will only have the orientation. More...
 
class  NDArray
 Pure virtual interface to interact with an ND array. More...
 
class  NDArrayStore
 Basic storage unity for ND array. Creates a big chunk of memory. More...
 
class  NDConstIter
 Constant iterator for NDArray. Typical usage calls for NDConstIter it(array); it++; *it. More...
 
class  NDConstView
 This is a basic accessor class, which allows for accessing array data in the type specified by the template. More...
 
class  NDIter
 This class is used to iterate through an N-Dimensional array. More...
 
class  NDView
 This is a basic accessor class, which allows for accessing array data in the type specified by the template. More...
 
class  NNInterp3DView
 The purpose of this class is to view an image as a continuous 3D+vector dimension image rather than a 4+D image. Therefore all dimensions above the third are cast as a vector and interpolation is only performed between 3D points, with the 4th dimension assumed to be non-spatial. The would be applicable if the upper dimensions are of a different type than the first 3. More...
 
class  NNInterpNDView
 General purpose Nearest-Neighbor interpolator. More...
 
class  Optimizer
 
class  Pixel3DView
 The purpose of this class is to view an image as a 3D image rather than a ND image. Therefore all dimensions above the third will be ignored and index 0 will be used. More...
 
class  Plotter
 Class for creating basic plots of arrays or functions. An example might be: More...
 
class  ProbDistCorrInfoComp
 The distortion correction MI Computer is used to compute the mutual information and gradient of mutual information between two images using nonrigid, unidirectional, B-spline transform. In this variant the moving image should be a probability map. More...
 
struct  RegrResult
 
struct  rgb_t
 
struct  rgba_t
 
struct  Rigid3DTrans
 Struct for holding information about a rigid transform. Note that rotation R = Rx*Ry*Rz, where Rx, Ry, and Rz are the rotations about x, y and z aaxes, and the angles are stored (in radians) in the rotation member. More...
 
class  RigidCorrComp
 The Rigid Corr Computer is used to compute the correlation and gradient of correlation between two images. As the name implies, it is designed for 6 parameter rigid transforms. More...
 
class  RigidInfoComp
 The Rigid MI Computer is used to compute the mutual information and gradient of mutual information between two images. As the name implies, it is designed for 6 parameter rigid transforms. More...
 
class  Slicer
 This class is used to step through an ND array in order of dimensions. Order may be any size from 0 to the number of dimensions. The first member of order will be the fastest moving, and the last will be the slowest. Any not dimensions not included in the order vector will be slower than the last member of order. More...
 
class  StudentsT
 Student's T-distribution. A cache of the Probability Density Function and cumulative density function is created using the analytical PDF. More...
 
class  Vector3DConstIter
 This class is used to iterate through an 3D array, where each point then has has multiple higher dimensional variable. This is analogous to Vector3DView, where even if there are multiple higher dimensions they are all alligned into a single vector at each 3D point. This makes them easier to than simple iteration in N-dimensions. This is the constant version. More...
 
class  Vector3DConstView
 The purpose of this class is to view an image as a 3D+vector dimension image rather than a 4+D image. Therefore all dimensions above the third are cast as a vector. If there is demand I may create a matrixx verion as well. More...
 
class  Vector3DIter
 This class is used to iterate through an 3D array, where each point then has has multiple higher dimensional variable. This is analogous to Vector3DView, where even if there are multiple higher dimensions they are all alligned into a single vector at each 3D point. This makes them easier to than simple iteration in N-dimensions. More...
 
class  Vector3DView
 The purpose of this class is to view an image as a 3D+vector dimension image rather than a 4+D image. Therefore all dimensions above the third are cast as a vector. If there is demand I may create a matrixx verion as well. More...
 
class  Wolfe
 Implementation of Armijo approximate line search algorithm. More...
 

Typedefs

typedef char rgba[4]
 
template<class T >
using OrderIter = NDIter< T >
 To maintain backward compatability, I have saved the OrderIter and OrderConstIter name, but eventually they may be deprecated. More...
 
template<class T >
using OrderConstIter = NDConstIter< T >
 To maintain backward compatability, I have saved the OrderIter and OrderConstIter name, but eventually they may be deprecated. More...
 
template<typename T >
using ptr = std::shared_ptr< T >
 Make the shared_ptr name shorter... More...
 
typedef std::vector< std::vector< std::array< float, 3 > > > TrackSet
 
typedef function< int(const VectorXd &x, double &v, VectorXd &g)> ValGradFunc
 Value and Gradient Computation Function. More...
 
typedef function< int(const VectorXd &x, VectorXd &g)> GradFunc
 Gradient Only Computation Function. More...
 
typedef function< int(const VectorXd &x, double &v)> ValFunc
 Value Only Computation Function. More...
 
typedef function< int(const VectorXd &x, double v, const VectorXd &g, size_t iter)> CallBackFunc
 Callback function. More...
 

Enumerations

enum  GraphDataT {
  G_DT_UNKNOWN = 0, G_DT_UCHAR = 1, G_DT_CHAR = 33, G_DT_USHORT = 2,
  G_DT_SHORT = 34, G_DT_ULONG = 4, G_DT_SLONG = 36, G_DT_ULONGLONG = 8,
  G_DT_SLONGLONG =40, G_DT_FLOAT = 132, G_DT_DOUBLE = 136, G_DT_QUAD = 144,
  G_DT_COMPLEX_FLOAT = 228, G_DT_COMPLEX_DOUBLE = 232, G_DT_COMPLEX_QUAD = 255
}
 
enum  GraphStoreT { G_STORE_UNKNOWN = 0, G_STORE_FULLMAT = 1, G_STORE_UNDIR = 2, G_STORE_LIST = 3 }
 
enum  SliceOrderT {
  UNKNOWN_SLICE =0, SEQ =1, RSEQ =2, ALT =3,
  RALT =4, ALT_SHFT =5, RALT_SHFT =6
}
 
enum  CoordinateT { NOFORM =0, QFORM =1, SFORM =2 }
 
enum  BoundaryConditionT { ZEROFLUX =0, CONSTZERO =1, WRAP =2 }
 
enum  PixelT {
  UNKNOWN_TYPE =0, UINT8 =2, INT16 =4, INT32 =8,
  FLOAT32 =16, COMPLEX64 =32, CFLOAT =32, FLOAT64 =64,
  RGB24 =128, INT8 =256, UINT16 =512, UINT32 =768,
  INT64 =1024, UINT64 =1280, FLOAT128 =1536, CDOUBLE =1792,
  COMPLEX128 =1792, CQUAD =2048, COMPLEX256 =2048, RGBA32 =2304
}
 
enum  Metric {
  METRIC_MI, METRIC_VI, METRIC_NMI, METRIC_COR,
  METRIC_REDUNDANCY, METRIC_NMIMETRIC, METRIC_DUALTC
}
 Information-based Metric to use. More...
 
enum  StopReason {
  ENDGRAD, ENDSTEP, ENDVALUE, ENDABSVALUE,
  ENDITERS, ENDFAIL
}
 

Functions

double linKern (double x)
 
template<typename T >
clamp (T inf, T sup, T v)
 Clamps value to range of [inf, sup]. Values outside will be pulled to either sup or inf, whichever is closer. More...
 
template<typename T >
wrap (T inf, T sup, T v)
 Wraps and index based on the range [inf, sup] (when v is outside that) range. Thus inf = 1, sup = 5, v = 0 will wrap around to 4, and v = 6 would wrap around to 1. More...
 
double rectWindow (double x, double a)
 Rectangle function centered at 0, with radius a, range should be = 2a. More...
 
double sincWindow (double x, double a)
 Sinc function centered at 0, with radius a, range should be = 2a. More...
 
double freqGaussian (double x, double sd)
 Gaussian function in the frequency domain. Note that the standard deviation is in the time domain. More...
 
double hammingWindow (double x, double a)
 
double welchWindow (double x, double a)
 
double hannWindow (double x, double a)
 
double lanczosKern (double x, double a)
 Derivative of lanczos kernel with respect to x. More...
 
double dLanczosKern (double x, double a)
 Derivative of lanczos kernel with respect to x. More...
 
double linKern (double x, double a)
 
double dLinKern (double x, double a)
 
double B3kern (double x)
 3rd order B-Spline, radius 2 [-2,2] More...
 
double B3kern (double x, double r)
 3rd order B-Spline, variable radius (w) More...
 
double dB3kern (double x)
 3rd order B-Spline derivative, radius 2 [-2,2] More...
 
double dB3kern (double x, double r)
 3rd order B-Spline, variable radius (w) More...
 
double ddB3kern (double x)
 3rd order B-Spline, 2nd derivative, radius 2 [-2,2] More...
 
double ddB3kern (double x, double r)
 3rd order B-Spline, variable radius (w) More...
 
double cot (double v)
 Cotangent function. More...
 
double csc (double v)
 Cosecant function. More...
 
double sec (double v)
 Secand function. More...
 
double degToRad (double rad)
 
double radToDeg (double rad)
 
int hob (int num)
 Highest order bit. More...
 
int64_t round2 (int64_t in)
 Round up to the nearest power of 2. More...
 
std::list< int64_t > factor (int64_t f)
 Provides a list of the prime-fractors of the input number. More...
 
int64_t round357 (int64_t in)
 Rounds a number up to the nearest number that can be broken down into 3,5,7. More...
 
template<typename T >
void writePlot (std::string filename, const std::vector< T > &data)
 Writes a plot to the given filename. This is a convience wrapper around Plotter, which for quick-and-dirty use might be too much setup. More...
 
template<typename T >
void writePlot (std::string filename, const std::vector< T > &data, size_t xsize, size_t ysize)
 Writes a plot to the given filename. This is a convience wrapper around Plotter, which for quick-and-dirty use might be too much setup. More...
 
template<typename T >
union npl::Bytes __attribute__ ((packed))
 
bool little_endian ()
 
bool big_endian ()
 
template<typename T >
void swap (T *val)
 
template<>
void swap< signed char > (signed char *val)
 
template<>
void swap< char > (char *val)
 
template<>
void swap< uint8_t > (uint8_t *val)
 
template<>
void swap< cquad_t > (cquad_t *val)
 
template<>
void swap< cdouble_t > (cdouble_t *val)
 
template<>
void swap< cfloat_t > (cfloat_t *val)
 
template<>
void swap< rgba_t > (rgba_t *val)
 
template<>
void swap< rgb_t > (rgb_t *val)
 
void createChirp (int64_t sz, fftw_complex *chirp, int64_t origsz, double upratio, double alpha, bool center, bool fft)
 Fills the input array (chirp) with a chirp of the specified type. More...
 
void chirpzFFT (size_t isize, size_t usize, fftw_complex *inout, size_t uppadsize, fftw_complex *buffer, fftw_complex *prechirp, fftw_complex *convchirp, fftw_complex *postchirp, bool debug=false)
 Comptues the chirpzFFT transform using FFTW for n log n performance. More...
 
void chirpzFFT (size_t isize, size_t usize, fftw_complex *inout, fftw_complex *buffer, bool debug=false)
 Comptues the chirpzFFT transform using FFTW for n log n performance. More...
 
void chirpzFFT (size_t isize, fftw_complex *in, fftw_complex *out, double a, bool debug=false)
 Comptues the chirpzFFT transform using FFTW for n log n performance. More...
 
void chirpzFT_brute2 (size_t isize, fftw_complex *in, fftw_complex *out, double a, bool debug=false)
 Performs chirpz transform with a as fractional parameter by N^2 algorithm. More...
 
void chirpzFT_brute (size_t len, fftw_complex *in, fftw_complex *out, double a)
 Performs chirpz transform with a as fractional parameter by N^2 algorithm. More...
 
void chirpzFT_zoom (size_t isize, fftw_complex *in, fftw_complex *out, double a)
 Performs the chirpz-transform using linear intpolation and the FFT. For greater speed pre-allocate the buffer and use the other chirpzFT_zoom. More...
 
void chirpzFT_zoom (size_t isize, fftw_complex *in, fftw_complex *out, fftw_complex *buffer, double a)
 Performs the chirpz-transform using linear intpolation and teh FFT. More...
 
void writePlotAbsAng (std::string file, size_t insz, fftw_complex *in)
 Plots an array of complex points with the Real and Imaginary Parts. More...
 
void writePlotReIm (std::string file, const std::vector< std::complex< double >> &in)
 Plots an array of complex points with the Real and Imaginary Parts. More...
 
void writePlotReIm (std::string file, size_t insz, fftw_complex *in)
 Plots an array of complex points with the Real and Imaginary Parts. More...
 
void zoom (size_t isize, fftw_complex *in, fftw_complex *out, double a)
 Performs a de-facto chirpz by interpolated zoom of a fourier-space line. More...
 
VectorXd onDiskSVD (const MatrixReorg &A, int rank, size_t poweriters, double varthresh, double cvarthresh, MatrixXd *U=NULL, MatrixXd *V=NULL)
 Uses randomized subspace approximation to reduce the input matrix (made up of blocks stored on disk with a given prefix). This assumes that the matrix is a wide matrix (which is generally a good assumption in fMRI) and that it therefore is better to reduce the number of columns. More...
 
void gicaCreateMatrices (size_t tcat, size_t scat, vector< std::string > masks, vector< std::string > inputs, std::string prefix, double maxmem, bool normts, bool verbose)
 Create on disk matrices based on an array of input images. The array will be concatinated in time tcat time and space scat time, with time as the faster dimension. More...
 
void gicaReduceFull (std::string inpref, std::string outpref, double varthresh, double cvarthresh, size_t maxrank, bool verbose)
 Compute PCA for the given group, defined. More...
 
void gicaReduceProb (std::string inpref, std::string outpref, double varthresh, double cvarthresh, size_t rank, size_t poweriters, bool verbose)
 Compute PCA for the given group, defined. More...
 
void gicaTemporalICA (std::string reorgpref, std::string reducepref, std::string outpref, bool verbose)
 Perform ICA with each dimension as a separate timeseries. This is essentially unmixing in space and producing independent timeseries. More...
 
void gicaSpatialICA (std::string reorgpref, std::string reducepref, std::string outpref, bool verbose)
 Perform ICA with each dimension as a separate timeseries. This is essentially unmixing in space and producing independent timeseries. More...
 
VectorXd covSVD (const MatrixReorg &A, double varthresh, double cvarthresh, size_t maxrank, MatrixXd *U, MatrixXd *V)
 Computes the SVD from XXt using the JacobiSVD. More...
 
void fmriGLM (ptr< const MRImage > fmri, const MatrixXd &X, ptr< MRImage > bimg, ptr< MRImage > Timg, ptr< MRImage > pimg)
 Performs general linear model analysis on a 4D image. More...
 
void fmriBandPass (ptr< MRImage > inimg, double cuton, double cutoff)
 Takes the FFT of each line of the image, performs bandpass filtering on the line and then invert FFTs and writes back to the input image. More...
 
ptr< MRImageregressOut (ptr< const MRImage > inimg, const MatrixXd &X)
 Regresses out the given variables, creating time series which are uncorrelated with X. More...
 
MatrixXd extractLabelAVG (ptr< const MRImage > fmri, ptr< const MRImage > labelmap)
 Creates a matrix of timeseries, then perfrorms principal components analysis on it to reduce the number of timeseries to outsz. Each unique non-zero label in the input image will be considered a group of measurements which will be reduced together. Thus if there are labels 0,1,2 there will be 2 columns in the output. More...
 
MatrixXd extractLabelPCA (ptr< const MRImage > fmri, ptr< const MRImage > labelmap, size_t outsz)
 Creates a matrix of timeseries, then perfrorms principal components analysis on it to reduce the number of timeseries to outsz. Each unique non-zero label in the input image will be considered a group of measurements which will be reduced together. Thus if there are labels 0,1,2 there will be 2*outsz columns in the output. More...
 
MatrixXd extractLabelICA (ptr< const MRImage > fmri, ptr< const MRImage > labelmap, size_t outsz)
 Creates a matrix of timeseries, then perfrorms principal components analysis on it to reduce the number of timeseries to outsz. Each unique non-zero label in the input image will be considered a group of measurements which will be reduced together. Thus if there are labels 0,1,2 there will be 2*outsz columns in the output. More...
 
void interp (int64_t isize, fftw_complex *in, int64_t osize, fftw_complex *out)
 Interpolate the input array, filling the output array. More...
 
void createChirp (int64_t sz, fftw_complex *chirp, int64_t origsz, double upratio, double alpha, double beta, bool fft)
 Fills the input array (chirp) with a chirp of the specified type. More...
 
void fractional_ft (size_t isize, fftw_complex *in, fftw_complex *out, double a, size_t bsz=0, fftw_complex *buffer=NULL, bool nonfft=false)
 Comptues the Fractional Fourier transform using FFTW for nlogn performance. More...
 
template<typename T >
GraphDataT getType ()
 
std::string describeType (GraphDataT type)
 
template<int D1, int D2>
std::ostream & operator<< (std::ostream &os, const Matrix< D1, D2 > &b)
 
std::ostream & operator<< (std::ostream &os, const MatrixP &b)
 
template<int D1, int D2>
Matrix< D1, D2 > operator+= (Matrix< D1, D2 > &lhs, const Matrix< D1, D2 > &rhs)
 
template<int D1, int D2>
Matrix< D1, D2 > operator+ (const Matrix< D1, D2 > &lhs, const Matrix< D1, D2 > &rhs)
 
template<int D1, int D2>
Matrix< D1, D2 > operator- (const Matrix< D1, D2 > &lhs, const Matrix< D1, D2 > &rhs)
 
template<int D1, int D2>
Matrix< D1, D2 > operator- (const Matrix< D1, D2 > &rhs)
 
template<int D1, int D2, int D3>
Matrix< D1, D3 > operator* (const Matrix< D1, D2 > &lhs, const Matrix< D2, D3 > &rhs)
 
template<int D1, int D2>
Matrix< D1+D2, D1+D2 > join (const Matrix< D1, D1 > &tl, const Matrix< D1, D2 > &tr, const Matrix< D2, D1 > &bl, const Matrix< D2, D2 > &br)
 Join together 4 matrices from a blockwise decomposition. More...
 
template<int D1, int D2>
void split (const Matrix< D1+D2, D1+D2 > &input, Matrix< D1, D1 > &tl, Matrix< D1, D2 > &tr, Matrix< D2, D1 > &bl, Matrix< D2, D2 > &br)
 
double det (const Matrix< 1, 1 > &trg)
 
double det (const Matrix< 2, 2 > &trg)
 
double det (const Matrix< 3, 3 > &trg)
 
template<int DIM>
double det (const Matrix< DIM, DIM > &trg)
 
template<int D1, int D2>
double norm (const Matrix< D1, D2 > &trg)
 
template<int DIM>
double norm (const Matrix< DIM, 1 > &trg)
 
template<int DIM>
double norm (const Matrix< 1, DIM > &trg)
 
Matrix< 1, 1 > inverse (const Matrix< 1, 1 > &trg)
 
Matrix< 2, 2 > inverse (const Matrix< 2, 2 > &trg)
 
template<int DIM>
Matrix< DIM, DIM > inverse (const Matrix< DIM, DIM > &trg)
 
ptr< MRImagecreateMRImage (size_t ndim, const size_t *size, PixelT type)
 Creates a new MRImage with dimensions set by ndim, and size set by size. Output pixel type is decided by type variable. More...
 
ptr< MRImagecreateMRImage (const std::vector< size_t > &dim, PixelT type)
 Creates a new MRImage with dimensions set by ndim, and size set by size. Output pixel type is decided by type variable. More...
 
ptr< MRImagecreateMRImage (size_t ndim, const size_t *size, PixelT type, void *ptr, std::function< void(void *)> deleter)
 Creates a new MRImage with dimensions set by ndim, and size set by size. Output pixel type is decided by type variable. More...
 
ptr< MRImagecreateMRImage (const std::vector< size_t > &dim, PixelT type, void *ptr, std::function< void(void *)> deleter)
 Creates a new MRImage with dimensions set by ndim, and size set by size. Output pixel type is decided by type variable. More...
 
std::ostream & operator<< (std::ostream &out, const MRImage &img)
 Writes out information about an MRImage. More...
 
void gaussianSmooth1D (ptr< MRImage > inout, size_t dim, double stddev)
 Gaussian smooths an image in 1 direction. Questionable whether it works. Seems to shift image. More...
 
ptr< MRImagesmoothDownsample (ptr< const MRImage > in, double sigma, double spacing=-1)
 Performs smoothing in each dimension, then downsamples so that pixel spacing is roughly equal to FWHM. More...
 
ptr< MRImageresample (ptr< const MRImage > in, double *spacing, double(*window)(double, double)=hannWindow)
 Performs fourier resampling using fourier transform and the provided window function. More...
 
ptr< MRImageshiftImage (ptr< MRImage > in, size_t len, double *vect)
 Uses fourier shift theorem to shift an image. More...
 
void writeComplex (std::string basename, ptr< const MRImage > in, bool absPhase=false)
 Writes a pair of images, one real, one imaginary or if absPhase is set to true then an absolute image and a phase image. More...
 
ptr< MRImagefft_forward (ptr< const MRImage > in, const std::vector< size_t > &in_osize)
 Performs forward FFT transform in N dimensions. More...
 
ptr< MRImagefft_backward (ptr< const MRImage > in, const std::vector< size_t > &in_osize)
 Performs inverse FFT transform in N dimensions. More...
 
int rotateImageShearKern (ptr< MRImage > inout, double rx, double ry, double rz, double(*kern)(double, double)=npl::lanczosKern)
 Rotates an image around the center using shear decomposition followed by kernel-based shearing. Rotation order is Rz, Ry, Rx, and about the center of the image. This means that 1D interpolation will be used. More...
 
int rotateImageShearFFT (ptr< MRImage > inout, double rx, double ry, double rz, double(*window)(double, double)=npl::sincWindow)
 Rotates an image around the center using shear decomposition followed by FFT-based shearing. Rotation order is Rz, Ry, Rx, and about the center of the image. More...
 
ptr< MRImagerigidTransform (ptr< MRImage > in, double rx, double ry, double rz, double sx, double sy, double sz)
 Rigid Transforms an image. More...
 
ptr< MRImagediffOfGauss (ptr< const MRImage > in, double sd1, double sd2)
 Computes difference of gaussians. More...
 
double overlapRatio (ptr< const MRImage > a, ptr< const MRImage > b)
 Computes the overlap of the two images' in 3-space. More...
 
ptr< MRImageresampleNN (ptr< const MRImage > in, ptr< const MRImage > atlas, PixelT type=UNKNOWN_TYPE)
 Performs nearest neighbor resasmpling of input to atlas. More...
 
ptr< MRImageresampleNN (ptr< const MRImage > in, double *newspace, PixelT type=UNKNOWN_TYPE)
 Performs nearest neighbor resasmpling of input to atlas. More...
 
ptr< MRImagerandImage (PixelT type, double mean, double sd, size_t x, size_t y, size_t z, size_t t)
 Create random image, with gaussian distribution. More...
 
ptr< NDArraycreateNDArray (size_t ndim, const size_t *size, PixelT ptype)
 Creates a new NDArray with dimensions set by ndim, and size set by size. Output pixel type is decided by ptype variable. More...
 
ptr< NDArraycreateNDArray (const std::vector< size_t > &dim, PixelT ptype)
 Creates a new NDArray with dimensions set by ndim, and size set by size. Output pixel type is decided by ptype variable. More...
 
ptr< NDArraycreateNDArray (size_t ndim, const size_t *size, PixelT ptype, void *ptr, std::function< void(void *)> deleter)
 Creates a new NDArray with dimensions set by ndim, and size set by size. Output pixel type is decided by ptype variable. More...
 
ptr< NDArraycreateNDArray (const std::vector< size_t > &dim, PixelT ptype, void *ptr, std::function< void(void *)> deleter)
 Creates a new NDArray with dimensions set by ndim, and size set by size. Output pixel type is decided by ptype variable. More...
 
void copyROI (ptr< const NDArray > in, const int64_t *inROIL, const size_t *inROIZ, ptr< NDArray > out, const int64_t *oROIL, const size_t *oROIZ, PixelT newtype)
 Copy an roi from one image to another image. ROI's must be the same size. More...
 
std::ostream & operator<< (std::ostream &out, const NDArray &img)
 Writes out information about an MRImage. More...
 
std::string pixelTtoString (PixelT type)
 Returns a string that is a descrption of the pixel type. More...
 
PixelT stringToPixelT (std::string type)
 Returns a pixeltype as described by the string. More...
 
std::unordered_set< int64_t > getLabels (ptr< const NDArray > in)
 Produces a std::unordered_set of labels within a labelmap. More...
 
bool 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< NDArrayderivative (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< NDArrayderivative (ptr< const NDArray > in, size_t dir)
 Computes the derivative of the image in the specified direction. More...
 
ptr< NDArraydilate (ptr< NDArray > in, size_t reps)
 Dilate an binary array repeatedly. More...
 
ptr< NDArrayerode (ptr< NDArray > in, size_t reps)
 Erode an binary array repeatedly. More...
 
void gaussianSmooth1D (ptr< NDArray > inout, size_t dim, double stddev)
 Smooths an image in 1 dimension. More...
 
void 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 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 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 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 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 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< NDArraylinearRotate (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 rotateImageKern (ptr< NDArray > inout, double rx, double ry, double rz)
 Performs a rotation using 3D intperolation kernel (lanczos) More...
 
int 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 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< NDArraypseudoPolar (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 > > 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< NDArraypseudoPolarZoom (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 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 fillLinear (ptr< NDArray > inout)
 Fills image with the linear index at each pixel. More...
 
void fillZero (ptr< NDArray > inout)
 Fills image with the linear index at each pixel. More...
 
void fillGaussian (ptr< NDArray > inout)
 Fills image with the linear index at each pixel. More...
 
ptr< NDArrayconcat (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< NDArrayconcatElevate (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< NDArraysobelEdge (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< NDArraycollapseSum (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< NDArrayrelabelConnected (ptr< NDArray > input)
 Performs relabeling based on connected component using the two pass algorithm. More...
 
double otsuThresh (ptr< const NDArray > in)
 Computes a threshold based on OTSU. More...
 
void 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< NDArraybinarize (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< NDArraythreshold (ptr< const NDArray > in, double t)
 Thresholds the image, changing everything below t to 0. More...
 
void thresholdIP (ptr< NDArray > in, double t)
 Thresholds the image, changing everything below t to 0. More...
 
ptr< NDArrayhistEqualize (ptr< const NDArray > in)
 Computes a histogram, then spaces out intensities so that each intensity has equal volume/area in the image. More...
 
double 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 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 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 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< NDArraymedianFilter (ptr< const NDArray > img)
 median filter More...
 
void standardizeIP (ptr< NDArray > img)
 Standardizes image distribution (makes it mean = 0, variance = 1). This computation is done in place (IP) More...
 
ptr< NDArraystandardize (ptr< const NDArray > img)
 Standardizes image distribution (makes it mean = 0, variance = 1). This computation is done in place (IP) More...
 
ptr< NDArrayvarianceT (ptr< const NDArray > img)
 Takes the variance of the higher dimensions and returns a 3D image. More...
 
ptr< NDArraycreateRandLabels (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 normalizeTS (ptr< NDArray > inout)
 Normalize timeseries' so that their mean is 1 and standard deviation is 0. More...
 
int writeMRImage (ptr< const MRImage > img, std::string fn, bool nifti2=false)
 Writes out an MRImage to the file fn. Bool indicates whether to use nifti2 (rather than nifti1) format. More...
 
int writeNDArray (ptr< const NDArray > img, std::string fn, bool nifti2=false)
 Writes out an MRImage to the file fn. Bool indicates whether to use nifti2 (rather than nifti1) format. More...
 
ptr< NDArrayreadNDArray (std::string filename, bool verbose=false, bool nopixeldata=false)
 Reads an array. Can read nifti's but orientation won't be read. More...
 
ptr< MRImagereadMRImage (std::string filename, bool verbose=false, bool nopixeldata=false)
 Reads an MRI image. Right now only nift images are supported. later on, it will try to load image using different reader functions until one suceeds. More...
 
template<typename T , typename F >
ptr< T > dPtrCast (const ptr< F > &in)
 Shorter name for dynamic_pointer_cast. More...
 
std::ostream & operator<< (std::ostream &stream, const rgb_t &v)
 
std::ostream & operator<< (std::ostream &stream, const rgba_t &v)
 
rgb_t operator+ (const rgb_t &lhs, const double &rhs)
 
rgb_t operator+ (const double &lhs, const rgb_t &rhs)
 
rgb_t operator- (const rgb_t &lhs, const double &rhs)
 
rgb_t operator- (const double &lhs, const rgb_t &rhs)
 
rgb_t operator* (const rgb_t &lhs, const double &rhs)
 
rgb_t operator* (const double &lhs, const rgb_t &rhs)
 
rgb_t operator/ (const rgb_t &lhs, const double &rhs)
 
rgb_t operator/ (const double &lhs, const rgb_t &rhs)
 
rgba_t operator+ (const rgba_t &lhs, const double &rhs)
 
rgba_t operator+ (const double &lhs, const rgba_t &rhs)
 
rgba_t operator- (const rgba_t &lhs, const double &rhs)
 
rgba_t operator- (const double &lhs, const rgba_t &rhs)
 
rgba_t operator* (const rgba_t &lhs, const double &rhs)
 
rgba_t operator* (const double &lhs, const rgba_t &rhs)
 
rgba_t operator/ (const rgba_t &lhs, const double &rhs)
 
rgba_t operator/ (const double &lhs, const rgba_t &rhs)
 
ptr< MRImagemotionCorrect (ptr< const MRImage > input, size_t ref)
 Performs motion correction on a set of volumes. Each 3D volume is extracted and linearly registered with the ref volume. More...
 
Rigid3DTrans corReg3D (ptr< const MRImage > fixed, ptr< const MRImage > moving, const std::vector< double > &sigmas)
 Performs correlation based registration between two 3D volumes. note that the two volumes should have identical sampling and identical orientation. If that is not the case, an exception will be thrown. More...
 
Rigid3DTrans informationReg3D (ptr< const MRImage > fixed, ptr< const MRImage > moving, const std::vector< double > &sigmas, size_t nbins=128, size_t binradius=4, std::string metric="MI", double stopx=0.001)
 Performs information-based registration between two 3D volumes. note that the two volumes should have identical sampling and identical orientation. If that is not the case, an exception will be thrown. More...
 
ptr< MRImageinfoDistCor (ptr< const MRImage > fixed, ptr< const MRImage > moving, bool otsu, int dir, double bspace, double jac, double tps, const std::vector< double > &sigmas, size_t nbins=128, size_t binradius=4, string metric="MI", size_t hist=8, double stopx=1e-5, double beta=0.5)
 Information based registration between two 3D volumes. note that the two volumes should have identical sampling and identical orientation. More...
 
int cor3DDerivTest (double step, double tol, ptr< const MRImage > in1, ptr< const MRImage > in2)
 This function checks the validity of the derivative functions used to optimize between-image corrlation. More...
 
int information3DDerivTest (double step, double tol, ptr< const MRImage > in1, ptr< const MRImage > in2)
 This function checks the validity of the derivative functions used to optimize between-image corrlation. More...
 
int distcorDerivTest (double step, double tol, shared_ptr< const MRImage > in1, shared_ptr< const MRImage > in2, double regj=0, double regt=0)
 This function checks the validity of the derivative functions used to optimize between-image corrlation. More...
 
std::ostream & operator<< (std::ostream &stream, const Rigid3DTrans &rigid)
 Prints a rigid transform. More...
 
double sample_var (const Ref< const VectorXd > vec)
 Computes the statistical variance of a column vector. More...
 
void regressOutLS (VectorXd &signal, const MatrixXd &X, const MatrixXd &covInv)
 Removes the effects of X from signal (y). Note that this takes both X and the pseudoinverse of X because the bulk of the computation will be on the pseudoinverse. More...
 
template<typename T >
void fillGaussian (Ref< T > m)
 
double gaussianPDF (double mean, double sd, double x)
 1D Gaussian distribution function More...
 
double gaussianCDF (double mean, double sd, double x)
 1D Gaussian cumulative distribution function More...
 
double gammaPDF_MS (double mean, double sd, double x)
 PDF for the gamma distribution, if mean is negative then it is assumed that x should be negated as well. Unlike gammaPDF, this takes the mean and standard deviation (_MS) More...
 
double mutualInformation (size_t len, double *a, double *b, size_t mbin)
 Computes mutual information between signal a and signal b which are of length len. Marginal bins used is mbin. More...
 
double correlation (size_t len, double *a, double *b)
 Computes correlation between signal a and signal b which are of length len. More...
 
double sample_var (int count, double sum, double sumsqr)
 Takes a count, sum and sumsqr and returns the sample variance. This is slightly different than the variance definition and I can never remember the exact formulation. More...
 
double sample_corr (int count, double sum1, double sum2, double sumsq1, double sumsq2, double s1s2)
 Computes the sample correlation. More...
 
void regress (RegrResult *out, const Ref< const VectorXd > y, const Ref< const MatrixXd > X, const Ref< const VectorXd > covInv, const Ref< const MatrixXd > Xinv, const StudentsT &distrib)
 Computes the Ordinary Least Square predictors, beta for. More...
 
void regress (RegrResult *out, const Ref< const VectorXd > y, const Ref< const MatrixXd > X)
 Computes the Ordinary Least Square predictors, beta for. More...
 
void randomizePowerIterationSVD (const Ref< const MatrixXd > A, size_t subsize, size_t poweriters, MatrixXd &U, VectorXd &E, MatrixXd &V)
 
void randomizePowerIterationSVD (const Ref< const MatrixXd > A, double tol, size_t startrank, size_t maxrank, size_t poweriters, MatrixXd &U, VectorXd &E, MatrixXd &V)
 
MatrixXd pca (const Ref< const MatrixXd > X, double varth=1, int odim=-1)
 Computes the Principal Components of input matrix X. More...
 
MatrixXd rpiPCA (const Ref< const MatrixXd > X, double varth, int odim)
 Computes the Principal Components of input matrix X using the randomized power iteration SVD algorithm. More...
 
MatrixXd symICA (const Ref< const MatrixXd > Xin, MatrixXd *unmix=NULL)
 Computes the Independent Components of input matrix X using symmetric decorrlation. Note that you should run PCA on X before running ICA. More...
 
MatrixXd asymICA (const Ref< const MatrixXd > Xin, MatrixXd *unmix=NULL)
 Computes the Independent Components of input matrix X using sequential component extraction. Note that you should run PCA on X before running ICA. More...
 
MatrixXd pseudoInverse (const Ref< const MatrixXd > X)
 Computes the pseudoinverse of the input matrix. More...
 
VectorXd shootingRegr (const Ref< const MatrixXd > X, const Ref< const VectorXd > y, double gamma)
 Performs LASSO regression using the 'shooting' algorithm of. More...
 
VectorXd activeShootingRegr (const Ref< const MatrixXd > X, const Ref< const VectorXd > y, double gamma)
 Performs LASSO regression using the 'activeShooting' algorithm of. More...
 
MatrixXd pcacov (const Ref< const MatrixXd > cov, double varth)
 Computes the Principal Components of input matrix X using the covariance matrix. More...
 
void expMax1D (const Ref< const VectorXd > data, vector< std::function< double(double, double, double)>> pdfs, Ref< VectorXd > mean, Ref< VectorXd > sd, Ref< VectorXd > prior, std::string plotfile="")
 Computes the mean and standard deviation of multiple distributions based on 1D data. The probability distribution functions should be passed in through a vector of function objects (pdfs) taking mu/sd/x. More...
 
void gaussGammaMixtureModel (const Ref< const VectorXd > data, Ref< VectorXd > mu, Ref< VectorXd > sd, Ref< VectorXd > prior, std::string plotfile)
 Computes the mean and standard deviation of multiple distributions based on 1D data. This is a special version in which a negative gamma, a gaussian and positive gamma. The means of the negative and positive gamma are relative to the center of the gaussian. More...
 
void approxKMeans (const Ref< const MatrixXd > samples, size_t nclass, MatrixXd &means)
 Approximates k-means using the algorithm of: More...
 
int fastSearchFindDP (const Eigen::MatrixXf &samples, double thresh, double outthresh, Eigen::VectorXi &classes, bool brute=false)
 Algorithm of unsupervised learning (clustering) based on density. More...
 
int findDensityPeaks (const Eigen::MatrixXf &samples, double thresh, Eigen::VectorXf &rho, Eigen::VectorXf &delta, Eigen::VectorXi &parent)
 Computes Density and Peak computation for Fast Search and Find of Density Peaks algorithm. More...
 
int findDensityPeaks_brute (const Eigen::MatrixXf &samples, double thresh, Eigen::VectorXf &rho, Eigen::VectorXf &delta, Eigen::VectorXi &parent)
 Computes Density and Peak computation for Fast Search and Find of Density Peaks algorithm. This is a slower, non-bin based version. More...
 
TrackSet readTracks (std::string filename, std::string ref="")
 Reads tracks into a vector of tracks, where each track is a vector of float[3]. More...
 
TrackSet readDFT (std::string tfile, std::string ref="")
 Reads a BrainSuite DFT file. Throws INVALID_ARGUMENT if the magic is wrong. More...
 
TrackSet readTrk (std::string filename, std::string ref="")
 Reads a trackvis trk file. Throws INVALID_ARGUMENT if the magic is wrong. More...
 
std::string dirname (std::string path)
 Returns the directory name for the given file. More...
 
bool isTxt (std::string filename)
 Reads a file and returns true if its entirely made up of printable ascii. More...
 
bool fileExists (std::string filename)
 Returns true if a file exists and is possible to open. More...
 
std::string chomp (std::string str)
 Removes whitespace at the beginning and end of a string. More...
 
std::vector< std::string > parseLine (std::string line, std::string delim)
 Given a delimiter splits the line based on the delmiter and removes extra white space as necessary. More...
 
std::vector< std::vector< std::string > > readStrCSV (std::string filename, char &delim, char comment= '#')
 This function parses an input and returns a list of rows. More...
 
std::vector< std::vector< double > > readNumericCSV (std::string filename, char comment= '#')
 This function parses an input and returns a list of rows. More...
 
double gammaPDF (double x, double k, double theta)
 Gamma distribution, used by Cannonical HRF from SPM. More...
 
double cannonHrf (double t, double rdelay, double udelay, double rdisp, double udisp, double puRatio, double onset, double total)
 Cannonical hemodynamic response funciton from SPM. delay of response (relative to onset) = 6 delay of undershoot (relative to onset) = 16 dispersion of response = 1 dispersion of undershoot = 1 ratio of response to undershoot = 6 onset (seconds) = 0 length of kernel (seconds) = 32. More...
 
double cannonHrf (double t)
 The cannoical HRF with all default parameters. More...
 
std::vector< double > getRegressor (std::vector< std::vector< double >> &spec, double tr, size_t ntimes, double t0)
 Takes a 1 or 3 column format of regressor and produces a timeseries sampeled every tr, starting at time t0, and running for ntimes. More...
 
void boldsim (size_t len, double *iobuff, double dt, double learn)
 In place simulation of BOL timeseries using the balloon model. Habituation is accomplished by subtracting exponential moving average of u, thus if u tends to be on a lot, the effective u will be lower, if it turns on for the first time in a long time, the spike will be greater. Learn is the weight of the current point, the previous moving average value is weighted (1-learn) More...
 
void convolve (std::vector< double > &signal, double(*foo)(double), double tr, double length)
 Convolves a signal and a function using loops (not fast) No wrapping is done. More...
 
double fwhm_to_sd (double fwhm)
 Computes the standard deviation from FWHM (because I can never remember the ratio) More...
 
double sd_to_fwhm (double sd)
 Computes the FWHM from from standard deviation (because I can never remember the ratio) More...
 
int testgrad (double &error, const VectorXd &x, double stepsize, double tol, const ValFunc &valfunc, const ValGradFunc &valgradfunc)
 Tests a gradient function using the value function. More...
 
int testgrad (double &error, const VectorXd &x, double stepsize, double tol, const ValFunc &valfunc, const GradFunc &gradfunc)
 Tests a gradient function using the value function. More...
 
int gRosenbrock_G (const VectorXd &x, VectorXd &gradient)
 Implements generized rosenbrock gradient. More...
 
int gRosenbrock_V (const VectorXd &x, double &v)
 Implements generized rosenbrock value. More...
 
void gRosenbrock_callCounts (size_t &vcalls, size_t &gcalls)
 Returns the number of times the Value and Gradient functions for the Generalized Rosenbrock Function were called. More...
 
int noopCallback (const VectorXd &x, double value, const VectorXd &grad, size_t iter)
 Callback that does nothing. More...
 

Variables

class npl::MatMap __attribute__
 
const size_t MAXDIM = 10
 Defines the maximum supported dimension by image, used for stack-allocations. More...
 

Typedef Documentation

template<typename T >
using npl::ptr = typedef std::shared_ptr<T>

Make the shared_ptr name shorter...

Template Parameters
TType we are pointing at

Definition at line 42 of file npltypes.h.

typedef char npl::rgba[4]

Definition at line 29 of file basic_plot.h.

typedef std::vector<std::vector<std::array<float,3> > > npl::TrackSet

Definition at line 20 of file tracks.h.

Enumeration Type Documentation

Enumerator
ZEROFLUX 
CONSTZERO 
WRAP 

Definition at line 37 of file mrimage.h.

Enumerator
NOFORM 
QFORM 
SFORM 

Definition at line 35 of file mrimage.h.

Enumerator
G_DT_UNKNOWN 
G_DT_UCHAR 
G_DT_CHAR 
G_DT_USHORT 
G_DT_SHORT 
G_DT_ULONG 
G_DT_SLONG 
G_DT_ULONGLONG 
G_DT_SLONGLONG 
G_DT_FLOAT 
G_DT_DOUBLE 
G_DT_QUAD 
G_DT_COMPLEX_FLOAT 
G_DT_COMPLEX_DOUBLE 
G_DT_COMPLEX_QUAD 

Definition at line 28 of file graph.h.

Enumerator
G_STORE_UNKNOWN 
G_STORE_FULLMAT 
G_STORE_UNDIR 
G_STORE_LIST 

Definition at line 47 of file graph.h.

Information-based Metric to use.

Enumerator
METRIC_MI 
METRIC_VI 
METRIC_NMI 
METRIC_COR 
METRIC_REDUNDANCY 
METRIC_NMIMETRIC 
METRIC_DUALTC 

Definition at line 33 of file npltypes.h.

Enumerator
UNKNOWN_TYPE 
UINT8 
INT16 
INT32 
FLOAT32 
COMPLEX64 
CFLOAT 
FLOAT64 
RGB24 
INT8 
UINT16 
UINT32 
INT64 
UINT64 
FLOAT128 
CDOUBLE 
COMPLEX128 
CQUAD 
COMPLEX256 
RGBA32 

Definition at line 35 of file ndarray.h.

Enumerator
UNKNOWN_SLICE 
SEQ 
RSEQ 
ALT 
RALT 
ALT_SHFT 
RALT_SHFT 

Definition at line 32 of file mrimage.h.

Function Documentation

double npl::B3kern ( double  x)
inline

3rd order B-Spline, radius 2 [-2,2]

Parameters
xDistance from center
Returns
Weight

Definition at line 251 of file basic_functions.h.

double npl::B3kern ( double  x,
double  r 
)
inline

3rd order B-Spline, variable radius (w)

Parameters
xDistance from center
rRadius
Returns
Weight

Definition at line 281 of file basic_functions.h.

bool npl::big_endian ( )
inline

Definition at line 40 of file byteswap.h.

void npl::boldsim ( size_t  len,
double *  iobuff,
double  dt,
double  learn 
)

In place simulation of BOL timeseries using the balloon model. Habituation is accomplished by subtracting exponential moving average of u, thus if u tends to be on a lot, the effective u will be lower, if it turns on for the first time in a long time, the spike will be greater. Learn is the weight of the current point, the previous moving average value is weighted (1-learn)

Parameters
lenLength of input/output buffer
iobuffInput/Output Buffer of values (input stimulus, output signal)
dtTimestep for simulation
learnThe weight of the current point, the previous moving average value is weighted (1-learn), setting learn to 1 removes all habituation This limits the effect of habituation.
double npl::cannonHrf ( double  t,
double  rdelay,
double  udelay,
double  rdisp,
double  udisp,
double  puRatio,
double  onset,
double  total 
)

Cannonical hemodynamic response funciton from SPM. delay of response (relative to onset) = 6 delay of undershoot (relative to onset) = 16 dispersion of response = 1 dispersion of undershoot = 1 ratio of response to undershoot = 6 onset (seconds) = 0 length of kernel (seconds) = 32.

Parameters
tTime of sampled value
rdelayDelay of onset (default 6)
udelayDelay of undershot (relative to onset, default 16)
rdispDispersion of response (default 1)
udispDispersion of undershoot (default 1)
puRatioRatio of response to undershoot (default 6)
onsetOnset time (default 0)
totalKernel time (default 32)
Returns
Weight at the given time
double npl::cannonHrf ( double  t)

The cannoical HRF with all default parameters.

Parameters
tTime from stimulus
Returns
Response level
void npl::chirpzFFT ( size_t  isize,
size_t  usize,
fftw_complex *  inout,
size_t  uppadsize,
fftw_complex *  buffer,
fftw_complex *  prechirp,
fftw_complex *  convchirp,
fftw_complex *  postchirp,
bool  debug = false 
)

Comptues the chirpzFFT transform using FFTW for n log n performance.

This version needs for chirps to already been calculated. This is useful if you are running a large number of inputs with the same alpha

Parameters
isizeSize of input/output
usizeSize that we should upsample input to
inoutInput array, length sz
uppadsizePadded+upsampled array size
bufferComplex buffer used for upsampling, size = uppadsize
prechirpPre-multiply chirp.
convchirpChirp that we need to convolve with
postchirpPost-multiply chirp.
debugwhether to write out diagnostic plots
void npl::chirpzFFT ( size_t  isize,
size_t  usize,
fftw_complex *  inout,
fftw_complex *  buffer,
bool  debug = false 
)

Comptues the chirpzFFT transform using FFTW for n log n performance.

This version needs for chirps to already been calculated. This is useful if you are running a large number of inputs with the same alpha

Parameters
isizeSize of input/output
usizeSize that we should upsample input to
inoutInput array, length sz
bufferComplex buffer used for upsampling, size = uppadsize
debugwhether to write out diagnostic plots
void npl::chirpzFFT ( size_t  isize,
fftw_complex *  in,
fftw_complex *  out,
double  a,
bool  debug = false 
)

Comptues the chirpzFFT transform using FFTW for n log n performance.

Parameters
isizeSize of input/output
inInput array, may be the same as out, length sz
outOutput array, may be the same as input, length sz
aRatio of the output frequency spectrum to sample.
debugwhether to write out diagnostic plots
void npl::chirpzFT_brute ( size_t  len,
fftw_complex *  in,
fftw_complex *  out,
double  a 
)

Performs chirpz transform with a as fractional parameter by N^2 algorithm.

Parameters
lenLength of input array
inInput Array (length = len)
outOutput Array (length = len)
aFraction/Alpha To raise exp() term to
void npl::chirpzFT_brute2 ( size_t  isize,
fftw_complex *  in,
fftw_complex *  out,
double  a,
bool  debug = false 
)

Performs chirpz transform with a as fractional parameter by N^2 algorithm.

Parameters
isizeLength of input array
inInput Array (length = len)
outOutput Array (length = len)
aFraction/Alpha To raise exp() term to
debugWrite out debugging information (including plots!)
void npl::chirpzFT_zoom ( size_t  isize,
fftw_complex *  in,
fftw_complex *  out,
double  a 
)

Performs the chirpz-transform using linear intpolation and the FFT. For greater speed pre-allocate the buffer and use the other chirpzFT_zoom.

Parameters
isizeInput size
inInput line
outOutput line
aZoom factor (alpha)
void npl::chirpzFT_zoom ( size_t  isize,
fftw_complex *  in,
fftw_complex *  out,
fftw_complex *  buffer,
double  a 
)

Performs the chirpz-transform using linear intpolation and teh FFT.

Parameters
isizeInput size
inInput line
outOutput line
bufferBuffer, should be size isize
aZoom factor (alpha)
std::string npl::chomp ( std::string  str)

Removes whitespace at the beginning and end of a string.

Parameters
strstring to chomp
Returns
chomped string
template<typename T >
T npl::clamp ( inf,
sup,
v 
)
inline

Clamps value to range of [inf, sup]. Values outside will be pulled to either sup or inf, whichever is closer.

Template Parameters
TValue of inf/sup/v/output
Parameters
infLower bound (infinum)
supUpper bound (supremum)
vValue to clamp
Returns

Definition at line 41 of file basic_functions.h.

void npl::convolve ( std::vector< double > &  signal,
double(*)(double)  foo,
double  tr,
double  length 
)

Convolves a signal and a function using loops (not fast) No wrapping is done.

for ii in 0...N-1 for jj in 0...M-1 if jj-ii valid: s[ii] = s[ii]*kern[jj-ii]

Parameters
signalInput signal sampled every (tr)
fooFunction to sample backwards
trSampling time of input signal
lengthNumber of samples to draw from foo
double npl::cot ( double  v)
inline

Cotangent function.

Parameters
vangle in radians
Returns
Cotangent of angle

Definition at line 372 of file basic_functions.h.

VectorXd npl::covSVD ( const MatrixReorg A,
double  varthresh,
double  cvarthresh,
size_t  maxrank,
MatrixXd *  U,
MatrixXd *  V 
)

Computes the SVD from XXt using the JacobiSVD.

Parameters
AMatrixReorg object that can be used to load images on disk
varthreshstop after the eigenvalues reach this ratio of the maximum
cvarthreshstop after the sum of eigenvalues reaches this ratio of total
maxrankuse no more than the given rank when reducing
UOutput U matrix, if null then ignored
VOutput V matrix, if null then ignored
Returns
Vector of singular values
void npl::createChirp ( int64_t  sz,
fftw_complex *  chirp,
int64_t  origsz,
double  upratio,
double  alpha,
bool  center,
bool  fft 
)

Fills the input array (chirp) with a chirp of the specified type.

Parameters
szSize of output array
chirpOutput array
origszOriginal size, decides maximum frequency reached
upratioRatio of upsampling performed. This may be different than sz/origsz
alphaPositive term in exp
centerWhether to center, or start at 0
fftWhether to fft the output (put it in frequency domain)
void npl::createChirp ( int64_t  sz,
fftw_complex *  chirp,
int64_t  origsz,
double  upratio,
double  alpha,
double  beta,
bool  fft 
)

Fills the input array (chirp) with a chirp of the specified type.

Parameters
szSize of output array
chirpOutput array
origszOriginal size, decides maximum frequency reached
upratioRatio of upsampling performed. This may be different than sz/origsz
alphaPositive term in exp
betaNegative term in exp
fftWhether to fft the output (put it in frequency domain)
double npl::csc ( double  v)
inline

Cosecant function.

Parameters
vangle in radians
Returns
Cosecant of angle

Definition at line 385 of file basic_functions.h.

double npl::dB3kern ( double  x)
inline

3rd order B-Spline derivative, radius 2 [-2,2]

Parameters
xDistance from center
Returns
Weight

Definition at line 294 of file basic_functions.h.

double npl::dB3kern ( double  x,
double  r 
)
inline

3rd order B-Spline, variable radius (w)

Parameters
xDistance from center
rRadius
Returns
Weight

Definition at line 320 of file basic_functions.h.

double npl::ddB3kern ( double  x)
inline

3rd order B-Spline, 2nd derivative, radius 2 [-2,2]

Parameters
xDistance from center
Returns
Weight

Definition at line 333 of file basic_functions.h.

double npl::ddB3kern ( double  x,
double  r 
)
inline

3rd order B-Spline, variable radius (w)

Parameters
xDistance from center
rRadius
Returns
Weight

Definition at line 359 of file basic_functions.h.

double npl::degToRad ( double  rad)
inline

Definition at line 405 of file basic_functions.h.

std::string npl::describeType ( GraphDataT  type)
double npl::det ( const Matrix< 1, 1 > &  trg)

Definition at line 625 of file matrix_deprecated.h.

double npl::det ( const Matrix< 2, 2 > &  trg)

Definition at line 630 of file matrix_deprecated.h.

double npl::det ( const Matrix< 3, 3 > &  trg)

Definition at line 635 of file matrix_deprecated.h.

template<int DIM>
double npl::det ( const Matrix< DIM, DIM > &  trg)

Definition at line 650 of file matrix_deprecated.h.

std::string npl::dirname ( std::string  path)

Returns the directory name for the given file.

Parameters
pathInput path
Returns
Output directory name of input path
double npl::dLanczosKern ( double  x,
double  a 
)
inline

Derivative of lanczos kernel with respect to x.

Parameters
xDistance from center (0)
aRadius
Returns
Weight

Definition at line 208 of file basic_functions.h.

double npl::dLinKern ( double  x,
double  a 
)
inline

Definition at line 229 of file basic_functions.h.

template<typename T , typename F >
ptr<T> npl::dPtrCast ( const ptr< F > &  in)

Shorter name for dynamic_pointer_cast.

Template Parameters
FCast from this type
TCast to this type
Parameters
inInput pointer (type F*)
Returns
Output pointer (type T*)

Definition at line 54 of file npltypes.h.

MatrixXd npl::extractLabelAVG ( ptr< const MRImage fmri,
ptr< const MRImage labelmap 
)

Creates a matrix of timeseries, then perfrorms principal components analysis on it to reduce the number of timeseries to outsz. Each unique non-zero label in the input image will be considered a group of measurements which will be reduced together. Thus if there are labels 0,1,2 there will be 2 columns in the output.

Note that labelmap and fmri should be in the same pixel space (except for dimension 3)

Parameters
fmriFMRI image with timeseres to extract
labelmapLabelmap used to identify relevent input timeseries
Returns
Matrix of time-series which were reduced, 1 column per label group, since each label group gets reduced to an average
MatrixXd npl::extractLabelICA ( ptr< const MRImage fmri,
ptr< const MRImage labelmap,
size_t  outsz 
)

Creates a matrix of timeseries, then perfrorms principal components analysis on it to reduce the number of timeseries to outsz. Each unique non-zero label in the input image will be considered a group of measurements which will be reduced together. Thus if there are labels 0,1,2 there will be 2*outsz columns in the output.

Note that labelmap and fmri should be in the same pixel space (except for dimension 3)

Parameters
fmriFMRI image with timeseres to extract
labelmapLabelmap used to identify relevent input timeseries
outszNumber of output timeseres ti append to design
Returns
Matrix of time-series which were reduced, 1 block of outsz for each label group, since each label group gets reduced to outsz leading components
MatrixXd npl::extractLabelPCA ( ptr< const MRImage fmri,
ptr< const MRImage labelmap,
size_t  outsz 
)

Creates a matrix of timeseries, then perfrorms principal components analysis on it to reduce the number of timeseries to outsz. Each unique non-zero label in the input image will be considered a group of measurements which will be reduced together. Thus if there are labels 0,1,2 there will be 2*outsz columns in the output.

Note that labelmap and fmri should be in the same pixel space (except for dimension 3)

Parameters
fmriFMRI image with timeseres to extract
labelmapLabelmap used to identify relevent input timeseries
outszNumber of output timeseres ti append to design
Returns
Matrix of time-series which were reduced, 1 block of outsz for each label group, since each label group gets reduced to outsz leading components
std::list<int64_t> npl::factor ( int64_t  f)
inline

Provides a list of the prime-fractors of the input number.

Parameters
finput number
Returns
list of factors

Definition at line 463 of file basic_functions.h.

bool npl::fileExists ( std::string  filename)

Returns true if a file exists and is possible to open.

Parameters
filenameto read
Returns
if the file exists
void npl::fmriBandPass ( ptr< MRImage inimg,
double  cuton,
double  cutoff 
)

Takes the FFT of each line of the image, performs bandpass filtering on the line and then invert FFTs and writes back to the input image.

Parameters
inimgInput image
cutonMinimum frequency (may be 0)
cutoffMaximum frequency in band (may be INFINITY)
void npl::fmriGLM ( ptr< const MRImage fmri,
const MatrixXd &  X,
ptr< MRImage bimg,
ptr< MRImage Timg,
ptr< MRImage pimg 
)

Performs general linear model analysis on a 4D image.

Parameters
fmriInput 4D image.
XRegressors
bimgOutput betas for each voxel (should have same
TimgOutput t-score image
pimgOutput p-valeu image
void npl::fractional_ft ( size_t  isize,
fftw_complex *  in,
fftw_complex *  out,
double  a,
size_t  bsz = 0,
fftw_complex *  buffer = NULL,
bool  nonfft = false 
)

Comptues the Fractional Fourier transform using FFTW for nlogn performance.

The definition of the fractional fourier transform is:

\[ F(u) = SUM f(j) exp(-2 PI i a u j / (N+1) \]

where $j = [-N/2,N/2], u = [-N/2, N/2]$

Parameters
isizesize of input/output
inInput array, may be the same as output, length sz
outOutput array, may be the same as input, length sz
bszBuffer size
aFraction, 1 = fourier transform, 2 = reverse, 3 = inverse fourier transform, 4 = identity
bufferBuffer to do computations in, may be null, in which case new memory will be allocated and deallocated during processing. Note that if the provided buffer is not sufficient size a new buffer will be allocated and deallocated, and a warning will be produced
nonfftWhether to use brute force method (non-fft)
double npl::freqGaussian ( double  x,
double  sd 
)
inline

Gaussian function in the frequency domain. Note that the standard deviation is in the time domain.

Parameters
xdistance from center
sdstandard deviation
Returns
weight

Definition at line 117 of file basic_functions.h.

double npl::fwhm_to_sd ( double  fwhm)
inline

Computes the standard deviation from FWHM (because I can never remember the ratio)

Parameters
fwhmFull width-half max that we want to convert to equivalent standard deviation
Returns
Standard deviation for a gaussian with the specified FWHM

Definition at line 251 of file utility.h.

double npl::gammaPDF ( double  x,
double  k,
double  theta 
)

Gamma distribution, used by Cannonical HRF from SPM.

Parameters
xPosition
kShape parameter
thetaScale parameter
Returns
std::vector< double > npl::getRegressor ( std::vector< std::vector< double >> &  spec,
double  tr,
size_t  ntimes,
double  t0 
)

Takes a 1 or 3 column format of regressor and produces a timeseries sampeled every tr, starting at time t0, and running for ntimes.

3 column format:

onset duration value

1 column format (value of 1 is assumed):

onsert

Parameters
spec
tr
ntimes
t0
Returns
template<typename T >
GraphDataT npl::getType ( )
void npl::gicaCreateMatrices ( size_t  tcat,
size_t  scat,
vector< std::string >  masks,
vector< std::string >  inputs,
std::string  prefix,
double  maxmem,
bool  normts,
bool  verbose 
)

Create on disk matrices based on an array of input images. The array will be concatinated in time tcat time and space scat time, with time as the faster dimension.

Parameters
tcatNumber of images to concatinate in time (faster moving in inputs)
scatNumber of images to concatinate in space (slower moving in inputs)
masksArray of all image masks, 1 per spatial concatination
inputsInput files, should be tcat*scat in size
prefixPrefix of output matrices. Will create prefix_tall_0, prefix_tall_1 ...
maxmemMaximum memory per individual tall file, this is used to limit the loaded memory at a time. There will be more file overhead for smaller memory (though not much)
normtsWhether to normalize the timeseries, within each input image before writing to flat matrices
verbosePrint more information during reorganization
void npl::gicaReduceFull ( std::string  inpref,
std::string  outpref,
double  varthresh,
double  cvarthresh,
size_t  maxrank,
bool  verbose 
)

Compute PCA for the given group, defined.

The basic idea is to split the rows into digesteable chunks, then perform the SVD on each of them.

A = [A1 A2 A3 ... ] A = [UEV1 UEV2 .... ] A = [UE1 UE2 UE3 ...] diag([V1, V2, V3...])

UE1 should have far fewer columns than rows so that where A is RxC, with R < C, [UE1 ... ] should have be R x LN with LN < R

Say we are concatinating S subjects each with T timepoints, then A is STxC, assuming a rank of L then [UE1 ... ] will be ST x SL

Even if L = T / 2 then this is a 1/4 savings in the SVD computation

Parameters
inprefinput prefix of reorganized data matrices
outprefoutput prefix for U,E,V matrices
varthreshthreshold for singular values, everything smaller than this ratio of the leading singular value will be treated as zero
cvarthreshthreshold for singular values, everything after this ratio of the total sum of singular values will be treated as zero
maxrankmaximum rank to use in reduction
verbosewhether to print debuging information
void npl::gicaReduceProb ( std::string  inpref,
std::string  outpref,
double  varthresh,
double  cvarthresh,
size_t  rank,
size_t  poweriters,
bool  verbose 
)

Compute PCA for the given group, defined.

The basic idea is to split the rows into digesteable chunks, then perform the SVD on each of them.

A = [A1 A2 A3 ... ] A = [UEV1 UEV2 .... ] A = [UE1 UE2 UE3 ...] diag([V1, V2, V3...])

UE1 should have far fewer columns than rows so that where A is RxC, with R < C, [UE1 ... ] should have be R x LN with LN < R

Say we are concatinating S subjects each with T timepoints, then A is STxC, assuming a rank of L then [UE1 ... ] will be ST x SL

Even if L = T / 2 then this is a 1/4 savings in the SVD computation

Parameters
inprefinput prefix of reorganized data matrices
outprefoutput prefix for U,E,V matrices
ranknumber of rows to estimate full matrix
poweritersnumber of power iterations to perform do better distringuish between close singular values 2-3 are probably sufficient for most cases
varthreshthreshold for singular values, everything smaller than this ratio of the leading singular value will be treated as zero
cvarthreshthreshold for singular values, everything after this ratio of the total sum of singular values will be treated as zero
verbosewhether to print debuging information
void npl::gicaSpatialICA ( std::string  reorgpref,
std::string  reducepref,
std::string  outpref,
bool  verbose 
)

Perform ICA with each dimension as a separate timeseries. This is essentially unmixing in space and producing independent timeseries.

Parameters
reorgprefPrefix of tall input file *_tall_[0-9]*
reduceprefPrefix input files *Umat, *Vmat *Evec files
outprefOutput file prefix *_SpaceIC *TimeIC etc
verboseWhether to print more debugging information
void npl::gicaTemporalICA ( std::string  reorgpref,
std::string  reducepref,
std::string  outpref,
bool  verbose 
)

Perform ICA with each dimension as a separate timeseries. This is essentially unmixing in space and producing independent timeseries.

Parameters
reorgprefPrefix of tall input file *_tall_[0-9]*
reduceprefPrefix input files *Umat, *Vmat *Evec files
outprefOutput file prefix *_SpaceIC *TimeIC etc
verboseWhether to print more debugging information
double npl::hammingWindow ( double  x,
double  a 
)
inline

Definition at line 132 of file basic_functions.h.

double npl::hannWindow ( double  x,
double  a 
)
inline

Definition at line 170 of file basic_functions.h.

int npl::hob ( int  num)
inline

Highest order bit.

Parameters
numInput, output will be this with the highest order bit set
Returns

Definition at line 424 of file basic_functions.h.

void npl::interp ( int64_t  isize,
fftw_complex *  in,
int64_t  osize,
fftw_complex *  out 
)

Interpolate the input array, filling the output array.

Parameters
isizeSize of in
inValues to interpolate
osizeSize of out
outOutput array, filled with interpolated values of in
Matrix<1, 1> npl::inverse ( const Matrix< 1, 1 > &  trg)

Definition at line 735 of file matrix_deprecated.h.

Matrix<2, 2> npl::inverse ( const Matrix< 2, 2 > &  trg)

Definition at line 740 of file matrix_deprecated.h.

template<int DIM>
Matrix<DIM, DIM> npl::inverse ( const Matrix< DIM, DIM > &  trg)

Definition at line 757 of file matrix_deprecated.h.

bool npl::isTxt ( std::string  filename)

Reads a file and returns true if its entirely made up of printable ascii.

Parameters
filenamename of file to read
Returns
if the file is text
template<int D1, int D2>
Matrix<D1+D2,D1+D2> npl::join ( const Matrix< D1, D1 > &  tl,
const Matrix< D1, D2 > &  tr,
const Matrix< D2, D1 > &  bl,
const Matrix< D2, D2 > &  br 
)

Join together 4 matrices from a blockwise decomposition.

Template Parameters
D1
D2
Parameters
tl
tr
bl
br
Returns

Definition at line 554 of file matrix_deprecated.h.

double npl::lanczosKern ( double  x,
double  a 
)
inline

Derivative of lanczos kernel with respect to x.

Parameters
xDistance from center (0)
aRadius
Returns
Weight

Definition at line 189 of file basic_functions.h.

double npl::linKern ( double  x,
double  a 
)
inline

Definition at line 222 of file basic_functions.h.

bool npl::little_endian ( )
inline

Definition at line 28 of file byteswap.h.

template<int D1, int D2>
double npl::norm ( const Matrix< D1, D2 > &  trg)

Definition at line 676 of file matrix_deprecated.h.

template<int DIM>
double npl::norm ( const Matrix< DIM, 1 > &  trg)

Definition at line 684 of file matrix_deprecated.h.

template<int DIM>
double npl::norm ( const Matrix< 1, DIM > &  trg)

Definition at line 693 of file matrix_deprecated.h.

VectorXd npl::onDiskSVD ( const MatrixReorg A,
int  rank,
size_t  poweriters,
double  varthresh,
double  cvarthresh,
MatrixXd *  U = NULL,
MatrixXd *  V = NULL 
)

Uses randomized subspace approximation to reduce the input matrix (made up of blocks stored on disk with a given prefix). This assumes that the matrix is a wide matrix (which is generally a good assumption in fMRI) and that it therefore is better to reduce the number of columns.

To achieve this, we transpose the algorithm of 4.4 from Halko N, Martinsson P-G, Tropp J A. Finding structure with randomness: Probabilistic algorithms for constructing approximate matrix decompositions. 2009;1–74. Available from: http://arxiv.org/abs/0909.4061

Parameters
AMatrixReorg object that can be used to load images on disk
rankNumber of output columns (output rank)
poweritersNumber of power iterations to perform. 2 passes over A are required for each iteration, but iteration drives error to 0 at an exponential rate
varthreshstop after the eigenvalues reach this ratio of the maximum
cvarthreshstop after the sum of eigenvalues reaches this ratio of total
UOutput U matrix, if null then ignored
VOutput V matrix, if null then ignored
Returns
Vector of singular values
rgb_t npl::operator* ( const rgb_t lhs,
const double &  rhs 
)
rgb_t npl::operator* ( const double &  lhs,
const rgb_t rhs 
)
rgba_t npl::operator* ( const rgba_t lhs,
const double &  rhs 
)
rgba_t npl::operator* ( const double &  lhs,
const rgba_t rhs 
)
template<int D1, int D2, int D3>
Matrix<D1, D3> npl::operator* ( const Matrix< D1, D2 > &  lhs,
const Matrix< D2, D3 > &  rhs 
)

Definition at line 527 of file matrix_deprecated.h.

rgb_t npl::operator+ ( const rgb_t lhs,
const double &  rhs 
)
rgb_t npl::operator+ ( const double &  lhs,
const rgb_t rhs 
)
rgba_t npl::operator+ ( const rgba_t lhs,
const double &  rhs 
)
rgba_t npl::operator+ ( const double &  lhs,
const rgba_t rhs 
)
template<int D1, int D2>
Matrix<D1, D2> npl::operator+ ( const Matrix< D1, D2 > &  lhs,
const Matrix< D1, D2 > &  rhs 
)

Definition at line 491 of file matrix_deprecated.h.

template<int D1, int D2>
Matrix<D1, D2> npl::operator+= ( Matrix< D1, D2 > &  lhs,
const Matrix< D1, D2 > &  rhs 
)

Definition at line 480 of file matrix_deprecated.h.

rgb_t npl::operator- ( const rgb_t lhs,
const double &  rhs 
)
rgb_t npl::operator- ( const double &  lhs,
const rgb_t rhs 
)
rgba_t npl::operator- ( const rgba_t lhs,
const double &  rhs 
)
rgba_t npl::operator- ( const double &  lhs,
const rgba_t rhs 
)
template<int D1, int D2>
Matrix<D1, D2> npl::operator- ( const Matrix< D1, D2 > &  lhs,
const Matrix< D1, D2 > &  rhs 
)

Definition at line 503 of file matrix_deprecated.h.

template<int D1, int D2>
Matrix<D1, D2> npl::operator- ( const Matrix< D1, D2 > &  rhs)

Definition at line 515 of file matrix_deprecated.h.

rgb_t npl::operator/ ( const rgb_t lhs,
const double &  rhs 
)
rgb_t npl::operator/ ( const double &  lhs,
const rgb_t rhs 
)
rgba_t npl::operator/ ( const rgba_t lhs,
const double &  rhs 
)
rgba_t npl::operator/ ( const double &  lhs,
const rgba_t rhs 
)
std::ostream& npl::operator<< ( std::ostream &  stream,
const rgb_t v 
)
std::ostream& npl::operator<< ( std::ostream &  stream,
const rgba_t v 
)
template<int D1, int D2>
std::ostream& npl::operator<< ( std::ostream &  os,
const Matrix< D1, D2 > &  b 
)

Definition at line 452 of file matrix_deprecated.h.

std::ostream& npl::operator<< ( std::ostream &  os,
const MatrixP b 
)

Definition at line 465 of file matrix_deprecated.h.

std::vector<std::string> npl::parseLine ( std::string  line,
std::string  delim 
)

Given a delimiter splits the line based on the delmiter and removes extra white space as necessary.

Note that repeated white space characters will be removed but other delimiters wont be

TODO handle ", " which should technically be ignored and maybe \, but not \, etc

Parameters
linestring holding the line
delimcharacter delimiter[s]
Returns
vector of strings, one string per parsed token
double npl::radToDeg ( double  rad)
inline

Definition at line 411 of file basic_functions.h.

TrackSet npl::readDFT ( std::string  tfile,
std::string  ref = "" 
)

Reads a BrainSuite DFT file. Throws INVALID_ARGUMENT if the magic is wrong.

Parameters
tfiletrk file
refReference image
Returns
vector of vector of points
ptr<MRImage> npl::readMRImage ( std::string  filename,
bool  verbose = false,
bool  nopixeldata = false 
)

Reads an MRI image. Right now only nift images are supported. later on, it will try to load image using different reader functions until one suceeds.

Parameters
filenameName of input file to read
verboseWhether to print out information as the file is read
nopixeldataDon't actually read the pixel data, just the header and create the image. So if you want to copy an image's orientation and structure, this would be the way to do it without wasting time actually reading.
Returns
Loaded image
ptr<NDArray> npl::readNDArray ( std::string  filename,
bool  verbose = false,
bool  nopixeldata = false 
)

Reads an array. Can read nifti's but orientation won't be read.

Parameters
filenameName of input file to read
verboseWhether to print out information as the file is read
nopixeldataDon't actually read the pixel data, just the header and create the image. So if you want to copy an image's orientation and structure, this would be the way to do it without wasting time actually reading.
Returns
Loaded image
std::vector<std::vector<double> > npl::readNumericCSV ( std::string  filename,
char  comment = '#' 
)

This function parses an input and returns a list of rows.

This function reads a text file of the form: DvDvDvD....Dv[D] by deciding whether white space or commas or semi-colons is the delimiter and then proceeding to read each line. It does this by looking at the first 10 lines and comparing the line based on each possible deliminter. out

Parameters
filenamefile to read
commentlines with this first non-white space character will be ignored
Returns
out vector of rows (stored in vectors)
std::vector<std::vector<std::string> > npl::readStrCSV ( std::string  filename,
char &  delim,
char  comment = '#' 
)

This function parses an input and returns a list of rows.

This function reads a text file of the form: DvDvDvD....Dv[D] by deciding whether white space or commas or semi-colons is the delimiter and then proceeding to read each line. It does this by looking at the first 10 lines and comparing the line based on each possible deliminter. out

Parameters
filenamefile to read
delimOutput: Delimiter found (this gets set).
commentlines with this first non-white space character will be ignored
Returns
out vector of rows (stored in vectors)
TrackSet npl::readTracks ( std::string  filename,
std::string  ref = "" 
)

Reads tracks into a vector of tracks, where each track is a vector of float[3].

Parameters
filenameFile storing tracks
refMatching image used to construct the tracks (for orientation information). This is mandatory for DFT files, which lack orientation information of their own
Returns
vector<vector<float[3]>> aka TrackSet
TrackSet npl::readTrk ( std::string  filename,
std::string  ref = "" 
)

Reads a trackvis trk file. Throws INVALID_ARGUMENT if the magic is wrong.

Parameters
filenametrk file
refReference image (in case the RAS is not valid)
Returns
double npl::rectWindow ( double  x,
double  a 
)
inline

Rectangle function centered at 0, with radius a, range should be = 2a.

Parameters
xdistance from center
aradius
Returns
weight

Definition at line 80 of file basic_functions.h.

ptr<MRImage> npl::regressOut ( ptr< const MRImage inimg,
const MatrixXd &  X 
)

Regresses out the given variables, creating time series which are uncorrelated with X.

Parameters
inimgInput 4D image
Xmatrix of covariates
int64_t npl::round2 ( int64_t  in)
inline

Round up to the nearest power of 2.

Parameters
inNumber to round
Returns
Rounded up umber

Definition at line 446 of file basic_functions.h.

int64_t npl::round357 ( int64_t  in)
inline

Rounds a number up to the nearest number that can be broken down into 3,5,7.

Parameters
inInput number
Returns
Next number up that matches the requirement

Definition at line 485 of file basic_functions.h.

double npl::sd_to_fwhm ( double  sd)
inline

Computes the FWHM from from standard deviation (because I can never remember the ratio)

Parameters
sdStandard deviation of a Gaussian function.
Returns
Full-width-half-max size of the same gaussian function

Definition at line 265 of file utility.h.

double npl::sec ( double  v)
inline

Secand function.

Parameters
vangle in radians
Returns
Secand of angle

Definition at line 398 of file basic_functions.h.

double npl::sincWindow ( double  x,
double  a 
)
inline

Sinc function centered at 0, with radius a, range should be = 2a.

Parameters
xdistance from center
aradius
Returns
weight

Definition at line 97 of file basic_functions.h.

template<int D1, int D2>
void npl::split ( const Matrix< D1+D2, D1+D2 > &  input,
Matrix< D1, D1 > &  tl,
Matrix< D1, D2 > &  tr,
Matrix< D2, D1 > &  bl,
Matrix< D2, D2 > &  br 
)

Definition at line 591 of file matrix_deprecated.h.

template<typename T >
void npl::swap ( T *  val)

Definition at line 52 of file byteswap.h.

template<>
void npl::swap< cdouble_t > ( cdouble_t val)
inline

Definition at line 106 of file byteswap.h.

template<>
void npl::swap< cfloat_t > ( cfloat_t val)
inline

Definition at line 126 of file byteswap.h.

template<>
void npl::swap< char > ( char *  val)
inline

Definition at line 71 of file byteswap.h.

template<>
void npl::swap< cquad_t > ( cquad_t val)
inline

Definition at line 86 of file byteswap.h.

template<>
void npl::swap< rgb_t > ( rgb_t val)
inline

Definition at line 153 of file byteswap.h.

template<>
void npl::swap< rgba_t > ( rgba_t val)
inline

Definition at line 146 of file byteswap.h.

template<>
void npl::swap< signed char > ( signed char *  val)
inline

Definition at line 63 of file byteswap.h.

template<>
void npl::swap< uint8_t > ( uint8_t *  val)
inline

Definition at line 78 of file byteswap.h.

double npl::welchWindow ( double  x,
double  a 
)
inline

Definition at line 152 of file basic_functions.h.

template<typename T >
T npl::wrap ( inf,
sup,
v 
)
inline

Wraps and index based on the range [inf, sup] (when v is outside that) range. Thus inf = 1, sup = 5, v = 0 will wrap around to 4, and v = 6 would wrap around to 1.

Template Parameters
TValue of inf/sup/v
Parameters
inflower bound (inclusive)
supupper bound (inclusive)
vvalueto wrap. Output will be the position wrapped.
Returns
Wrapped value

Definition at line 59 of file basic_functions.h.

int npl::writeMRImage ( ptr< const MRImage img,
std::string  fn,
bool  nifti2 = false 
)

Writes out an MRImage to the file fn. Bool indicates whether to use nifti2 (rather than nifti1) format.

Parameters
imgImage to write.
fnFilename
nifti2Whether the use nifti2 format
Returns
0 if successful
int npl::writeNDArray ( ptr< const NDArray img,
std::string  fn,
bool  nifti2 = false 
)

Writes out an MRImage to the file fn. Bool indicates whether to use nifti2 (rather than nifti1) format.

Parameters
imgImage to write.
fnFilename
nifti2Whether the use nifti2 format
Returns
0 if successful
template<typename T >
void npl::writePlot ( std::string  filename,
const std::vector< T > &  data 
)

Writes a plot to the given filename. This is a convience wrapper around Plotter, which for quick-and-dirty use might be too much setup.

Template Parameters
TType of data to plot (will be cast to double)
Parameters
filename
dataVector of data to plot

Definition at line 229 of file basic_plot.h.

template<typename T >
void npl::writePlot ( std::string  filename,
const std::vector< T > &  data,
size_t  xsize,
size_t  ysize 
)

Writes a plot to the given filename. This is a convience wrapper around Plotter, which for quick-and-dirty use might be too much setup.

Template Parameters
TType of data to plot (will be cast to double)
Parameters
filename
dataVector of 1D data to plot
xsizesize output image (only matters for raster images *.tga)
ysizesize output image (only matters for raster images *.tga)

Definition at line 252 of file basic_plot.h.

void npl::writePlotAbsAng ( std::string  file,
size_t  insz,
fftw_complex *  in 
)

Plots an array of complex points with the Real and Imaginary Parts.

Writes a 2D plot of the complex array where both absolute value and angle * values are plotted together.

Parameters
fileFilename
inszSize of in
inArray input
fileFilename base
inszSize of in array
inArray of complex values
void npl::writePlotReIm ( std::string  file,
const std::vector< std::complex< double >> &  in 
)

Plots an array of complex points with the Real and Imaginary Parts.

Parameters
fileFilename
inArray input
void npl::writePlotReIm ( std::string  file,
size_t  insz,
fftw_complex *  in 
)

Plots an array of complex points with the Real and Imaginary Parts.

Writes a 2D plot of the complex array where both real and imaginary values are plotted together.

Parameters
fileFilename
inszSize of in
inArray input
fileFilename base
inszSize of in array
inArray of complex values
void npl::zoom ( size_t  isize,
fftw_complex *  in,
fftw_complex *  out,
double  a 
)

Performs a de-facto chirpz by interpolated zoom of a fourier-space line.

Parameters
isizeSize of input array
inInput array (which should be in the fourier domain)
outOutput array
aZoom factor (should be -1 <= a <= 1)

Variable Documentation

class npl::MatMap npl::__attribute__
const size_t npl::MAXDIM = 10

Defines the maximum supported dimension by image, used for stack-allocations.

Definition at line 46 of file ndarray.h.