Inheritance diagram for nipy.io.imageformats.spatialimages:
Very simple spatial image class
The image class maintains the association between a 3D (or greater) array, and an affine transform that maps voxel coordinates to some real world space. It also has a header - some standard set of meta-data that is specific to the image format - and extra - a dictionary container for any other metadata.
It has attributes:
- extra
methods:
- .get_data()
- .get_affine()
- .get_header()
- .get_shape()
- .set_shape(shape)
- .to_filename(fname) - writes data to filename(s) derived from fname, where the derivation may differ between formats.
- to_files() - save image to files with which the image is already associated. Or img.to_files(files) saves to the files passed.
classmethods:
- from_filename(fname) - make instance by loading from filename
- instance_to_filename(img, fname) - save img instance to filename fname.
There is the usual way, which is the default:
img.to_filename(fname)
and that is, to take the data encapsulated by the image and cast it to the datatype the header expects, setting any available header scaling into the header to help the data match.
You can load the data into an image from file with:
img.from_filename(fname)
The image stores its associated files in a rather secretive way. In order to just save an image, for which you know there is an associated filename, or other storage, you can do:
img.to_files()
alternatively, you can pass in the needed files yourself, into this method, as an argument.
You can get the data out again with of:
img.get_data(fileobj)
Less commonly, for some image types that support it, you might want to fetch out the unscaled array via the header:
unscaled_data = img.get_unscaled_data()
Analyze-type images (including nifti) support this, but others may not (MINC, for example).
Sometimes you might to avoid any loss of precision by making the data type the same as the input:
hdr = img.get_header()
hdr.set_data_dtype(data.dtype)
img.to_filename(fname)
Bases: object
Create new instance of own class from img
This is a class method
Parameters : | img : spatialimage instance
|
---|---|
Returns : | cimg : spatialimage instance
|
Save img in our own format, to name implied by filename
This is a class method
Parameters : | img : spatialimage instance
filename : str
|
---|
Write image to files implied by filename string
Returns : | None : |
---|