NPL
Neurological Programs and Libraries
npl::MRImage Class Referenceabstract

MRImage can basically be used like an NDArray, with the addition of orientation related additions. More...

#include <mrimage.h>

Inherits npl::NDArray.

Inherited by npl::MRImageStore< 3, double > [virtual], npl::MRImageStore< 4, double > [virtual], npl::MRImageStore< 5, double > [virtual], and npl::MRImageStore< D, T > [virtual].

Public Member Functions

 MRImage ()
 
void orientDefault ()
 Default orientation (dir=ident, space=1 and origin=0), also resizes them. So this could be called without first initializing size. More...
 
bool isOriented ()
 Returns true if the image has a valid orientation. More...
 
void setOrient (const VectorXd &neworig, const VectorXd &newspace, const MatrixXd &newdir, bool reinit=true, CoordinateT coord=QFORM)
 Update the orientation of the pixels in RAS space. More...
 
const double & direction (int64_t row, int64_t col) const
 Returns reference to a value in the direction matrix. Each row indicates the direction of the grid in RAS coordinates. This is the rotation of the Index grid. More...
 
const double & invdirection (int64_t row, int64_t col) const
 Returns reference to a value in the inverse direction matrix. Each row indicates the direction of the grid in RAS coordinates. This is the rotation of the Index grid. More...
 
const MatrixXd & getDirection () const
 Returns reference to the direction matrix. Each row indicates the direction of the grid in RAS coordinates. This is the rotation of the Index grid. More...
 
void setDirection (const MatrixXd &newdir, bool reinit, CoordinateT coord=QFORM)
 Updates orientation information. If reinit is given then it will first set direction to the identity. otherwise old values will be left. After this the first min(DIMENSION,dir.rows()) columns and min(DIMENSION,dir.cols()) columns will be copies into the image direction matrix. More...
 
double & origin (int64_t row)
 Returns reference to a value in the origin vector. This is the physical point that corresponds to index 0. More...
 
const double & origin (int64_t row) const
 Returns reference to a value in the origin vector. This is the physical point that corresponds to index 0. More...
 
const VectorXd & getOrigin () const
 Returns const reference to the origin vector. This is the physical point that corresponds to index 0. More...
 
void setOrigin (const VectorXd &neworigin, bool reinit)
 Sets the origin vector. This is the physical point that corresponds to index 0. Note that min(current, new) elements will be copied. More...
 
double & spacing (int64_t row)
 Returns reference to a value in the spacing vector. This is the physical distance between adjacent indexes. More...
 
const double & spacing (int64_t row) const
 Returns reference to a value in the spacing vector. This is the physical distance between adjacent indexes. More...
 
const VectorXd & getSpacing () const
 Returns const reference to the spacing vector. This is the physical distance between adjacent indexes. More...
 
void setSpacing (const VectorXd &newspacing, bool reinit)
 Sets the spacing vector. This is the physical point that corresponds to index 0. Note that min(current, new) elements will be copied. More...
 
virtual int indexToPoint (size_t len, const int64_t *xyz, double *ras) const =0
 
virtual int indexToPoint (size_t len, const double *xyz, double *ras) const =0
 Converts an index in pixel space to RAS, physical/time coordinates. If len < dimensions, additional dimensions are assumed to be 0. If len > dimensions then additional values are ignored, and only the first DIM values will be transformed and written to ras. More...
 
virtual int pointToIndex (size_t len, const double *ras, double *xyz) const =0
 Converts a point in RAS coordinate system to index. If len < dimensions, additional dimensions are assumed to be 0. If len > dimensions then additional values are ignored, and only the first DIM values will be transformed and written to ras. More...
 
virtual int pointToIndex (size_t len, const double *ras, int64_t *index) const =0
 Converts a point in RAS coordinate system to index. If len < dimensions, additional dimensions are assumed to be 0. If len > dimensions then additional values are ignored, and only the first DIM values will be transformed and written to ras. More...
 
virtual int orientVector (size_t len, const double *xyz, double *ras) const =0
 Convert a vector in index coordinates to a vector in ras coordinates. Vector is simply multiplied by the internal rotation matrix. More...
 
virtual int disOrientVector (size_t len, const double *ras, double *xyz) const =0
 Convert a vector in index coordinates to a vector in ras coordinates. Vector is simply multiplied by the internal rotation matrix. More...
 
virtual bool pointInsideFOV (size_t len, const double *ras) const =0
 Returns true if the point is within the field of view of the image. Note, like all coordinates pass to MRImage, if the array given differs from the dimensions of the image, then the result will either pad out zeros and ignore extra values in the input array. More...
 
virtual bool indexInsideFOV (size_t len, const double *xyz) const =0
 Returns true if the constinuous index is within the field of view of the image. Note, like all coordinates pass to MRImage, if the array given differs from the dimensions of the image, then the result will either pad out zeros and ignore extra values in the input array. More...
 
virtual bool indexInsideFOV (size_t len, const int64_t *xyz) const =0
 Returns true if the constinuous index is within the field of view of the image. Note, like all coordinates pass to MRImage, if the array given differs from the dimensions of the image, then the result will either pad out zeros and ignore extra values in the input array. More...
 
virtual bool matchingOrient (ptr< const MRImage > other, bool checkdim, bool checksize, double tol=0.01) const
 Returns true of the other image has matching orientation as this. If checksize = true, then it will also check the size of the two images and return true if both orientation and size match, and false if they don't. More...
 
virtual bool isIsotropic (bool only3d=true, double tol=0.01) const
 Returns true if the image is isotropic (same spacing in all dimensions). This can be looseened to checking only the first 3 dims with only3d = true. Tolerence in the absolute maximum difference between the first dim and any other dim. More...
 
virtual int write (std::string filename, double version=1) const =0
 Write the image to a nifti file. More...
 
ptr< MRImagegetPtr ()
 Returns a pointer to self. More...
 
ptr< const MRImagegetConstPtr () const
 Returns a constant pointer to self. More...
 
virtual ptr< MRImagecloneImage () const =0
 Create a copy of this image. This is identical to copy() but will return a pointer to an image rather than an NDArray. More...
 
virtual ptr< NDArraycopy () const =0
 Performs a deep copy of the entire image and all metadata. More...
 
virtual ptr< NDArraycreateAnother () const =0
 Creates an identical array, but does not initialize pixel values. More...
 
virtual ptr< NDArraycreateAnother (size_t newdims, const size_t *newsize, PixelT newtype) const =0
 Create a new array that is the same underlying type as this. If this is an image then it will also copy the metdata, but NOT the pixels. More...
 
virtual ptr< NDArraycreateAnother (PixelT newtype) const =0
 Create a new array that is the same underlying type as this, but with a different pixel type. More...
 
virtual ptr< NDArraycreateAnother (size_t newdims, const size_t *newsize) const =0
 Create a new array that is the same underlying type as this, and same pixel type and orientation as this, but with a different size. More...
 
virtual ptr< NDArraycopyCast (size_t newdims, const size_t *newsize, PixelT newtype) const =0
 Create a new image that is a copy of the input, possibly with new dimensions and pixeltype. The new image will have all overlapping pixels copied from the old image. More...
 
virtual ptr< NDArraycopyCast (PixelT newtype) const =0
 Create a new image that is a copy of the input, with same dimensions but pxiels cast to newtype. The new image will have all overlapping pixels copied from the old image. More...
 
virtual ptr< NDArraycopyCast (size_t newdims, const size_t *newsize) const =0
 Create a new image that is a copy of the input, possibly with new dimensions or size. The new image will have all overlapping pixels copied from the old image. The new image will have the same pixel type as the input image. More...
 
virtual ptr< NDArrayextractCast (size_t len, const int64_t *index, const size_t *size) const =0
 extracts a region of this image. Zeros in the size variable indicate dimension to be removed. More...
 
virtual ptr< NDArrayextractCast (size_t len, const size_t *size) const =0
 extracts a region of this image. Zeros in the size variable indicate dimension to be removed. More...
 
virtual ptr< NDArrayextractCast (size_t len, const int64_t *index, const size_t *size, PixelT newtype) const =0
 extracts a region of this image. Zeros in the size variable indicate dimension to be removed. More...
 
virtual ptr< NDArrayextractCast (size_t len, const size_t *size, PixelT newtype) const =0
 extracts a region of this image. Zeros in the size variable indicate dimension to be removed. More...
 
virtual void copyMetadata (ptr< const MRImage > src)
 Copies metadata from another image. This includes slice timing, anything read from nifti files, spacing, orientation etc, but NOT pixel data, size, and dimensionality. More...
 
void updateSliceTiming (double duration, int start, int end, SliceOrderT order)
 
virtual size_t ndim () const =0
 
virtual size_t bytes () const =0
 
virtual size_t bytesper () const =0
 
virtual size_t elements () const =0
 
virtual size_t dim (size_t dir) const =0
 
virtual const size_t * dim () const =0
 
virtual PixelT type () const =0
 Return enum PixelT type of pixels. More...
 
bool floatType () const
 Returns true if the stored type is FLOAT32, FLOAT64, or FLOAT128, ie is a pure float type. More...
 
bool complexType () const
 Returns true if the stored type is COMPLEX256, COMPLEX128, or COMPLEX64, ie is a complex floating point type. More...
 
bool signedType () const
 Returns true if the stored type is a variant of signed integer . More...
 
bool unsignedType () const
 Returns true if the stored type is a variant of unsigned signed integer. More...
 
virtual void * data ()=0
 
virtual const void * data () const =0
 
virtual void zero ()=0
 Sets all elements to zero. More...
 
virtual void * __getAddr (std::initializer_list< int64_t > index) const =0
 
virtual void * __getAddr (size_t len, const int64_t *index) const =0
 
virtual void * __getAddr (const std::vector< int64_t > &index) const =0
 
virtual void * __getAddr (int64_t i) const =0
 
virtual void * __getAddr (int64_t x, int64_t y, int64_t z, int64_t t) const =0
 
virtual int64_t getLinIndex (std::initializer_list< int64_t > index) const =0
 
virtual int64_t getLinIndex (size_t len, const int64_t *index) const =0
 
virtual int64_t getLinIndex (const std::vector< int64_t > &index) const =0
 
virtual int64_t getLinIndex (int64_t x, int64_t y, int64_t z, int64_t t) const =0
 
virtual int64_t tlen () const =0
 This function just returns the number of elements in a theoretical fourth dimension (ignoring orgnaization of higher dimensions) More...
 

Public Attributes

int m_freqdim
 
int m_phasedim
 
int m_slicedim
 
CoordinateT m_coordinate
 
double m_slice_duration
 
int m_slice_start
 
int m_slice_end
 
SliceOrderT m_slice_order
 
std::map< int64_t, double > m_slice_timing
 

Protected Member Functions

virtual int writeNifti1Image (gzFile file) const =0
 
virtual int writeNifti2Image (gzFile file) const =0
 

Protected Attributes

MatrixXd m_direction
 Direction Matrix. Each row indicates the direction of the grid in RAS coordinates. This is the rotation of the Index grid. Note that you should not set this directly,. More...
 
MatrixXd m_inv_direction
 Inverse of Direction Matrix. More...
 
VectorXd m_spacing
 Spacing vector. Indicates distance between adjacent pixels in each dimension. Note that you should not set this directly, use setSpacing() instead because it will update the affine Matrix. More...
 
VectorXd m_origin
 Origin vector. Indicates the RAS coordinates of index [0,0,0,..] Note that you should not set this directly, use setOrigin() instead because it will update the affine Matrix. More...
 
std::function< void(void *)> m_freefunc
 The function which should be called when deleting data. By default this will just be delete[], but if data is grafted or if. More...
 

Friends

ptr< MRImagereadNiftiImage (gzFile file, bool verbose)
 

Detailed Description

MRImage can basically be used like an NDArray, with the addition of orientation related additions.

Definition at line 123 of file mrimage.h.

Constructor & Destructor Documentation

npl::MRImage::MRImage ( )
inline

Definition at line 126 of file mrimage.h.

Member Function Documentation

virtual void* npl::NDArray::__getAddr ( std::initializer_list< int64_t >  index) const
pure virtualinherited
virtual void* npl::NDArray::__getAddr ( size_t  len,
const int64_t *  index 
) const
pure virtualinherited
virtual void* npl::NDArray::__getAddr ( const std::vector< int64_t > &  index) const
pure virtualinherited
virtual void* npl::NDArray::__getAddr ( int64_t  i) const
pure virtualinherited
virtual void* npl::NDArray::__getAddr ( int64_t  x,
int64_t  y,
int64_t  z,
int64_t  t 
) const
pure virtualinherited
virtual size_t npl::NDArray::bytes ( ) const
pure virtualinherited
virtual size_t npl::NDArray::bytesper ( ) const
pure virtualinherited
virtual ptr<MRImage> npl::MRImage::cloneImage ( ) const
pure virtual

Create a copy of this image. This is identical to copy() but will return a pointer to an image rather than an NDArray.

Returns
Pointer to deep-copied image.

Implemented in npl::MRImageStore< D, T >, npl::MRImageStore< 3, double >, npl::MRImageStore< 4, double >, and npl::MRImageStore< 5, double >.

bool npl::NDArray::complexType ( ) const
inlineinherited

Returns true if the stored type is COMPLEX256, COMPLEX128, or COMPLEX64, ie is a complex floating point type.

Returns
True if the number can be represented by a complex<long double>

Definition at line 203 of file ndarray.h.

virtual ptr<NDArray> npl::MRImage::copy ( ) const
pure virtual

Performs a deep copy of the entire image and all metadata.

Returns
Copied image (as NDarray pointer)

Implements npl::NDArray.

Implemented in npl::MRImageStore< D, T >, npl::MRImageStore< 3, double >, npl::MRImageStore< 4, double >, and npl::MRImageStore< 5, double >.

virtual ptr<NDArray> npl::MRImage::copyCast ( size_t  newdims,
const size_t *  newsize,
PixelT  newtype 
) const
pure virtual

Create a new image that is a copy of the input, possibly with new dimensions and pixeltype. The new image will have all overlapping pixels copied from the old image.

Parameters
newdimsNumber of dimensions in output image
newsizeSize of output image
newtypeType of pixels in output image
Returns
Image with overlapping sections cast and copied from 'in'

Implements npl::NDArray.

Implemented in npl::MRImageStore< D, T >, npl::MRImageStore< 3, double >, npl::MRImageStore< 4, double >, and npl::MRImageStore< 5, double >.

virtual ptr<NDArray> npl::MRImage::copyCast ( PixelT  newtype) const
pure virtual

Create a new image that is a copy of the input, with same dimensions but pxiels cast to newtype. The new image will have all overlapping pixels copied from the old image.

Parameters
newtypeType of pixels in output image
Returns
Image with overlapping sections cast and copied from 'in'

Implements npl::NDArray.

Implemented in npl::MRImageStore< D, T >, npl::MRImageStore< 3, double >, npl::MRImageStore< 4, double >, and npl::MRImageStore< 5, double >.

virtual ptr<NDArray> npl::MRImage::copyCast ( size_t  newdims,
const size_t *  newsize 
) const
pure virtual

Create a new image that is a copy of the input, possibly with new dimensions or size. The new image will have all overlapping pixels copied from the old image. The new image will have the same pixel type as the input image.

Parameters
newdimsNumber of dimensions in output image
newsizeSize of output image
Returns
Image with overlapping sections cast and copied from 'in'

Implements npl::NDArray.

Implemented in npl::MRImageStore< D, T >, npl::MRImageStore< 3, double >, npl::MRImageStore< 4, double >, and npl::MRImageStore< 5, double >.

virtual void npl::MRImage::copyMetadata ( ptr< const MRImage src)
virtual

Copies metadata from another image. This includes slice timing, anything read from nifti files, spacing, orientation etc, but NOT pixel data, size, and dimensionality.

Parameters
srcOther image to copy from
virtual ptr<NDArray> npl::MRImage::createAnother ( ) const
pure virtual

Creates an identical array, but does not initialize pixel values.

Returns
New array.

Implements npl::NDArray.

Implemented in npl::MRImageStore< D, T >, npl::MRImageStore< 3, double >, npl::MRImageStore< 4, double >, and npl::MRImageStore< 5, double >.

virtual ptr<NDArray> npl::MRImage::createAnother ( size_t  newdims,
const size_t *  newsize,
PixelT  newtype 
) const
pure virtual

Create a new array that is the same underlying type as this. If this is an image then it will also copy the metdata, but NOT the pixels.

Parameters
newdimsNumber of dimensions in copied output
newsizeSize of output, this array should be of size newdims
newtypeType of pixels in output array
Returns
Image with identical orientation but different size and pixeltype

Implements npl::NDArray.

Implemented in npl::MRImageStore< D, T >, npl::MRImageStore< 3, double >, npl::MRImageStore< 4, double >, and npl::MRImageStore< 5, double >.

virtual ptr<NDArray> npl::MRImage::createAnother ( PixelT  newtype) const
pure virtual

Create a new array that is the same underlying type as this, but with a different pixel type.

Parameters
newtypeType of pixels in output array
Returns
Image with identical orientation and size but different pixel type

Implements npl::NDArray.

Implemented in npl::MRImageStore< D, T >, npl::MRImageStore< 3, double >, npl::MRImageStore< 4, double >, and npl::MRImageStore< 5, double >.

virtual ptr<NDArray> npl::MRImage::createAnother ( size_t  newdims,
const size_t *  newsize 
) const
pure virtual

Create a new array that is the same underlying type as this, and same pixel type and orientation as this, but with a different size.

Parameters
newdimsNumber of dimensions in output array
newsizeInput array of length newdims that gives the size of output array,
Returns
Image with identical orientation and pixel type but different size from this

Implements npl::NDArray.

Implemented in npl::MRImageStore< D, T >, npl::MRImageStore< 3, double >, npl::MRImageStore< 4, double >, and npl::MRImageStore< 5, double >.

virtual const void* npl::NDArray::data ( ) const
pure virtualinherited
virtual size_t npl::NDArray::dim ( size_t  dir) const
pure virtualinherited
virtual const size_t* npl::NDArray::dim ( ) const
pure virtualinherited
const double& npl::MRImage::direction ( int64_t  row,
int64_t  col 
) const

Returns reference to a value in the direction matrix. Each row indicates the direction of the grid in RAS coordinates. This is the rotation of the Index grid.

Parameters
rowRow to access
colColumn to access
Returns
Element in direction matrix
virtual int npl::MRImage::disOrientVector ( size_t  len,
const double *  ras,
double *  xyz 
) const
pure virtual

Convert a vector in index coordinates to a vector in ras coordinates. Vector is simply multiplied by the internal rotation matrix.

Parameters
lenLength of input vector (may be different than dimension - extra values will be ignored, missing values will be assumed zero)
rasInput vector in physical space.
xyzOutput vector in index space ijk. This is the product of the input vector and inverse rotation matrix
Returns
Success

Implemented in npl::MRImageStore< D, T >, npl::MRImageStore< 3, double >, npl::MRImageStore< 4, double >, and npl::MRImageStore< 5, double >.

virtual size_t npl::NDArray::elements ( ) const
pure virtualinherited
virtual ptr<NDArray> npl::MRImage::extractCast ( size_t  len,
const int64_t *  index,
const size_t *  size 
) const
pure virtual

extracts a region of this image. Zeros in the size variable indicate dimension to be removed.

Parameters
lenLength of index/newsize arrays
indexIndex to start copying from.
sizeSize of output image. Note length 0 dimensions will be removed, while length 1 dimensions will be left.
Returns
Image with overlapping sections cast and copied from 'in'

Implements npl::NDArray.

Implemented in npl::MRImageStore< D, T >, npl::MRImageStore< 3, double >, npl::MRImageStore< 4, double >, and npl::MRImageStore< 5, double >.

virtual ptr<NDArray> npl::MRImage::extractCast ( size_t  len,
const size_t *  size 
) const
pure virtual

extracts a region of this image. Zeros in the size variable indicate dimension to be removed.

Parameters
lenLength of index/size arrays
sizeSize of output image. Note length 0 dimensions will be removed, while length 1 dimensions will be left.
Returns
Image with overlapping sections cast and copied from 'in'

Implements npl::NDArray.

Implemented in npl::MRImageStore< D, T >, npl::MRImageStore< 3, double >, npl::MRImageStore< 4, double >, and npl::MRImageStore< 5, double >.

virtual ptr<NDArray> npl::MRImage::extractCast ( size_t  len,
const int64_t *  index,
const size_t *  size,
PixelT  newtype 
) const
pure virtual

extracts a region of this image. Zeros in the size variable indicate dimension to be removed.

Parameters
lenLength of index/size arrays
indexIndex to start copying from.
sizeSize of output image. Note length 0 dimensions will be removed, while length 1 dimensions will be left.
newtypePixel type of output image.
Returns
Image with overlapping sections cast and copied from 'in'

Implements npl::NDArray.

Implemented in npl::MRImageStore< D, T >, npl::MRImageStore< 3, double >, npl::MRImageStore< 4, double >, and npl::MRImageStore< 5, double >.

virtual ptr<NDArray> npl::MRImage::extractCast ( size_t  len,
const size_t *  size,
PixelT  newtype 
) const
pure virtual

extracts a region of this image. Zeros in the size variable indicate dimension to be removed.

Parameters
lenLength of index/size arrays
sizeSize of output image. Note length 0 dimensions will be removed, while length 1 dimensions will be left.
newtypePixel type of output image.
Returns
Image with overlapping sections cast and copied from 'in'

Implements npl::NDArray.

Implemented in npl::MRImageStore< D, T >, npl::MRImageStore< 3, double >, npl::MRImageStore< 4, double >, and npl::MRImageStore< 5, double >.

bool npl::NDArray::floatType ( ) const
inlineinherited

Returns true if the stored type is FLOAT32, FLOAT64, or FLOAT128, ie is a pure float type.

Returns
True if the number can be represented by a long double

Definition at line 193 of file ndarray.h.

ptr<const MRImage> npl::MRImage::getConstPtr ( ) const
inline

Returns a constant pointer to self.

Returns
this

Definition at line 490 of file mrimage.h.

const MatrixXd& npl::MRImage::getDirection ( ) const

Returns reference to the direction matrix. Each row indicates the direction of the grid in RAS coordinates. This is the rotation of the Index grid.

Returns
Direction matrix
virtual int64_t npl::NDArray::getLinIndex ( std::initializer_list< int64_t >  index) const
pure virtualinherited
virtual int64_t npl::NDArray::getLinIndex ( size_t  len,
const int64_t *  index 
) const
pure virtualinherited
virtual int64_t npl::NDArray::getLinIndex ( const std::vector< int64_t > &  index) const
pure virtualinherited
virtual int64_t npl::NDArray::getLinIndex ( int64_t  x,
int64_t  y,
int64_t  z,
int64_t  t 
) const
pure virtualinherited
const VectorXd& npl::MRImage::getOrigin ( ) const

Returns const reference to the origin vector. This is the physical point that corresponds to index 0.

Returns
Origin vector
ptr<MRImage> npl::MRImage::getPtr ( )
inline

Returns a pointer to self.

Returns
this

Definition at line 481 of file mrimage.h.

const VectorXd& npl::MRImage::getSpacing ( ) const

Returns const reference to the spacing vector. This is the physical distance between adjacent indexes.

Returns
Spacing vector
virtual bool npl::MRImage::indexInsideFOV ( size_t  len,
const double *  xyz 
) const
pure virtual

Returns true if the constinuous index is within the field of view of the image. Note, like all coordinates pass to MRImage, if the array given differs from the dimensions of the image, then the result will either pad out zeros and ignore extra values in the input array.

Parameters
lenLength of xyz array
xyzArray of continouos indices
Returns
Whether the index would round to a voxel inside the image.

Implemented in npl::MRImageStore< D, T >, npl::MRImageStore< 3, double >, npl::MRImageStore< 4, double >, and npl::MRImageStore< 5, double >.

virtual bool npl::MRImage::indexInsideFOV ( size_t  len,
const int64_t *  xyz 
) const
pure virtual

Returns true if the constinuous index is within the field of view of the image. Note, like all coordinates pass to MRImage, if the array given differs from the dimensions of the image, then the result will either pad out zeros and ignore extra values in the input array.

Parameters
lenLength of xyz array
xyzArray of indices
Returns
Whether the index is inside the image

Implemented in npl::MRImageStore< D, T >, npl::MRImageStore< 3, double >, npl::MRImageStore< 4, double >, and npl::MRImageStore< 5, double >.

virtual int npl::MRImage::indexToPoint ( size_t  len,
const int64_t *  xyz,
double *  ras 
) const
pure virtual
virtual int npl::MRImage::indexToPoint ( size_t  len,
const double *  xyz,
double *  ras 
) const
pure virtual

Converts an index in pixel space to RAS, physical/time coordinates. If len < dimensions, additional dimensions are assumed to be 0. If len > dimensions then additional values are ignored, and only the first DIM values will be transformed and written to ras.

Parameters
lenLength of xyz/ras arrays.
xyzArray in xyz... coordinates (maybe as long as you want).
rasCorresponding coordinate
Returns
0

Implemented in npl::MRImageStore< D, T >, npl::MRImageStore< 3, double >, npl::MRImageStore< 4, double >, and npl::MRImageStore< 5, double >.

const double& npl::MRImage::invdirection ( int64_t  row,
int64_t  col 
) const

Returns reference to a value in the inverse direction matrix. Each row indicates the direction of the grid in RAS coordinates. This is the rotation of the Index grid.

Parameters
rowRow to access
colColumn to access
Returns
Element in direction matrix
virtual bool npl::MRImage::isIsotropic ( bool  only3d = true,
double  tol = 0.01 
) const
virtual

Returns true if the image is isotropic (same spacing in all dimensions). This can be looseened to checking only the first 3 dims with only3d = true. Tolerence in the absolute maximum difference between the first dim and any other dim.

Parameters
only3dOnly check spacing in the first 3 dimensions (default)
tolTolerence in the absolute maximum difference between the first dim and any other dim.
Returns
True if the image is roughly isotropic
bool npl::MRImage::isOriented ( )
inline

Returns true if the image has a valid orientation.

Returns
True if the image has a valid orientation

Definition at line 145 of file mrimage.h.

virtual bool npl::MRImage::matchingOrient ( ptr< const MRImage other,
bool  checkdim,
bool  checksize,
double  tol = 0.01 
) const
virtual

Returns true of the other image has matching orientation as this. If checksize = true, then it will also check the size of the two images and return true if both orientation and size match, and false if they don't.

Parameters
otherMRimage to compare.
checkdimWhether to enforce identical dimensionality. If this is false then the first min(D1,D2) dimensions will be checked, if this is true then mismatched dimensionality will cause this to return a false
checksizeWhether to enforce identical size as well as orientation
toltolerance for differences in orientation. Because the orientation matrix must undergo floating operationt to convert from Quaternions there are likely to be (small) errors.
Returns
True if the two images have matching orientation information.
void npl::MRImage::orientDefault ( )

Default orientation (dir=ident, space=1 and origin=0), also resizes them. So this could be called without first initializing size.

virtual int npl::MRImage::orientVector ( size_t  len,
const double *  xyz,
double *  ras 
) const
pure virtual

Convert a vector in index coordinates to a vector in ras coordinates. Vector is simply multiplied by the internal rotation matrix.

Parameters
lenLength of input vector (may be different than dimension - extra values will be ignored, missing values will be assumed zero)
xyzInput vector in index space ijk....
rasOutput vector in physical space. This is the product of the input vector and rotation matrix
Returns
Success

Implemented in npl::MRImageStore< D, T >, npl::MRImageStore< 3, double >, npl::MRImageStore< 4, double >, and npl::MRImageStore< 5, double >.

double& npl::MRImage::origin ( int64_t  row)

Returns reference to a value in the origin vector. This is the physical point that corresponds to index 0.

Parameters
rowRow to access
Returns
Element in origin vector
const double& npl::MRImage::origin ( int64_t  row) const

Returns reference to a value in the origin vector. This is the physical point that corresponds to index 0.

Parameters
rowRow to access
Returns
Element in origin vector
virtual bool npl::MRImage::pointInsideFOV ( size_t  len,
const double *  ras 
) const
pure virtual

Returns true if the point is within the field of view of the image. Note, like all coordinates pass to MRImage, if the array given differs from the dimensions of the image, then the result will either pad out zeros and ignore extra values in the input array.

Parameters
lenLength of RAS array
rasArray of Right-handed coordinates Right+, Anterior+, Superior+
Returns
Whether the point would round to a voxel inside the image.

Implemented in npl::MRImageStore< D, T >, npl::MRImageStore< 3, double >, npl::MRImageStore< 4, double >, and npl::MRImageStore< 5, double >.

virtual int npl::MRImage::pointToIndex ( size_t  len,
const double *  ras,
double *  xyz 
) const
pure virtual

Converts a point in RAS coordinate system to index. If len < dimensions, additional dimensions are assumed to be 0. If len > dimensions then additional values are ignored, and only the first DIM values will be transformed and written to ras.

Parameters
lenLength of xyz/ras arrays.
rasArray in RAS... coordinates (may be as long as you want).
xyzCorresponding coordinate
Returns
0

Implemented in npl::MRImageStore< D, T >, npl::MRImageStore< 3, double >, npl::MRImageStore< 4, double >, and npl::MRImageStore< 5, double >.

virtual int npl::MRImage::pointToIndex ( size_t  len,
const double *  ras,
int64_t *  index 
) const
pure virtual

Converts a point in RAS coordinate system to index. If len < dimensions, additional dimensions are assumed to be 0. If len > dimensions then additional values are ignored, and only the first DIM values will be transformed and written to ras.

Parameters
lenLength of xyz/ras arrays.
rasArray in RAS... coordinates (may be as long as you want).
indexCorresponding coordinate, rounded to nearest integer
Returns
0

Implemented in npl::MRImageStore< D, T >, npl::MRImageStore< 3, double >, npl::MRImageStore< 4, double >, and npl::MRImageStore< 5, double >.

void npl::MRImage::setDirection ( const MatrixXd &  newdir,
bool  reinit,
CoordinateT  coord = QFORM 
)

Updates orientation information. If reinit is given then it will first set direction to the identity. otherwise old values will be left. After this the first min(DIMENSION,dir.rows()) columns and min(DIMENSION,dir.cols()) columns will be copies into the image direction matrix.

Parameters
newdirInput direction/rotation
reinitWhether to reset everything to Identity/0 before applying. You may want to do this if theinput matrices/vectors differ in dimension from this image.
coordcoordinate system this refers to. Eventually this might include more advanced options (scanner,anat etc). For now it is just QFORM or SFORM
void npl::MRImage::setOrient ( const VectorXd &  neworig,
const VectorXd &  newspace,
const MatrixXd &  newdir,
bool  reinit = true,
CoordinateT  coord = QFORM 
)

Update the orientation of the pixels in RAS space.

Parameters
neworigNew Origin.
newspaceNew Spacing.
newdirNew Direction
reinitWhether to reset everything to Identity/0 before applying. You may want to do this if theinput matrices/vectors differ in dimension from this image.
coordcoordinate system this refers to. Eventually this might include more advanced options (scanner,anat etc). For now it is just QFORM or SFORM
void npl::MRImage::setOrigin ( const VectorXd &  neworigin,
bool  reinit 
)

Sets the origin vector. This is the physical point that corresponds to index 0. Note that min(current, new) elements will be copied.

Parameters
neworiginthe new origin vector to copy.
reinitWhether to reset everything to Identity/0 before applying. You may want to do this if theinput matrices/vectors differ in dimension from this image.
void npl::MRImage::setSpacing ( const VectorXd &  newspacing,
bool  reinit 
)

Sets the spacing vector. This is the physical point that corresponds to index 0. Note that min(current, new) elements will be copied.

Parameters
newspacingthe new spacing vector to copy.
reinitSet the whole vector to 1s first. This might be useful if you are setting fewer elements than dimensions
bool npl::NDArray::signedType ( ) const
inlineinherited

Returns true if the stored type is a variant of signed integer .

Returns
True if the number can be represented by an int64_t

Definition at line 212 of file ndarray.h.

double& npl::MRImage::spacing ( int64_t  row)

Returns reference to a value in the spacing vector. This is the physical distance between adjacent indexes.

Parameters
rowRow to access
Returns
Element in spacing vector
const double& npl::MRImage::spacing ( int64_t  row) const

Returns reference to a value in the spacing vector. This is the physical distance between adjacent indexes.

Parameters
rowRow to access
Returns
Element in spacing vector
virtual int64_t npl::NDArray::tlen ( ) const
pure virtualinherited

This function just returns the number of elements in a theoretical fourth dimension (ignoring orgnaization of higher dimensions)

Returns
number of elements in the 4th or greater dimensions

Implemented in npl::NDArrayStore< D, T >, npl::NDArrayStore< D, double >, npl::NDArrayStore< 1, double >, npl::NDArrayStore< 2, double >, and npl::NDArrayStore< 3, double >.

virtual PixelT npl::NDArray::type ( ) const
pure virtualinherited
bool npl::NDArray::unsignedType ( ) const
inlineinherited

Returns true if the stored type is a variant of unsigned signed integer.

Returns
True if the number can be represented by an size_t

Definition at line 222 of file ndarray.h.

void npl::MRImage::updateSliceTiming ( double  duration,
int  start,
int  end,
SliceOrderT  order 
)
virtual int npl::MRImage::write ( std::string  filename,
double  version = 1 
) const
pure virtual

Write the image to a nifti file.

Parameters
filenameFilename
versionVersion of nifti to use
Returns
0 if successful

Implements npl::NDArray.

Implemented in npl::MRImageStore< D, T >, npl::MRImageStore< 3, double >, npl::MRImageStore< 4, double >, and npl::MRImageStore< 5, double >.

virtual int npl::MRImage::writeNifti1Image ( gzFile  file) const
protectedpure virtual
virtual int npl::MRImage::writeNifti2Image ( gzFile  file) const
protectedpure virtual
virtual void npl::NDArray::zero ( )
pure virtualinherited

Friends And Related Function Documentation

ptr<MRImage> readNiftiImage ( gzFile  file,
bool  verbose 
)
friend

Member Data Documentation

CoordinateT npl::MRImage::m_coordinate

Definition at line 675 of file mrimage.h.

MatrixXd npl::MRImage::m_direction
protected

Direction Matrix. Each row indicates the direction of the grid in RAS coordinates. This is the rotation of the Index grid. Note that you should not set this directly,.

Definition at line 714 of file mrimage.h.

std::function<void(void*)> npl::NDArray::m_freefunc
protectedinherited

The function which should be called when deleting data. By default this will just be delete[], but if data is grafted or if.

Definition at line 435 of file ndarray.h.

int npl::MRImage::m_freqdim

Definition at line 672 of file mrimage.h.

MatrixXd npl::MRImage::m_inv_direction
protected

Inverse of Direction Matrix.

Definition at line 719 of file mrimage.h.

VectorXd npl::MRImage::m_origin
protected

Origin vector. Indicates the RAS coordinates of index [0,0,0,..] Note that you should not set this directly, use setOrigin() instead because it will update the affine Matrix.

Definition at line 733 of file mrimage.h.

int npl::MRImage::m_phasedim

Definition at line 673 of file mrimage.h.

double npl::MRImage::m_slice_duration

Definition at line 685 of file mrimage.h.

int npl::MRImage::m_slice_end

Definition at line 687 of file mrimage.h.

SliceOrderT npl::MRImage::m_slice_order

Definition at line 700 of file mrimage.h.

int npl::MRImage::m_slice_start

Definition at line 686 of file mrimage.h.

std::map<int64_t,double> npl::MRImage::m_slice_timing

Definition at line 703 of file mrimage.h.

int npl::MRImage::m_slicedim

Definition at line 674 of file mrimage.h.

VectorXd npl::MRImage::m_spacing
protected

Spacing vector. Indicates distance between adjacent pixels in each dimension. Note that you should not set this directly, use setSpacing() instead because it will update the affine Matrix.

Definition at line 726 of file mrimage.h.


The documentation for this class was generated from the following file: