# Temporal Dimension Semantics in 2D + Time Image Series Written Out As 3D Image

**URL:** <https://discourse.itk.org/t/temporal-dimension-semantics-in-2d-time-image-series-written-out-as-3d-image/6708>\
**Category:** Beginner Questions\
**Created:** [June 19, 2024, 2:29am UTC](https://discourse.itk.org/t/temporal-dimension-semantics-in-2d-time-image-series-written-out-as-3d-image/6708 "2024-06-19T02:29:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![constantine](https://discourse.itk.org/user_avatar/discourse.itk.org/constantine/32/3915_2.png) [@constantine](https://discourse.itk.org/u/constantine)\
**Post date:** [June 19, 2024, 2:29am UTC](https://discourse.itk.org/t/temporal-dimension-semantics-in-2d-time-image-series-written-out-as-3d-image/6708/1 "2024-06-19T02:29:23Z")

</div>

Hello Everyone,

Given a bunch of 2D frames in a temporal series, what is the intended way in ITK to write those out to be recognised as 2D + t image, not just as 3D image?

I’m asking because ITK-Snap or Slicer display 3D DICOM images (written out this way, naturally, 🤷‍♂️) as single time-step image. This is from converting VFSS .avi to DICOM for analysis, which is not ideal.

What is the most straightforward intended way and, specifically, _format_ to preserve temporal series semantics (preferably without having to fiddle with DICOM tags)?

---

<div class="post-metadata">

**Author:** ![lassoan](https://discourse.itk.org/user_avatar/discourse.itk.org/lassoan/32/27_2.png) [@lassoan](https://discourse.itk.org/u/lassoan)\
**Post date:** [June 19, 2024, 5:40am UTC](https://discourse.itk.org/t/temporal-dimension-semantics-in-2d-time-image-series-written-out-as-3d-image/6708/2 "2024-06-19T05:40:41Z")

</div>

If you use NRRD file format then you can specify the [kind](https://teem.sourceforge.net/nrrd/format.html#kinds) of each axis. For example:

- `kinds: domain domain domain`: 3D image
- `kinds: time domain domain`: 2D+t image

In 3D Slicer, we recognize many 2D time sequence image acquisitions, such as fluoroscopy, ultrasound, cine-MRI. Therefore, VFSS is loaded as a time sequence (when it is loaded properly with the DICOM module). If you experience a different behavior in the latest Slicer version then let me know.

---

<div class="post-metadata">

**Author:** ![constantine](https://discourse.itk.org/user_avatar/discourse.itk.org/constantine/32/3915_2.png) [@constantine](https://discourse.itk.org/u/constantine)\
**Post date:** [June 20, 2024, 10:55pm UTC](https://discourse.itk.org/t/temporal-dimension-semantics-in-2d-time-image-series-written-out-as-3d-image/6708/3 "2024-06-20T22:55:06Z")

</div>

Thank you, Andras (@lassoan).

I’ve had a quick look at `itk::NrrdImageIO`, but I’m unclear how/where to specify the `kind` of each axis, when writing NRRD (`.nhdr`). Or, does it have to be passed to `NrrdImageIO` via `itk::MetaDataDictionary`? I can’t find a working example to set those axis `kind`s. 😬

Would you be able to point me to an example, perhaps, in Python?

PS. With our stand-alone GE Fluorostar we can’t get DICOM export to work correctly, and GE support are dragging their feet with addressing the issue with this unit. So, at this stage I’m forced to export AVIs, and then convert those to something suitable for analysis. Not ideal, but kinda have to play along at this stage, 😬

---

<div class="post-metadata">

**Author:** ![constantine](https://discourse.itk.org/user_avatar/discourse.itk.org/constantine/32/3915_2.png) [@constantine](https://discourse.itk.org/u/constantine)\
**Post date:** [June 20, 2024, 11:59pm UTC](https://discourse.itk.org/t/temporal-dimension-semantics-in-2d-time-image-series-written-out-as-3d-image/6708/4 "2024-06-20T23:59:01Z")

</div>

Oh, doing further searching and found this post:

> [@How to write a custom Tag to an image (NRRD or other) header](https://discourse.itk.org/t/how-to-write-a-custom-tag-to-an-image-nrrd-or-other-header/565):
>
> The following question was asked on the [ITK user mailing list](http://itk-users.7.n7.nabble.com/ITK-users-add-tag-to-nrrd-header-td38864.html): I can’t find any possibility to add a field (custom or not) into a nrrd header. The NrrdImageIO doesn’t allow it (or I missed it). Is someone know how to do that? Here is an short example to add a tag to a header (more specifically to add a key/value pair to the metadata dictionary of an image: CMakeLists.txt: cmake\_minimum\_required(VERSION 3.0) project(metadataNRRD) find\_package(ITK REQUIRED) include(${ITK\_USE\_FILE}) add\_e…

I’m doing attempting this sort of thing now, setting `kinds` tags:

```auto
img.GetMetaDataDictionary()['kinds'] = 'time domain domain'

```

But this doesn’t end up in the output .nrrd header metadata. I still end up with:

```auto
kinds: domain domain domain

```

I’ve tried setting the `kinds` tag in MetaDataDictionary dictionaries in all these:

1. the image,
2. the writer filter,
3. the image IO (NrrdImageIO).

And yet, somehow, in the output I don’t see the `time` domain.

Would you suggest what I’m doing wrong here?

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [June 21, 2024, 1:37pm UTC](https://discourse.itk.org/t/temporal-dimension-semantics-in-2d-time-image-series-written-out-as-3d-image/6708/5 "2024-06-21T13:37:09Z")

</div>

You might need this pattern:

```py
meta_data = img.GetMetaDataDictionary()
meta_data['kinds'] = 'time domain domain'
img.SetMetaDataDictionary(meta_data)

```

---

<div class="post-metadata">

**Author:** ![constantine](https://discourse.itk.org/user_avatar/discourse.itk.org/constantine/32/3915_2.png) [@constantine](https://discourse.itk.org/u/constantine)\
**Post date:** [June 24, 2024, 4:19am UTC](https://discourse.itk.org/t/temporal-dimension-semantics-in-2d-time-image-series-written-out-as-3d-image/6708/6 "2024-06-24T04:19:16Z")

</div>

Thank you, Dženan (@dzenanz), for the tip.

I’ve followed, and now the header comes out like this, where kinds appears as a field, and as a key/value pair, which doesn’t look right — something is rotten in the state of Denmark:

```auto
NRRD0004
# Complete NRRD file format specification at:
# http://teem.sourceforge.net/nrrd/format.html
type: unsigned char
dimension: 3
space: left-posterior-superior
sizes: 1024 1280 13
space directions: (1,0,0) (0,1,0) (0,0,1)
kinds: domain domain domain
encoding: raw
space origin: (0,0,0)
kinds:=time domain domain

```

I did a bit of reading/searching and there’s this ([How to write a custom Tag to an image (NRRD or other) header - #6 by jonasteuwen](https://discourse.itk.org/t/how-to-write-a-custom-tag-to-an-image-nrrd-or-other-header/565/6)):

> [@How to write a custom Tag to an image (NRRD or other) header](https://discourse.itk.org/t/how-to-write-a-custom-tag-to-an-image-nrrd-or-other-header/565/6):
>
> Each of the “\< _field_ \>: \< _desc_ \>” lines specifies information about one of the fields in the nrrd. (…)  
> Each of the “\< _key_ \>:=\< _value_ \>” lines specifies a key/value pair in the nrrd. (…)

But then, the NRRD format spec ([Teem: nrrd: Definition of NRRD File Format](https://teem.sourceforge.net/nrrd/format.html)) says `kinds` is a field, not just a key/value pair.

_Any further tips how to get this right?_

It would seem something of this sort (basic image IO) should be closer to the surface, no?

---

<div class="post-metadata">

**Author:** ![constantine](https://discourse.itk.org/user_avatar/discourse.itk.org/constantine/32/3915_2.png) [@constantine](https://discourse.itk.org/u/constantine)\
**Post date:** [June 24, 2024, 5:34am UTC](https://discourse.itk.org/t/temporal-dimension-semantics-in-2d-time-image-series-written-out-as-3d-image/6708/7 "2024-06-24T05:34:38Z")

</div>

@lassoan — Andras, following your invitation to test in latest 3D Slicer and post here.

I’ve downloaded 3D Slicer 5.6.2. When loading NRRD with this header (manually edited for the sake of the exercise, but following the specs)

```auto
NRRD0004
# Complete NRRD file format specification at:
# http://teem.sourceforge.net/nrrd/format.html
type: unsigned char
dimension: 3
space: left-posterior-superior
sizes: 1024 1280 13
space directions: (1,0,0) (0,1,0) none
kinds: domain domain time
encoding: raw
space origin: (0,0,0)

```

it appears the image is still loaded as a 3D volume, judging from the spacing, etc., not time series:

 ![image](https://discourse.itk.org/uploads/default/original/2X/9/9dad55f6815b4f0ddb09a7853a27a5aee104bee1.png)

It is likely I’m misunderstanding something — would you please comment?

---

<div class="post-metadata">

**Author:** ![lassoan](https://discourse.itk.org/user_avatar/discourse.itk.org/lassoan/32/27_2.png) [@lassoan](https://discourse.itk.org/u/lassoan)\
**Post date:** [June 24, 2024, 10:45am UTC](https://discourse.itk.org/t/temporal-dimension-semantics-in-2d-time-image-series-written-out-as-3d-image/6708/8 "2024-06-24T10:45:50Z")

</div>

In 3D Slicer everything is in 3D. If you have a 2D image slice then we want to be able to put it anywhere at any orientation. Therefore, regardless if the image has one or more slices, it must to have 3 dimensional domain and so the header should contain `kinds: domain domain domain time` and all spatial positions and directions should have 3 components.

You can go to Sample Data module, download the cardiac CT time sequence image, save it, and have a look at the header. Or you can create a 4D sequence using [this Python script](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#create-a-4d-volume-in-python-outside-slicer).

---

<div class="post-metadata">

**Author:** ![constantine](https://discourse.itk.org/user_avatar/discourse.itk.org/constantine/32/3915_2.png) [@constantine](https://discourse.itk.org/u/constantine)\
**Post date:** [June 25, 2024, 4:59am UTC](https://discourse.itk.org/t/temporal-dimension-semantics-in-2d-time-image-series-written-out-as-3d-image/6708/9 "2024-06-25T04:59:15Z")

</div>

Thank you, Andras (@lassoan) — I’ll have a play with this.
