digraph inheritance8823115a3a { rankdir=LR; ratio=compress; fontsize=14; size="6.0, 8.0"; "SpmAnalyzeHeader" [shape=ellipse,URL="nibabel.spm99analyze.SpmAnalyzeHeader.html#nibabel.spm99analyze.SpmAnalyzeHeader",fontname=Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans,fontsize=14,color=dodgerblue1,style=filled,height=0.75]; "AnalyzeHeader" -> "SpmAnalyzeHeader" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Spm99AnalyzeHeader" [shape=ellipse,URL="#nibabel.spm99analyze.Spm99AnalyzeHeader",fontname=Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans,fontsize=14,color=dodgerblue1,style=filled,height=0.75]; "SpmAnalyzeHeader" -> "Spm99AnalyzeHeader" [arrowsize=0.5,style="setlinewidth(0.5)"]; "AnalyzeHeader" [shape=ellipse,URL="nibabel.analyze.AnalyzeHeader.html#nibabel.analyze.AnalyzeHeader",fontname=Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans,fontsize=14,color=dodgerblue1,style=filled,height=0.75]; }
Adds origin functionality to base SPM header
Methods
as_analyze_map | |
as_byteswapped | |
check_fix | |
copy | Generic (shallow and deep) copying operations. |
data_from_fileobj | |
data_to_fileobj | |
diagnose_binaryblock | |
from_fileobj | |
from_header | |
get_base_affine | |
get_best_affine | |
get_data_dtype | |
get_data_offset | |
get_data_shape | |
get_origin_affine | |
get_slope_inter | |
get_value_label | |
get_zooms | |
items | |
keys | |
raw_data_from_fileobj | |
scaling_from_data | |
set_data_dtype | |
set_data_shape | |
set_origin_from_affine | |
set_slope_inter | |
set_zooms | |
values | |
write_to |
Initialize header from binary data block
Parameters : | binaryblock : {None, string} optional
endianness : {None, ‘<’,’>’, other endian code} string, optional
check : bool, optional
|
---|
Examples
>>> hdr1 = AnalyzeHeader() # an empty header
>>> hdr1.endianness == native_code
True
>>> hdr1.get_data_shape()
(0,)
>>> hdr1.set_data_shape((1,2,3)) # now with some content
>>> hdr1.get_data_shape()
(1, 2, 3)
We can set the binary block directly via this initialization. Here we get it from the header we have just made
>>> binblock2 = hdr1.binaryblock
>>> hdr2 = AnalyzeHeader(binblock2)
>>> hdr2.get_data_shape()
(1, 2, 3)
Empty headers are native endian by default
>>> hdr2.endianness == native_code
True
You can pass valid opposite endian headers with the endianness parameter. Even empty headers can have endianness
>>> hdr3 = AnalyzeHeader(endianness=swapped_code)
>>> hdr3.endianness == swapped_code
True
If you do not pass an endianness, and you pass some data, we will try to guess from the passed data.
>>> binblock3 = hdr3.binaryblock
>>> hdr4 = AnalyzeHeader(binblock3)
>>> hdr4.endianness == swapped_code
True
Methods
as_analyze_map | |
as_byteswapped | |
check_fix | |
copy | Generic (shallow and deep) copying operations. |
data_from_fileobj | |
data_to_fileobj | |
diagnose_binaryblock | |
from_fileobj | |
from_header | |
get_base_affine | |
get_best_affine | |
get_data_dtype | |
get_data_offset | |
get_data_shape | |
get_origin_affine | |
get_slope_inter | |
get_value_label | |
get_zooms | |
items | |
keys | |
raw_data_from_fileobj | |
scaling_from_data | |
set_data_dtype | |
set_data_shape | |
set_origin_from_affine | |
set_slope_inter | |
set_zooms | |
values | |
write_to |
Get affine from header, using SPM origin field if sensible
The default translations are got from the origin field, if set, or from the center of the image otherwise.
Examples
>>> hdr = Spm99AnalyzeHeader()
>>> hdr.set_data_shape((3, 5, 7))
>>> hdr.set_zooms((3, 2, 1))
>>> hdr.default_x_flip
True
>>> hdr.get_origin_affine() # from center of image
array([[-3., 0., 0., 3.],
[ 0., 2., 0., -4.],
[ 0., 0., 1., -3.],
[ 0., 0., 0., 1.]])
>>> hdr['origin'][:3] = [3,4,5]
>>> hdr.get_origin_affine() # using origin
array([[-3., 0., 0., 6.],
[ 0., 2., 0., -6.],
[ 0., 0., 1., -4.],
[ 0., 0., 0., 1.]])
>>> hdr['origin'] = 0 # unset origin
>>> hdr.set_data_shape((3, 5, 7))
>>> hdr.get_origin_affine() # from center of image
array([[-3., 0., 0., 3.],
[ 0., 2., 0., -4.],
[ 0., 0., 1., -3.],
[ 0., 0., 0., 1.]])
Get affine from header, using SPM origin field if sensible
The default translations are got from the origin field, if set, or from the center of the image otherwise.
Examples
>>> hdr = Spm99AnalyzeHeader()
>>> hdr.set_data_shape((3, 5, 7))
>>> hdr.set_zooms((3, 2, 1))
>>> hdr.default_x_flip
True
>>> hdr.get_origin_affine() # from center of image
array([[-3., 0., 0., 3.],
[ 0., 2., 0., -4.],
[ 0., 0., 1., -3.],
[ 0., 0., 0., 1.]])
>>> hdr['origin'][:3] = [3,4,5]
>>> hdr.get_origin_affine() # using origin
array([[-3., 0., 0., 6.],
[ 0., 2., 0., -6.],
[ 0., 0., 1., -4.],
[ 0., 0., 0., 1.]])
>>> hdr['origin'] = 0 # unset origin
>>> hdr.set_data_shape((3, 5, 7))
>>> hdr.get_origin_affine() # from center of image
array([[-3., 0., 0., 3.],
[ 0., 2., 0., -4.],
[ 0., 0., 1., -3.],
[ 0., 0., 0., 1.]])
Set SPM origin to header from affine matrix.
The origin field was read but not written by SPM99 and 2. It was used for storing a central voxel coordinate, that could be used in aligning the image to some standard position - a proxy for a full translation vector that was usually stored in a separate matlab .mat file.
Nifti uses the space occupied by the SPM origin field for important other information (the transform codes), so writing the origin will make the header a confusing Nifti file. If you work with both Analyze and Nifti, you should probably avoid doing this.
Parameters : | affine : array-like, shape (4,4)
|
---|---|
Returns : | None : |
Examples
>>> hdr = Spm99AnalyzeHeader()
>>> hdr.set_data_shape((3, 5, 7))
>>> hdr.set_zooms((3,2,1))
>>> hdr.get_origin_affine()
array([[-3., 0., 0., 3.],
[ 0., 2., 0., -4.],
[ 0., 0., 1., -3.],
[ 0., 0., 0., 1.]])
>>> affine = np.diag([3,2,1,1])
>>> affine[:3,3] = [-6, -6, -4]
>>> hdr.set_origin_from_affine(affine)
>>> np.all(hdr['origin'][:3] == [3,4,5])
True
>>> hdr.get_origin_affine()
array([[-3., 0., 0., 6.],
[ 0., 2., 0., -6.],
[ 0., 0., 1., -4.],
[ 0., 0., 0., 1.]])