RNifti
Fast R and C++ Access to NIfTI Images
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
RNifti::NiftiImage Class Reference

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...
 
class  Extension
 Inner class wrapping a NIfTI extension, a weakly-specified standard for attaching additional metadata to NIfTI-1 and NIfTI-2 images. More...
 
class  Xform
 Inner class representing an xform matrix, which indicates the orientation and other spatial properties of an image. More...
 

Public Member Functions

 NiftiImage ()
 Default constructor.
 
 NiftiImage (const NiftiImage &source, const bool copy=true)
 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::vector< dim_t > &dim, const int datatype)
 Initialise from basic metadata, allocating and zeroing pixel data. More...
 
 NiftiImage (const std::vector< dim_t > &dim, const std::string &datatype)
 Initialise from basic metadata, allocating and zeroing pixel data. More...
 
 NiftiImage (const std::string &path, const bool readData=true)
 Initialise using a path string. More...
 
 NiftiImage (const std::string &path, const std::vector< dim_t > &volumes)
 Initialise using a path string and sequence of required volumes. More...
 
 NiftiImage (const SEXP object, const bool readData=true, const bool readOnly=false)
 Initialise from an R object, retrieving an existing image from an external pointer attribute if available; otherwise constructing a new one from the R object itself. More...
 
virtual ~NiftiImage ()
 Destructor which decrements the reference counter, and releases the wrapped pointer if the counter drops to zero.
 
 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.
 
NiftiImageoperator= (const NiftiImage &source)
 Copy assignment operator, which copies from its argument. More...
 
NiftiImageoperator= (const Block &source)
 Copy assignment operator, which allows a block to be used to replace the contents of a suitably sized image. More...
 
NiftiImagesetPersistence (const bool persistent)
 Mark the image as persistent, so that it can be passed back to R. More...
 
bool isNull () const
 Determine whether or not the wrapped pointer is NULL. More...
 
bool isShared () const
 Determine whether the wrapped pointer is shared with another NiftiImage. More...
 
bool isPersistent () const
 Determine whether or not the image is marked as persistent. More...
 
bool isDataScaled () const
 Determine whether nontrivial scale and slope parameters are set. More...
 
int nDims () const
 Return the number of dimensions in the image. More...
 
std::vector< dim_t > dim () const
 Return the dimensions of the image. More...
 
std::vector< pixdim_t > pixdim () const
 Return the dimensions of the pixels or voxels in the image. More...
 
NiftiImagedrop ()
 Drop unitary dimensions. More...
 
const NiftiImageData data () const
 Obtain the pixel data within the image. More...
 
NiftiImageData data ()
 Obtain the pixel data within the image. 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...
 
NiftiImagechangeDatatype (const int datatype, const bool useSlope=false)
 Change the datatype of the image, casting the pixel data if present. More...
 
NiftiImagechangeDatatype (const std::string &datatype, const bool useSlope=false)
 Change the datatype of the image, casting the pixel data if present. More...
 
template<typename SourceType >
NiftiImagereplaceData (const std::vector< SourceType > &data, const int datatype=DT_NONE)
 Replace the pixel data in the image with the contents of a vector. More...
 
NiftiImagereplaceData (const NiftiImageData &data)
 Replace the pixel data in the image with the contents of a NiftiImageData object. More...
 
NiftiImagedropData ()
 Drop the data from the image, retaining only the metadata. More...
 
NiftiImagerescale (const std::vector< pixdim_t > &scales)
 Rescale the image, changing its image dimensions and pixel dimensions. More...
 
NiftiImagereorient (const int i, const int j, const int k)
 Reorient the image by permuting dimensions and potentially reversing some. More...
 
NiftiImagereorient (const std::string &orientation)
 Reorient the image by permuting dimensions and potentially reversing some. More...
 
NiftiImageupdate (const Rcpp::RObject &object)
 Update the image from an R array. More...
 
const Xform xform (const bool preferQuaternion=true) const
 Obtain an xform matrix, indicating the orientation of the image. More...
 
const Xform qform () const
 Access the qform matrix. More...
 
Xform qform ()
 Access the qform matrix. More...
 
const Xform sform () const
 Access the sform matrix. More...
 
Xform sform ()
 Access the sform matrix. More...
 
dim_t nBlocks () const
 Return the number of blocks in the image. More...
 
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...
 
int nChannels () const
 Return the number of colour channels used by the image. More...
 
size_t nVoxels () const
 Return the number of voxels in the image. More...
 
int nExtensions () const
 Return the number of extensions associated with the image. More...
 
std::list< Extensionextensions (const int code=-1) const
 Return a list of the extensions associated with the image. More...
 
NiftiImageaddExtension (const Extension &extension)
 Add an extension to the image. More...
 
NiftiImagereplaceExtensions (const std::list< Extension > extensions)
 Replace all extensions with new ones. More...
 
NiftiImagedropExtensions ()
 Remove any extensions from the image. More...
 
std::pair< std::string, std::string > toFile (const std::string fileName, const int datatype=DT_NONE, const int filetype=-1) const
 Write the image to a NIfTI-1 file. More...
 
std::pair< std::string, std::string > toFile (const std::string fileName, const std::string &datatype, const int filetype=-1) 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...
 

Static Public Member Functions

static int sexpTypeToNiftiType (const int sexpType)
 Convert between R SEXP object type and nifti_image datatype codes. 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 acquire (nifti_image *const image)
 Acquire the specified pointer to a nifti_image struct, taking (possibly shared) responsibility for freeing the associated memory. More...
 
void acquire (const NiftiImage &source)
 Acquire the same pointer as another NiftiImage, incrementing the shared reference count. More...
 
void release ()
 Release the currently wrapped pointer, if it is not NULL, decrementing the reference count and releasing memory if there are no remaining references to the pointer.
 
void copy (const nifti_image *source)
 Copy the contents of a nifti_image to create a new image, acquiring the new pointer. More...
 
void copy (const NiftiImage &source)
 Copy the contents of another NiftiImage to create a new image, acquiring a new pointer. More...
 
void copy (const Block &source)
 Copy the contents of a Block to create a new image, acquiring a new pointer. 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 initFromDims (const std::vector< dim_t > &dim, const int datatype)
 Initialise an empty object from basic metadata. More...
 
void updatePixdim (const std::vector< pixdim_t > &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.
 
int * refCount
 A reference counter, shared with other objects wrapping the same pointer.
 

Detailed Description

Thin wrapper around a C-style nifti_image struct that allows C++-style destruction.

Reference counting is used to allow multiple NiftiImage objects to wrap the same nifti_image pointer, akin to a std::shared_ptr (but without requiring C++11).

Author
Jon Clayden (code@.nosp@m.clay.nosp@m.den.o.nosp@m.rg)

Constructor & Destructor Documentation

◆ NiftiImage() [1/8]

RNifti::NiftiImage::NiftiImage ( const NiftiImage source,
const bool  copy = true 
)
inline

Copy constructor.

Parameters
sourceAnother NiftiImage object
copyIf true, the underlying nifti_image will be copied; otherwise the new object wraps the same nifti_image and increments the shared reference count

◆ NiftiImage() [2/8]

RNifti::NiftiImage::NiftiImage ( const Block source)
inline

Initialise from a block, copying in the data.

Parameters
sourceA Block object, referring to part of another NiftiImage

◆ NiftiImage() [3/8]

RNifti::NiftiImage::NiftiImage ( nifti_image *const  image,
const bool  copy = false 
)
inline

Initialise using an existing nifti_image pointer.

Parameters
imageAn existing nifti_image pointer, possibly NULL
copyIf true, the image data will be copied; otherwise this object just wraps the pointer passed to it

◆ NiftiImage() [4/8]

RNifti::NiftiImage::NiftiImage ( const std::vector< dim_t > &  dim,
const int  datatype 
)

Initialise from basic metadata, allocating and zeroing pixel data.

Parameters
dimA vector of image dimensions
datatypeA datatype code for the image data

◆ NiftiImage() [5/8]

RNifti::NiftiImage::NiftiImage ( const std::vector< dim_t > &  dim,
const std::string &  datatype 
)

Initialise from basic metadata, allocating and zeroing pixel data.

Parameters
dimA vector of image dimensions
datatypeA datatype string for the image data

◆ NiftiImage() [6/8]

RNifti::NiftiImage::NiftiImage ( const std::string &  path,
const bool  readData = true 
)

Initialise using a path string.

Parameters
pathA string specifying a path to a valid NIfTI-1 file, possibly gzipped
readDataIf true, the data will be read as well as the metadata
Exceptions
runtime_errorIf reading from the file fails

◆ NiftiImage() [7/8]

RNifti::NiftiImage::NiftiImage ( const std::string &  path,
const std::vector< dim_t > &  volumes 
)

Initialise using a path string and sequence of required volumes.

Parameters
pathA string specifying a path to a valid NIfTI-1 file, possibly gzipped
volumesThe volumes to read in (squashing all dimensions above the third together)
Exceptions
runtime_errorIf reading from the file fails, or volumes is empty

◆ NiftiImage() [8/8]

RNifti::NiftiImage::NiftiImage ( const SEXP  object,
const bool  readData = true,
const bool  readOnly = false 
)

Initialise from an R object, retrieving an existing image from an external pointer attribute if available; otherwise constructing a new one from the R object itself.

Parameters
objectThe source object
readDataIf true, the data will be retrieved as well as the metadata
readOnlyIf true, the caller asserts that its intent is read-only. Otherwise, if the SEXP may have multiple names at the R level (according to the MAYBE_SHARED R macro), an image retrieved from an external pointer will be duplicated to preserve R's usual semantics

Member Function Documentation

◆ acquire() [1/2]

void RNifti::NiftiImage::acquire ( const NiftiImage source)
inlineprotected

Acquire the same pointer as another NiftiImage, incrementing the shared reference count.

Parameters
sourceA reference to a NiftiImage

◆ acquire() [2/2]

void RNifti::NiftiImage::acquire ( nifti_image *const  image)
protected

Acquire the specified pointer to a nifti_image struct, taking (possibly shared) responsibility for freeing the associated memory.

If the object currently wraps another pointer, it will be released

Parameters
imageThe pointer to wrap

◆ addExtension()

NiftiImage& RNifti::NiftiImage::addExtension ( const Extension extension)
inline

Add an extension to the image.

Parameters
Thenew image extension, an Extension object
Returns
Self, with the extension appended

◆ block() [1/2]

Block RNifti::NiftiImage::block ( const int  i)
inline

Extract a block from the image.

Parameters
iThe block number required
Returns
A Block object
Note
slice and volume are variants of this function specific to 3D and 4D images, respectively, which may be preferred in some cases for clarity

◆ block() [2/2]

const Block RNifti::NiftiImage::block ( const int  i) const
inline

Extract a block from the image.

Parameters
iThe block number required
Returns
A Block object
Note
slice and volume are variants of this function specific to 3D and 4D images, respectively, which may be preferred in some cases for clarity

◆ changeDatatype() [1/2]

NiftiImage& RNifti::NiftiImage::changeDatatype ( const int  datatype,
const bool  useSlope = false 
)

Change the datatype of the image, casting the pixel data if present.

Parameters
datatypeA NIfTI datatype code
useSlopeIf 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
Returns
Self, after changing the datatype

◆ changeDatatype() [2/2]

NiftiImage& RNifti::NiftiImage::changeDatatype ( const std::string &  datatype,
const bool  useSlope = false 
)

Change the datatype of the image, casting the pixel data if present.

Parameters
datatypeA string specifying the new datatype
useSlopeIf 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
Returns
Self, after changing the datatype

◆ copy() [1/3]

void RNifti::NiftiImage::copy ( const Block source)
protected

Copy the contents of a Block to create a new image, acquiring a new pointer.

Parameters
sourceA reference to a Block

◆ copy() [2/3]

void RNifti::NiftiImage::copy ( const nifti_image *  source)
protected

Copy the contents of a nifti_image to create a new image, acquiring the new pointer.

Parameters
sourceA pointer to a nifti_image

◆ copy() [3/3]

void RNifti::NiftiImage::copy ( const NiftiImage source)
protected

Copy the contents of another NiftiImage to create a new image, acquiring a new pointer.

Parameters
sourceA reference to a NiftiImage

◆ data() [1/2]

NiftiImageData RNifti::NiftiImage::data ( )
inline

Obtain the pixel data within the image.

Returns
A mutable NiftiImageData object encapsulating the data

◆ data() [2/2]

const NiftiImageData RNifti::NiftiImage::data ( ) const
inline

Obtain the pixel data within the image.

Returns
A constant NiftiImageData object encapsulating the data

◆ dim()

std::vector<dim_t> RNifti::NiftiImage::dim ( ) const
inline

Return the dimensions of the image.

Returns
A vector of integers giving the width in each dimension

◆ drop()

NiftiImage& RNifti::NiftiImage::drop ( )
inline

Drop unitary dimensions.

Returns
Self, after possibly reducing the dimensionality of the image
Note
This function differs from its R equivalent in only dropping unitary dimensions after the last nonunitary one

◆ dropData()

NiftiImage& RNifti::NiftiImage::dropData ( )
inline

Drop the data from the image, retaining only the metadata.

This method invalidates any NiftiImageData objects referencing the old data

Returns
Self, after dropping the data

◆ dropExtensions()

NiftiImage& RNifti::NiftiImage::dropExtensions ( )
inline

Remove any extensions from the image.

Returns
Self, with extensions removed

◆ extensions()

std::list<Extension> RNifti::NiftiImage::extensions ( const int  code = -1) const
inline

Return a list of the extensions associated with the image.

Parameters
codeInteger specifying the code corresponding to the extensions required. If -1, the default, all extensions are returned. There may be more than one extension with a given code
Returns
A list of Extension objects

◆ fileVersion()

static int RNifti::NiftiImage::fileVersion ( const std::string &  path)
static

Get the NIfTI format version used by the file at the specified path.

Parameters
pathA string specifying a file path
Returns
An integer: -1 if the file is not present or not valid, 0 for ANALYZE-7.5, or a value greater than 0 for NIfTI

◆ getData()

template<typename TargetType >
std::vector<TargetType> RNifti::NiftiImage::getData ( const bool  useSlope = true) const

Extract a vector of data from the image, casting it to any required element type.

Parameters
useSlopeIf true, the default, then the data will be adjusted for the slope and intercept stored with the image, if any
Returns
A vector of data values, cast to the required type
Note
If the slope and intercept are applied, there is no guarantee that the adjusted values will fit within the requested type. No check is made for this
Deprecated:
Use of the (ultimately more flexible) data methods is now preferred

◆ initFromArray()

void RNifti::NiftiImage::initFromArray ( const Rcpp::RObject &  object,
const bool  copyData = true 
)
protected

Initialise the object from an R array.

Parameters
objectThe source object
copyDataIf true, the data are copied in; otherwise just the metadata is extracted

◆ initFromDims()

void RNifti::NiftiImage::initFromDims ( const std::vector< dim_t > &  dim,
const int  datatype 
)
protected

Initialise an empty object from basic metadata.

Parameters
dimA vector of image dimensions
datatypeA datatype code for the image data

◆ initFromList()

void RNifti::NiftiImage::initFromList ( const Rcpp::RObject &  object)
protected

Initialise the object from an R list with named elements, which can only contain metadata.

Parameters
objectThe source object

◆ initFromMriImage()

void RNifti::NiftiImage::initFromMriImage ( const Rcpp::RObject &  object,
const bool  copyData = true 
)
protected

Initialise the object from a reference object of class "MriImage".

Parameters
objectThe source object
copyDataIf true, the data are copied in; otherwise just the metadata is extracted

◆ initFromNiftiS4()

void RNifti::NiftiImage::initFromNiftiS4 ( const Rcpp::RObject &  object,
const bool  copyData = true 
)
protected

Initialise the object from an S4 object of class "nifti".

Parameters
objectThe source object
copyDataIf true, the data are copied in; otherwise just the metadata is extracted

◆ isDataScaled()

bool RNifti::NiftiImage::isDataScaled ( ) const
inline

Determine whether nontrivial scale and slope parameters are set.

Returns
true if the object wraps an image pointer, its slope is not zero and the slope and intercept are not exactly one and zero; false otherwise

◆ isNull()

bool RNifti::NiftiImage::isNull ( ) const
inline

Determine whether or not the wrapped pointer is NULL.

Returns
true if the wrapped pointer is NULL; false otherwise

◆ isPersistent()

bool RNifti::NiftiImage::isPersistent ( ) const
inline

Determine whether or not the image is marked as persistent.

Returns
false, always
Deprecated:
The persistence mechanism has been replaced with reference counting, so this function will always return false. Use isShared instead.

◆ isShared()

bool RNifti::NiftiImage::isShared ( ) const
inline

Determine whether the wrapped pointer is shared with another NiftiImage.

Returns
true if the reference count is greater than 1; false otherwise

◆ nBlocks()

dim_t RNifti::NiftiImage::nBlocks ( ) const
inline

Return the number of blocks in the image.

Returns
An integer giving the number of blocks in the image

◆ nChannels()

int RNifti::NiftiImage::nChannels ( ) const
inline

Return the number of colour channels used by the image.

Returns
An integer giving the number of channels: generally 1, exception for RGB datatypes, which have 3 or 4, or the empty datatype, which has 0. Also 0 for null images

◆ nDims()

int RNifti::NiftiImage::nDims ( ) const
inline

Return the number of dimensions in the image.

Returns
An integer giving the image dimensionality

◆ nExtensions()

int RNifti::NiftiImage::nExtensions ( ) const
inline

Return the number of extensions associated with the image.

Returns
An integer giving the number of extensions

◆ nVoxels()

size_t RNifti::NiftiImage::nVoxels ( ) const
inline

Return the number of voxels in the image.

Returns
An integer giving the number of voxels in the image

◆ operator=() [1/2]

NiftiImage& RNifti::NiftiImage::operator= ( const Block source)
inline

Copy assignment operator, which allows a block to be used to replace the contents of a suitably sized image.

Parameters
sourceA reference to a suitable Block object

◆ operator=() [2/2]

NiftiImage& RNifti::NiftiImage::operator= ( const NiftiImage source)
inline

Copy assignment operator, which copies from its argument.

Parameters
sourceAnother NiftiImage

◆ pixdim()

std::vector<pixdim_t> RNifti::NiftiImage::pixdim ( ) const
inline

Return the dimensions of the pixels or voxels in the image.

Returns
A vector of floating-point values giving the pixel width in each dimension

◆ qform() [1/2]

Xform RNifti::NiftiImage::qform ( )
inline

Access the qform matrix.

Returns
An Xform object

◆ qform() [2/2]

const Xform RNifti::NiftiImage::qform ( ) const
inline

Access the qform matrix.

Returns
An Xform object

◆ reorient() [1/2]

NiftiImage& RNifti::NiftiImage::reorient ( const int  i,
const int  j,
const int  k 
)

Reorient the image by permuting dimensions and potentially reversing some.

Parameters
i,j,kConstants such as NIFTI_L2R, NIFTI_P2A and NIFTI_I2S, giving the canonical axes to reorient to
Returns
Self, after reorientation
Note
The pixel data is reordered, but not resampled. The xform matrices will also be adjusted in line with the transformation

◆ reorient() [2/2]

NiftiImage& RNifti::NiftiImage::reorient ( const std::string &  orientation)

Reorient the image by permuting dimensions and potentially reversing some.

Parameters
orientationA string containing some permutation of the letters L or R, P or A, I or S, giving the canonical axes to reorient to
Returns
Self, after reorientation
Note
The pixel data is reordered, but not resampled. The xform matrices will also be adjusted in line with the transformation

◆ replaceData() [1/2]

NiftiImage& RNifti::NiftiImage::replaceData ( const NiftiImageData data)

Replace the pixel data in the image with the contents of a NiftiImageData object.

Parameters
dataA data object, whose elements will be case to match the datatype of the image
Exceptions
runtime_errorIf the length of the new data does not match the image
Returns
Self, after replacing the data

◆ replaceData() [2/2]

template<typename SourceType >
NiftiImage& RNifti::NiftiImage::replaceData ( const std::vector< SourceType > &  data,
const int  datatype = DT_NONE 
)

Replace the pixel data in the image with the contents of a vector.

Parameters
dataA data vector, whose elements will be used to replace the image data
datatypeThe final datatype required. By default the existing datatype of the image is used
Exceptions
runtime_errorIf the length of the new data does not match the image
Returns
Self, after replacing the data

◆ replaceExtensions()

NiftiImage& RNifti::NiftiImage::replaceExtensions ( const std::list< Extension extensions)
inline

Replace all extensions with new ones.

Parameters
Alist of Extension objects
Returns
Self, with the new extensions attached

◆ rescale()

NiftiImage& RNifti::NiftiImage::rescale ( const std::vector< pixdim_t > &  scales)

Rescale the image, changing its image dimensions and pixel dimensions.

Parameters
scalesVector of scale factors along each dimension
Returns
Self, after rescaling the metadata
Note
No interpolation is performed on the pixel data, which is simply dropped

◆ setPersistence()

NiftiImage& RNifti::NiftiImage::setPersistence ( const bool  persistent)
inline

Mark the image as persistent, so that it can be passed back to R.

Parameters
persistentThe new persistence state of the object
Returns
A reference to the callee.
Deprecated:
The persistence mechanism has been replaced with reference counting, so this function no longer has any effect. Instead it returns *this, unmodified.

◆ setPixunits()

void RNifti::NiftiImage::setPixunits ( const std::vector< std::string > &  pixunits)
protected

Modify the pixel dimension units.

Parameters
pixunitsVector of new pixel units, specified using their standard abbreviations

◆ sexpTypeToNiftiType()

static int RNifti::NiftiImage::sexpTypeToNiftiType ( const int  sexpType)
inlinestatic

Convert between R SEXP object type and nifti_image datatype codes.

Parameters
sexpTypeA numeric R SEXP type code
Returns
A nifti_image datatype code
Exceptions
runtime_errorIf a non-numeric type is passed

◆ sform() [1/2]

Xform RNifti::NiftiImage::sform ( )
inline

Access the sform matrix.

Returns
An Xform object

◆ sform() [2/2]

const Xform RNifti::NiftiImage::sform ( ) const
inline

Access the sform matrix.

Returns
An Xform object

◆ slice() [1/2]

Block RNifti::NiftiImage::slice ( const int  i)
inline

Extract a slice block from a 3D image.

Parameters
iThe slice number required
Returns
A Block object

◆ slice() [2/2]

const Block RNifti::NiftiImage::slice ( const int  i) const
inline

Extract a slice block from a 3D image.

Parameters
iThe slice number required
Returns
A Block object

◆ toArray()

Rcpp::RObject RNifti::NiftiImage::toArray ( ) const

Create an R array from the image.

Returns
A numeric array object with an external pointer attribute

◆ toArrayOrPointer()

Rcpp::RObject RNifti::NiftiImage::toArrayOrPointer ( const bool  internal,
const std::string  label 
) const

A conditional method that calls either toArray or toPointer.

Parameters
internalIf true, toPointer will be called; otherwise toArray
labelA string labelling the image
Returns
An R object

◆ toFile() [1/2]

std::pair<std::string,std::string> RNifti::NiftiImage::toFile ( const std::string  fileName,
const int  datatype = DT_NONE,
const int  filetype = -1 
) const

Write the image to a NIfTI-1 file.

Parameters
fileNameThe file name to write to, with appropriate suffix (e.g. ".nii.gz")
datatypeThe datatype to use when writing the file
filetypeThe file type to create: a NIFTI_FTYPE constant or -1. In the latter case the file name is used to determine the file type
Returns
A pair of strings, giving the final header and image paths in that order

◆ toFile() [2/2]

std::pair<std::string,std::string> RNifti::NiftiImage::toFile ( const std::string  fileName,
const std::string &  datatype,
const int  filetype = -1 
) const

Write the image to a NIfTI-1 file.

Parameters
fileNameThe file name to write to, with appropriate suffix (e.g. ".nii.gz")
datatypeThe datatype to use when writing the file, or "auto"
filetypeThe file type to create: a NIFTI_FTYPE constant or -1. In the latter case the file name is used to determine the file type
Returns
A pair of strings, giving the final header and image paths in that order

◆ toPointer()

Rcpp::RObject RNifti::NiftiImage::toPointer ( const std::string  label) const

Create an internal image to pass back to R.

Parameters
labelA string labelling the image
Returns
An R character string with additional attributes

◆ update()

NiftiImage& RNifti::NiftiImage::update ( const Rcpp::RObject &  object)

Update the image from an R array.

Parameters
objectAn R array or list object
Returns
Self, after updating data and/or metadata

◆ updatePixdim()

void RNifti::NiftiImage::updatePixdim ( const std::vector< pixdim_t > &  pixdim)
protected

Modify the pixel dimensions, and potentially the xform matrices to match.

Parameters
pixdimVector of new pixel dimensions

◆ volume() [1/2]

Block RNifti::NiftiImage::volume ( const int  i)
inline

Extract a volume block from a 4D image.

Parameters
iThe volume number required
Returns
A Block object

◆ volume() [2/2]

const Block RNifti::NiftiImage::volume ( const int  i) const
inline

Extract a volume block from a 4D image.

Parameters
iThe volume number required
Returns
A Block object

◆ xform()

const Xform RNifti::NiftiImage::xform ( const bool  preferQuaternion = true) const

Obtain an xform matrix, indicating the orientation of the image.

Parameters
preferQuaternionIf true, use the qform matrix in preference to the sform; otherwise prefer the sform
Returns
An Xform object

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