神经图像NIBABEL官网:
https://nipy.org/nibabel/gettingstarted.html
读取
import nibabel as nib
img = nib.load('image_path+filename).get_fdata()
存储
img.tofile('save_path+filename')
头文件
ds = nib.load(image_path)
header = ds.header
print(header)
Information of machine and patient
dcmext = ds.header.extensions
print(dcmext)
把header读出来
>>> n2_header = n2_img.header
>>> print(n2_header)
<class 'nibabel.nifti2.Nifti2Header'> object, endian='<'
sizeof_hdr : 540
magic : b'n+2'
eol_check : [13 10 26 10]
datatype : int16
bitpix : 16
dim : [ 4 32 20 12 2 1 1 1]
intent_p1 : 0.0
intent_p2 : 0.0
intent_p3 : 0.0
pixdim : [ -1. 2. 2. 2.2 2000. 1. 1. 1. ]
vox_offset : 0
scl_slope : nan
scl_inter : nan
cal_max : 1162.0
cal_min : 0.0
slice_duration : 0.0
toffset : 0.0
slice_start : 0
slice_end : 23
descrip : b'FSL3.3\x00 v2.25 NIfTI-1 Single file format'
aux_file : b''
qform_code : scanner
sform_code : scanner
quatern_b : -1.94510681403e-26
quatern_c : -0.996708512306
quatern_d : -0.081068739295
qoffset_x : 117.855102539
qoffset_y : -35.7229423523
qoffset_z : -7.24879837036
srow_x : [ -2. 0. 0. 117.86]
srow_y : [ -0. 1.97 -0.36 -35.72]
srow_z : [ 0. 0.32 2.17 -7.25]
slice_code : unknown
xyzt_units : 10
intent_code : none
intent_name : b''
dim_info : 57
unused_str : b''
>>> n1_header['cal_max']
array(1162., dtype=float32)
>>> n1_header['cal_max'] = 1200
>>> n1_header['cal_max']
array(1200., dtype=float32)
更多数学原理小文请关注公众号:未名方略