@@ -151,10 +151,10 @@ You can get and set individual fields in the header using dict (mapping-type)
151151item access. For example:
152152
153153>>> n1_header[' cal_max' ]
154- array(1162.0 , dtype=float32)
154+ array(1162., dtype=float32)
155155>>> n1_header[' cal_max' ] = 1200
156156>>> n1_header[' cal_max' ]
157- array(1200.0 , dtype=float32)
157+ array(1200., dtype=float32)
158158
159159Check the attributes of the header for ``get_ `` / ``set_ `` methods to get and
160160set various combinations of NIfTI header fields.
@@ -173,10 +173,10 @@ Like other nibabel image types, NIfTI images have an affine relating the voxel
173173coordinates to world coordinates in RAS+ space:
174174
175175>>> n1_img.affine
176- array([[ -2. , 0. , 0. , 117.86],
177- [ -0. , 1.97, -0.36, -35.72],
178- [ 0. , 0.32, 2.17, -7.25],
179- [ 0. , 0. , 0. , 1. ]])
176+ array([[ -2. , 0. , 0. , 117.86],
177+ [ -0. , 1.97, -0.36, -35.72],
178+ [ 0. , 0.32, 2.17, -7.25],
179+ [ 0. , 0. , 0. , 1. ]])
180180
181181Unlike other formats, the NIfTI header format can specify this affine in one
182182of three ways |-- | the *sform * affine, the *qform * affine and the *fall-back
@@ -199,16 +199,16 @@ the image or the header.
199199For example:
200200
201201>>> print (n1_header[' srow_x' ])
202- [ -2. 0. 0. 117.86]
202+ [ -2. 0. 0. 117.86]
203203>>> print (n1_header[' srow_y' ])
204204[ -0. 1.97 -0.36 -35.72]
205205>>> print (n1_header[' srow_z' ])
206206[ 0. 0.32 2.17 -7.25]
207207>>> print (n1_header.get_sform())
208- [[ -2. 0. 0. 117.86]
209- [ -0. 1.97 -0.36 -35.72]
210- [ 0. 0.32 2.17 -7.25]
211- [ 0. 0. 0. 1. ]]
208+ [[ -2. 0. 0. 117.86]
209+ [ -0. 1.97 -0.36 -35.72]
210+ [ 0. 0.32 2.17 -7.25]
211+ [ 0. 0. 0. 1. ]]
212212
213213This affine is valid only if the ``sform_code `` is not zero.
214214
@@ -234,29 +234,29 @@ You can get the affine and the code using the ``coded=True`` argument to
234234``get_sform() ``:
235235
236236>>> print (n1_header.get_sform(coded = True ))
237- (array([[ -2. , 0. , 0. , 117.86],
238- [ -0. , 1.97, -0.36, -35.72],
239- [ 0. , 0.32, 2.17, -7.25],
240- [ 0. , 0. , 0. , 1. ]]), 1)
237+ (array([[ -2. , 0. , 0. , 117.86],
238+ [ -0. , 1.97, -0.36, -35.72],
239+ [ 0. , 0.32, 2.17, -7.25],
240+ [ 0. , 0. , 0. , 1. ]]), 1)
241241
242242You can set the sform with the ``set_sform() `` method of the header and
243243the image.
244244
245245>>> n1_header.set_sform(np.diag([2 , 3 , 4 , 1 ]))
246246>>> n1_header.get_sform()
247- array([[ 2., 0., 0., 0.],
248- [ 0., 3., 0., 0.],
249- [ 0., 0., 4., 0.],
250- [ 0., 0., 0., 1.]])
247+ array([[2., 0., 0., 0.],
248+ [0., 3., 0., 0.],
249+ [0., 0., 4., 0.],
250+ [0., 0., 0., 1.]])
251251
252252Set the affine and code using the ``code `` parameter to ``set_sform() ``:
253253
254254>>> n1_header.set_sform(np.diag([3 , 4 , 5 , 1 ]), code = ' mni' )
255255>>> n1_header.get_sform(coded = True )
256- (array([[ 3., 0., 0., 0.],
257- [ 0., 4., 0., 0.],
258- [ 0., 0., 5., 0.],
259- [ 0., 0., 0., 1.]]), 4)
256+ (array([[3., 0., 0., 0.],
257+ [0., 4., 0., 0.],
258+ [0., 0., 5., 0.],
259+ [0., 0., 0., 1.]]), 4)
260260
261261The qform affine
262262================
@@ -273,10 +273,10 @@ You can get and set the qform affine using the equivalent methods to those for
273273the sform: ``get_qform() ``, ``set_qform() ``.
274274
275275>>> n1_header.get_qform(coded = True )
276- (array([[ -2. , 0. , 0. , 117.86],
277- [ -0. , 1.97, -0.36, -35.72],
278- [ 0. , 0.32, 2.17, -7.25],
279- [ 0. , 0. , 0. , 1. ]]), 1)
276+ (array([[ -2. , 0. , 0. , 117.86],
277+ [ -0. , 1.97, -0.36, -35.72],
278+ [ 0. , 0.32, 2.17, -7.25],
279+ [ 0. , 0. , 0. , 1. ]]), 1)
280280
281281The qform also has a corresponding ``qform_code `` with the same interpretation
282282as the `sform_code `.
@@ -295,10 +295,10 @@ Again like SPM, we prefer to assume LAS+ voxel orientation by default.
295295You can always get the fall-back affine with ``get_base_affine() ``:
296296
297297>>> n1_header.get_base_affine()
298- array([[ -2. , 0. , 0. , 127. ],
299- [ 0. , 2. , 0. , -95. ],
300- [ 0. , 0. , 2.2, -25.3],
301- [ 0. , 0. , 0. , 1. ]])
298+ array([[ -2. , 0. , 0. , 127. ],
299+ [ 0. , 2. , 0. , -95. ],
300+ [ 0. , 0. , 2.2, -25.3],
301+ [ 0. , 0. , 0. , 1. ]])
302302
303303.. _choosing-image-affine :
304304
@@ -329,10 +329,10 @@ The sform and qform codes will be initialised to 2 (aligned) and 0 (unknown)
329329respectively:
330330
331331>>> img.get_sform(coded = True ) # doctest: +NORMALIZE_WHITESPACE
332- (array([[ 2., 0., 0., 0.],
333- [ 0., 2., 0., 0.],
334- [ 0., 0., 2., 0.],
335- [ 0., 0., 0., 1.]]), 2)
332+ (array([[2., 0., 0., 0.],
333+ [ 0., 2., 0., 0.],
334+ [ 0., 0., 2., 0.],
335+ [ 0., 0., 0., 1.]]), 2)
336336>>> img.get_qform(coded = True )
337337(None, 0)
338338
@@ -434,21 +434,21 @@ image is written. We can do this by setting the fields directly, or with
434434>>> array_header.get_slope_inter()
435435(2.0, 10.0)
436436>>> array_header[' scl_slope' ]
437- array(2.0 , dtype=float32)
437+ array(2., dtype=float32)
438438>>> array_header[' scl_inter' ]
439- array(10.0 , dtype=float32)
439+ array(10., dtype=float32)
440440
441441Setting the scale factors in the header has no effect on the image data before
442442we save and load again:
443443
444- >>> array_img.get_data ()
445- array([[[ 0, 1, 2, 3],
446- [ 4, 5, 6, 7],
447- [ 8, 9, 10, 11]],
444+ >>> array_img.get_fdata ()
445+ array([[[ 0. , 1. , 2. , 3. ],
446+ [ 4. , 5. , 6. , 7. ],
447+ [ 8. , 9. , 10. , 11. ]],
448448<BLANKLINE>
449- [[12, 13, 14, 15],
450- [16, 17, 18, 19],
451- [20, 21, 22, 23]]], dtype=int16 )
449+ [[12. , 13. , 14. , 15. ],
450+ [16. , 17. , 18. , 19. ],
451+ [20. , 21. , 22. , 23. ]]])
452452
453453Now we save the image and load it again:
454454
@@ -457,14 +457,14 @@ Now we save the image and load it again:
457457
458458The data array has the scaling applied:
459459
460- >>> scaled_img.get_data ()
461- ... ([[[ 10., 12., 14., 16.],
462- [ 18., 20., 22., 24.],
463- [ 26., 28., 30., 32.]],
460+ >>> scaled_img.get_fdata ()
461+ array ([[[10., 12., 14., 16.],
462+ [18., 20., 22., 24.],
463+ [26., 28., 30., 32.]],
464464<BLANKLINE>
465- [[ 34., 36., 38., 40.],
466- [ 42., 44., 46., 48.],
467- [ 50., 52., 54., 56.]]])
465+ [[34., 36., 38., 40.],
466+ [42., 44., 46., 48.],
467+ [50., 52., 54., 56.]]])
468468
469469The header for the loaded image has had the scaling reset to undefined, to
470470mark the fact that the scaling has been "consumed" by the load:
0 commit comments