mvpa2.misc.plot.lightbox.SpatialImage

Inheritance diagram of SpatialImage
class mvpa2.misc.plot.lightbox.SpatialImage(dataobj, affine, header=None, extra=None, file_map=None)

Template class for volumetric (3D/4D) images

Attributes

affine
dataobj
header
in_memory True when any array data is in memory cache
shape
slicer Slicer object that returns cropped and subsampled images

Methods

ImageSlicer alias of SpatialFirstSlicer
as_reoriented(ornt) Apply an orientation change and return a new image
filespec_to_file_map(klass, filespec) Make file_map for this class from filename filespec
filespec_to_files(\*args, \*\*kwargs) filespec_to_files class method is deprecated.
from_file_map(klass, file_map)
from_filename(klass, filename)
from_files(\*args, \*\*kwargs) from_files class method is deprecated.
from_image(klass, img) Class method to create new instance of own class from img
get_affine(\*args, \*\*kwargs) Get affine from image
get_data([caching]) Return image data from image with any necessary scaling applied
get_data_dtype()
get_fdata([caching, dtype]) Return floating point image data with necessary scaling applied
get_filename() Fetch the image filename
get_header(\*args, \*\*kwargs) Get header from image
get_shape(\*args, \*\*kwargs) Return shape for image
header_class alias of SpatialHeader
instance_to_filename(klass, img, filename) Save img in our own format, to name implied by filename
load(klass, filename)
make_file_map(klass[, mapping]) Class method to make files holder for this image type
orthoview() Plot the image using OrthoSlicer3D
path_maybe_image(klass, filename[, sniff, ...]) Return True if filename may be image matching this class
set_data_dtype(dtype)
set_filename(filename) Sets the files in the object from a given filename
to_file_map([file_map])
to_filename(filename) Write image to files implied by filename string
to_files(\*args, \*\*kwargs) to_files method is deprecated.
to_filespec(\*args, \*\*kwargs) to_filespec method is deprecated.
uncache() Delete any cached read of data from proxied data
update_header() Harmonize header with image data and affine

Initialize image

The image is a combination of (array-like, affine matrix, header), with optional metadata in extra, and filename / file-like objects contained in the file_map mapping.

Parameters:

dataobj : object

Object containg image data. It should be some object that retuns an array from np.asanyarray. It should have a shape attribute or property

affine : None or (4,4) array-like

homogenous affine giving relationship between voxel coordinates and world coordinates. Affine can also be None. In this case, obj.affine also returns None, and the affine as written to disk will depend on the file format.

header : None or mapping or header instance, optional

metadata for this image format

extra : None or mapping, optional

metadata to associate with image that cannot be stored in the metadata of this image type

file_map : mapping, optional

mapping giving file information for this image format

Attributes

affine
dataobj
header
in_memory True when any array data is in memory cache
shape
slicer Slicer object that returns cropped and subsampled images

Methods

ImageSlicer alias of SpatialFirstSlicer
as_reoriented(ornt) Apply an orientation change and return a new image
filespec_to_file_map(klass, filespec) Make file_map for this class from filename filespec
filespec_to_files(\*args, \*\*kwargs) filespec_to_files class method is deprecated.
from_file_map(klass, file_map)
from_filename(klass, filename)
from_files(\*args, \*\*kwargs) from_files class method is deprecated.
from_image(klass, img) Class method to create new instance of own class from img
get_affine(\*args, \*\*kwargs) Get affine from image
get_data([caching]) Return image data from image with any necessary scaling applied
get_data_dtype()
get_fdata([caching, dtype]) Return floating point image data with necessary scaling applied
get_filename() Fetch the image filename
get_header(\*args, \*\*kwargs) Get header from image
get_shape(\*args, \*\*kwargs) Return shape for image
header_class alias of SpatialHeader
instance_to_filename(klass, img, filename) Save img in our own format, to name implied by filename
load(klass, filename)
make_file_map(klass[, mapping]) Class method to make files holder for this image type
orthoview() Plot the image using OrthoSlicer3D
path_maybe_image(klass, filename[, sniff, ...]) Return True if filename may be image matching this class
set_data_dtype(dtype)
set_filename(filename) Sets the files in the object from a given filename
to_file_map([file_map])
to_filename(filename) Write image to files implied by filename string
to_files(\*args, \*\*kwargs) to_files method is deprecated.
to_filespec(\*args, \*\*kwargs) to_filespec method is deprecated.
uncache() Delete any cached read of data from proxied data
update_header() Harmonize header with image data and affine
ImageSlicer

alias of SpatialFirstSlicer

affine
as_reoriented(ornt)

Apply an orientation change and return a new image

If ornt is identity transform, return the original image, unchanged

Parameters:

ornt : (n,2) orientation array

orientation transform. ornt[N,1]` is flip of axis N of the array implied by `shape`, where 1 means no flip and -1 means flip.  For example, if ``N==0 and ornt[0,1] == -1, and there’s an array arr of shape shape, the flip would correspond to the effect of np.flipud(arr). ornt[:,0] is the transpose that needs to be done to the implied array, as in arr.transpose(ornt[:,0])

Notes

Subclasses should override this if they have additional requirements when re-orienting an image.

classmethod from_image(klass, img)

Class method to create new instance of own class from img

Parameters:

img : spatialimage instance

In fact, an object with the API of spatialimage - specifically dataobj, affine, header and extra.

Returns:

cimg : spatialimage instance

Image, of our own class

get_affine(*args, **kwargs)

Get affine from image

get_affine method is deprecated. Please use the img.affine property instead.

  • deprecated from version: 2.1
  • Will raise <class ‘nibabel.deprecator.ExpiredDeprecationError’> as of version: 4.0
get_data_dtype()
header_class

alias of SpatialHeader

orthoview()

Plot the image using OrthoSlicer3D

Returns:

viewer : instance of OrthoSlicer3D

The viewer.

Notes

This requires matplotlib. If a non-interactive backend is used, consider using viewer.show() (equivalently plt.show()) to show the figure.

set_data_dtype(dtype)
slicer

Slicer object that returns cropped and subsampled images

The image is resliced in the current orientation; no rotation or resampling is performed, and no attempt is made to filter the image to avoid aliasing.

The affine matrix is updated with the new intercept (and scales, if down-sampling is used), so that all values are found at the same RAS locations.

Slicing may include non-spatial dimensions. However, this method does not currently adjust the repetition time in the image header.

update_header()

Harmonize header with image data and affine

>>> data = np.zeros((2,3,4))
>>> affine = np.diag([1.0,2.0,3.0,1.0])
>>> img = SpatialImage(data, affine)
>>> img.shape == (2, 3, 4)
True
>>> img.update_header()
>>> img.header.get_data_shape() == (2, 3, 4)
True
>>> img.header.get_zooms()
(1.0, 2.0, 3.0)