|
| 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