RNifti
Fast R and C++ Access to NIfTI Images
|
Thin wrapper around a C-style nifti_image
struct that allows C++-style destruction.
More...
#include <NiftiImage.h>
Classes | |
struct | Block |
Inner class referring to a subset of an image. More... | |
Public Member Functions | |
NiftiImage () | |
Default constructor. | |
NiftiImage (const NiftiImage &source) | |
Copy constructor. More... | |
NiftiImage (const Block &source) | |
Initialise from a block, copying in the data. More... | |
NiftiImage (nifti_image *const image, const bool copy=false) | |
Initialise using an existing nifti_image pointer. More... | |
NiftiImage (const std::string &path, const bool readData=true) | |
Initialise using a path string. More... | |
NiftiImage (const std::string &path, const std::vector< int > &volumes) | |
Initialise using a path string and sequence of required volumes. More... | |
virtual | ~NiftiImage () |
Destructor which frees the wrapped pointer, unless the object is marked as persistent. | |
operator const nifti_image * () const | |
Allows a NiftiImage object to be treated as a pointer to a const nifti_image . | |
operator nifti_image * () | |
Allows a NiftiImage object to be treated as a pointer to a nifti_image . | |
const nifti_image * | operator-> () const |
Allows a NiftiImage object to be treated as a pointer to a const nifti_image . | |
nifti_image * | operator-> () |
Allows a NiftiImage object to be treated as a pointer to a nifti_image . | |
NiftiImage & | operator= (const NiftiImage &source) |
Copy assignment operator, which copies from its argument. More... | |
NiftiImage & | operator= (const Block &source) |
Copy assignment operator, which allows a block to be used to replace the contents of a suitably sized image. More... | |
NiftiImage & | setPersistence (const bool persistent) |
Marked the image as persistent, so that it can be passed back to R. More... | |
bool | isNull () const |
Determine whether or not the internal pointer is NULL . | |
bool | isPersistent () const |
Determine whether or not the image is marked as persistent. | |
bool | isDataScaled () const |
Determine whether nontrivial scale and slope parameters are set. | |
int | nDims () const |
Return the number of dimensions in the image. | |
std::vector< int > | dim () const |
Return the dimensions of the image. More... | |
std::vector< float > | pixdim () const |
Return the dimensions of the pixels or voxels in the image. More... | |
NiftiImage & | drop () |
Drop unitary dimensions. More... | |
template<typename TargetType > | |
std::vector< TargetType > | getData (const bool useSlope=true) const |
Extract a vector of data from the image, casting it to any required element type. More... | |
NiftiImage & | changeDatatype (const short datatype, const bool useSlope=false) |
Change the datatype of the image, casting the pixel data if present. More... | |
NiftiImage & | changeDatatype (const std::string &datatype, const bool useSlope=false) |
Change the datatype of the image, casting the pixel data if present. More... | |
template<typename SourceType > | |
NiftiImage & | replaceData (const std::vector< SourceType > &data, const short datatype=DT_NONE) |
Replace the pixel data in the image with the contents of a vector. More... | |
NiftiImage & | dropData () |
Drop the data from the image, retaining only the metadata. | |
NiftiImage & | rescale (const std::vector< float > &scales) |
Rescale the image, changing its image dimensions and pixel dimensions. More... | |
NiftiImage & | reorient (const int i, const int j, const int k) |
Reorient the image by permuting dimensions and potentially reversing some. More... | |
NiftiImage & | reorient (const std::string &orientation) |
Reorient the image by permuting dimensions and potentially reversing some. More... | |
mat44 | xform (const bool preferQuaternion=true) const |
Obtain an xform matrix, indicating the orientation of the image. More... | |
int | nBlocks () const |
Return the number of blocks in the image. | |
const Block | block (const int i) const |
Extract a block from the image. More... | |
Block | block (const int i) |
Extract a block from the image. More... | |
const Block | slice (const int i) const |
Extract a slice block from a 3D image. More... | |
Block | slice (const int i) |
Extract a slice block from a 3D image. More... | |
const Block | volume (const int i) const |
Extract a volume block from a 4D image. More... | |
Block | volume (const int i) |
Extract a volume block from a 4D image. More... | |
void | toFile (const std::string fileName, const short datatype=DT_NONE) const |
Write the image to a NIfTI-1 file. More... | |
void | toFile (const std::string fileName, const std::string &datatype) const |
Write the image to a NIfTI-1 file. More... | |
Static Public Member Functions | |
static mat33 | xformToRotation (const mat44 matrix) |
Extract the pure rotation part of a 4x4 xform matrix. More... | |
static std::string | xformToString (const mat44 matrix) |
Convert a 4x4 xform matrix to a string describing its canonical axes. More... | |
static int | fileVersion (const std::string &path) |
Get the NIfTI format version used by the file at the specified path. More... | |
Protected Member Functions | |
void | copy (const nifti_image *source) |
Copy the contents of a nifti_image to create a new image. More... | |
void | copy (const NiftiImage &source) |
Copy the contents of another NiftiImage to create a new image. More... | |
void | copy (const Block &source) |
Copy the contents of a Block to create a new image. More... | |
void | updatePixdim (const std::vector< float > &pixdim) |
Modify the pixel dimensions, and potentially the xform matrices to match. More... | |
void | setPixunits (const std::vector< std::string > &pixunits) |
Modify the pixel dimension units. More... | |
Protected Attributes | |
nifti_image * | image |
The wrapped nifti_image pointer. | |
bool | persistent |
Marker of persistence, which determines whether the nifti_image should be freed on destruction. | |
Thin wrapper around a C-style nifti_image
struct that allows C++-style destruction.
|
inline |
Copy constructor.
source | Another NiftiImage object |
|
inline |
Initialise from a block, copying in the data.
source | A Block object, referring to part of another NiftiImage |
|
inline |
Initialise using an existing nifti_image
pointer.
image | An existing nifti_image pointer, possibly NULL |
copy | If true , the image data will be copied; otherwise this object just wraps the pointer passed to it |
|
inline |
Initialise using a path string.
path | A string specifying a path to a valid NIfTI-1 file, possibly gzipped |
readData | If true , the data will be read as well as the metadata |
runtime_error | If reading from the file fails |
|
inline |
Initialise using a path string and sequence of required volumes.
path | A string specifying a path to a valid NIfTI-1 file, possibly gzipped |
volumes | The volumes to read in (squashing all dimensions above the third together) |
runtime_error | If reading from the file fails, or volumes is empty |
|
inline |
|
inline |
|
inline |
Change the datatype of the image, casting the pixel data if present.
datatype | A NIfTI datatype code |
useSlope | If true , and conversion is to an integer type, the data will be rescaled and the image's slope and intercept set to capture the full range of original values |
|
inline |
Change the datatype of the image, casting the pixel data if present.
datatype | A string specifying the new datatype |
useSlope | If true , and conversion is to an integer type, the data will be rescaled and the image's slope and intercept set to capture the full range of original values |
|
inlineprotected |
Copy the contents of a nifti_image
to create a new image.
source | A pointer to a nifti_image |
|
inlineprotected |
Copy the contents of another NiftiImage
to create a new image.
source | A reference to a NiftiImage |
|
inlineprotected |
|
inline |
Return the dimensions of the image.
|
inline |
Drop unitary dimensions.
|
inlinestatic |
Get the NIfTI format version used by the file at the specified path.
path | A string specifying a file path |
|
inline |
Extract a vector of data from the image, casting it to any required element type.
useSlope | If true , the default, then the data will be adjusted for the slope and intercept stored with the image, if any |
|
inline |
Copy assignment operator, which copies from its argument.
source | Another NiftiImage |
|
inline |
Copy assignment operator, which allows a block to be used to replace the contents of a suitably sized image.
source | A reference to a suitable Block object |
|
inline |
Return the dimensions of the pixels or voxels in the image.
|
inline |
Reorient the image by permuting dimensions and potentially reversing some.
i,j,k | Constants such as NIFTI_L2R , NIFTI_P2A and NIFTI_I2S , giving the canonical axes to reorient to |
|
inline |
Reorient the image by permuting dimensions and potentially reversing some.
orientation | A string containing some permutation of the letters L or R , P or A , I or S , giving the canonical axes to reorient to |
|
inline |
Replace the pixel data in the image with the contents of a vector.
data | A data vector, whose elements will be cast to match the datatype of the image. An exception will be raised if this does not have a length matching the image |
datatype | The final datatype required. By default the existing datatype of the image is used |
|
inline |
Rescale the image, changing its image dimensions and pixel dimensions.
scales | Vector of scale factors along each dimension |
|
inline |
Marked the image as persistent, so that it can be passed back to R.
persistent | The new persistence state of the object |
|
inlineprotected |
Modify the pixel dimension units.
pixunits | Vector of new pixel units, specified using their standard abbreviations |
|
inline |
|
inline |
|
inline |
Write the image to a NIfTI-1 file.
fileName | The file name to write to, with appropriate suffix (e.g. ".nii.gz") |
datatype | The datatype to use when writing the file |
|
inline |
Write the image to a NIfTI-1 file.
fileName | The file name to write to, with appropriate suffix (e.g. ".nii.gz") |
datatype | The datatype to use when writing the file, or "auto" |
|
inlineprotected |
Modify the pixel dimensions, and potentially the xform matrices to match.
pixdim | Vector of new pixel dimensions |
|
inline |
Extract a volume block from a 4D image.
i | The volume number required |
|
inline |
Extract a volume block from a 4D image.
i | The volume number required |
|
inline |
Obtain an xform matrix, indicating the orientation of the image.
preferQuaternion | If true , use the qform matrix in preference to the sform |
|
inlinestatic |
Extract the pure rotation part of a 4x4 xform matrix.
matrix | An xform matrix |
|
inlinestatic |
Convert a 4x4 xform matrix to a string describing its canonical axes.
matrix | An xform matrix |