Skip to content

Commit cc3af8e

Browse files
committed
Add Doc page on NIfTI header
1 parent 336f6bb commit cc3af8e

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

Changelog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ NiBabel
2222
Most work on NiBabel so far has been by Matthew Brett (MB), Michael Hanke (MH)
2323
and Stephan Gerhard (SG).
2424

25+
* 2.0.1
26+
27+
* Read and write support for DICOM tags in NIfTI Extended Header using
28+
pydicom.
29+
2530
* 2.0.0 (Tuesday 9 December 2014)
2631

2732
This release had large contributions from Eric Larson, Brendan Moloney,

doc/source/dicom/dicom.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Contents:
1616
dicom_mosaic
1717
siemens_csa
1818
spm_dicom
19+
dicom_niftiheader
1920

2021
.. these documents not yet ready for public advertisement
2122
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
.. _dicom-niftiheader:
2+
3+
##############################
4+
DICOM Tags in the NIfTI Header
5+
##############################
6+
7+
NIfTI images include an extended header (see the `NIfTI Extensions Standard`_) to store, amongst others, DICOM tags and attributes. When NiBabel loads a NIfTI file containing DICOM information (a NIfTI extension with ``ecode == 2``), it parses it and returns a pydicom dataset as the content of the NIfTI extension. This can be read and written to in order to facilitate communication with software that uses specific DICOM codes found in the NIfTI header.
8+
9+
For example, the commercial PMOD software stores the Frame Start and Duration times of images using the DICOM tags (0055, 1001) and (0055, 1004). Here's an example of an image created in PMOD with those stored times accessed through nibabel.
10+
11+
.. code:: python
12+
13+
>> import nibabel as nib
14+
>> nim = nib.load('pmod_pet.nii')
15+
>> dcmext = nim.header.extensions[0]
16+
>> dcmext
17+
Nifti1Extension('dicom', '(0054, 1001) Units CS: 'Bq/ml'
18+
(0055, 0010) Private Creator LO: 'PMOD_1'
19+
(0055, 1001) [Frame Start Times Vector] FD: [0.0, 30.0, 60.0, ..., 13720.0, 14320.0]
20+
(0055, 1004) [Frame Durations (ms) Vector] FD: [30000.0, 30000.0, 30000.0,600000.0, 600000.0]'))
21+
22+
+-------------+--------------------------------+---------------------------------------------------------+
23+
| Tag | Name | Value |
24+
+=============+================================+=========================================================+
25+
| (0054, 1001)| Units | CS: 'Bq/ml' |
26+
+-------------+--------------------------------+---------------------------------------------------------+
27+
|(0055, 0010) | Private Creator | LO: 'PMOD_1' |
28+
+-------------+--------------------------------+---------------------------------------------------------+
29+
|(0055, 1001) | [Frame Start Times Vector] | FD: [0.0, 30.0, 60.0, ..., 13720.0, 14320.0 |
30+
+-------------+--------------------------------+---------------------------------------------------------+
31+
|(0055, 1004) | [Frame Durations (ms) Vector] | FD: [30000.0, 30000.0, 30000.0, ..., 600000.0, 600000.0 |
32+
+-------------+--------------------------------+---------------------------------------------------------+
33+
34+
Access each value as you would with pydicom::
35+
36+
>> ds = dcmext.get_content()
37+
>> start_times = ds[0x0055, 0x1001].value
38+
>> durations = ds[0x0055, 0x1004].value
39+
40+
Creating a PMOD-compatible header is just as easy::
41+
42+
>> nim = nib.load('pet.nii')
43+
>> nim.header.extensions
44+
[]
45+
>> from dicom.dataset import Dataset
46+
>> ds = Dataset()
47+
>> ds.add_new((0x0054,0x1001),'CS','Bq/ml')
48+
>> ds.add_new((0x0055,0x0010),'LO','PMOD_1')
49+
>> ds.add_new((0x0055,0x1001),'FD',[0.,30.,60.,13720.,14320.])
50+
>> ds.add_new((0x0055,0x1004),'FD',[30000.,30000.,30000.,600000.,600000.])
51+
>> dcmext = nib.nifti1.Nifti1DicomExtension(2,ds) # Use DICOM ecode 2
52+
>> nim.header.extensions.append(dcmext)
53+
>> nib.save(nim,'pet_withdcm.nii')
54+
55+
.. _`NIfTI Extensions Standard`: http://nifti.nimh.nih.gov/nifti-1/documentation/nifti1fields/nifti1fields_pages/extension.html
56+
57+
.. include:: links_names.txt

0 commit comments

Comments
 (0)