Accessing images using nipy:
While Nifti is the primary file format Analyze images (with associated .mat file), and MINC files can also be read.
from nipy.io.api import load_image
infile = 'myimage.nii'
myimg = load_image(infile)
myimg.shape
myimg.affine
This allows user to access data in a numpy array.
Note
This is the correct way to access the data as it applies the proper intensity scaling to the image as defined in the header
from nipy.io.api import load_image
import numpy as np
myimg = load_file('myfile')
mydata = np.asarray(myimg)
mydata.shape
from nipy.io.api import load_image,save_image
import numpy as np
myimg = load_file('myfile.nii')
newimg = save_image(myimg,'newmyfile.nii')
This will have a generic CoordinateMap with Unit step sizes
from nipy.core.api import fromarray
from nipy.io.api import save_image
import numpy as np
rawarray = np.zeros(43,128,128)
innames='ijk'
outnames='xyz'
newimg = fromarray(rawarray, innames, outnames)
Images have a Coordinate Map.
The Coordinate Map contains information defining the input and output Coordinate Systems of the image, and the mapping between the two Coordinate systems.