|
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 SEXP object, const bool readData=true) | |
| Initialise from an R object. 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 |
| Extract a vector of data from the image, casting it to any required element type. | |
| NiftiImage & | changeDatatype (const short datatype) |
| Change the datatype of the image, casting the pixel data if present. More... | |
| NiftiImage & | changeDatatype (const std::string &datatype) |
| 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... | |
| NiftiImage & | update (const SEXP array) |
| Update the image from an R array. 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... | |
| Rcpp::RObject | toArray () const |
| Create an R array from the image. More... | |
| Rcpp::RObject | toPointer (const std::string label) const |
| Create an internal image to pass back to R. More... | |
| Rcpp::RObject | toArrayOrPointer (const bool internal, const std::string label) const |
| A conditional method that calls either toArray or toPointer. More... | |
| Rcpp::RObject | headerToList () const |
| Create an R list containing raw image metadata. More... | |
Static Public Member Functions | |
| static short | sexpTypeToNiftiType (const int sexpType) |
Convert between R SEXP object type and nifti_image datatype codes. More... | |
| static std::string | xformToString (const mat44 matrix) |
| Convert a 4x4 xform matrix to a string describing its canonical axes. 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 | initFromNiftiS4 (const Rcpp::RObject &object, const bool copyData=true) |
Initialise the object from an S4 object of class "nifti". More... | |
| void | initFromMriImage (const Rcpp::RObject &object, const bool copyData=true) |
Initialise the object from a reference object of class "MriImage". More... | |
| void | initFromList (const Rcpp::RObject &object) |
| Initialise the object from an R list with named elements, which can only contain metadata. More... | |
| void | initFromArray (const Rcpp::RObject &object, const bool copyData=true) |
| Initialise the object from an R array. 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 from an R object.
| object | The source object |
| readData | If true, the data will be copied as well as the metadata |
|
inline |
|
inline |
|
inline |
Change the datatype of the image, casting the pixel data if present.
| datatype | A NIfTI datatype code |
|
inline |
Change the datatype of the image, casting the pixel data if present.
| datatype | A string specifying the new datatype |
|
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.
|
inline |
Create an R list containing raw image metadata.
|
inlineprotected |
Initialise the object from an R array.
| object | The source object |
| copyData | If true, the data are copied in; otherwise just the metadata is extracted |
|
inlineprotected |
Initialise the object from an R list with named elements, which can only contain metadata.
| object | The source object |
|
inlineprotected |
Initialise the object from a reference object of class "MriImage".
| object | The source object |
| copyData | If true, the data are copied in; otherwise just the metadata is extracted |
|
inlineprotected |
Initialise the object from an S4 object of class "nifti".
| object | The source object |
| copyData | If true, the data are copied in; otherwise just the metadata is extracted |
|
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 |
|
inlinestatic |
Convert between R SEXP object type and nifti_image datatype codes.
| sexpType | A numeric R SEXP type code |
nifti_image datatype code | runtime_error | If a non-numeric type is passed |
|
inline |
|
inline |
|
inline |
Create an R array from the image.
|
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" |
|
inline |
Create an internal image to pass back to R.
| label | A string labelling the image |
|
inline |
Update the image from an R array.
| array | An R array object |
|
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 |
Convert a 4x4 xform matrix to a string describing its canonical axes.
| matrix | An xform matrix |
1.8.12