# Loosing 4th dimension after segmentation 

**URL:** <https://discourse.slicer.org/t/loosing-4th-dimension-after-segmentation/29881>\
**Category:** Support\
**Tags:** segmentation, nifti, 4d\
**Created:** [June 6, 2023, 11:06pm UTC](https://discourse.slicer.org/t/loosing-4th-dimension-after-segmentation/29881 "2023-06-06T23:06:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chopraamhk](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chopraamhk/32/66309_2.png) [@chopraamhk](https://discourse.slicer.org/u/chopraamhk)\
**Post date:** [June 6, 2023, 11:06pm UTC](https://discourse.slicer.org/t/loosing-4th-dimension-after-segmentation/29881/1 "2023-06-06T23:06:59Z")

</div>

Hi,

My original nifti file is having 4dimensions , i.e., ( 196, 240, 100, 1). I have done segmentation in 3d slicer using 2 labels, and after saving the segmented file, it is giving me output as 3d. My new dimensions are (196, 240, 100) but my time dimension has vanished. I have used reference volume option as while before exporting but it didnt give me my output. I would request you to help.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 6, 2023, 11:15pm UTC](https://discourse.slicer.org/t/loosing-4th-dimension-after-segmentation/29881/2 "2023-06-06T23:15:03Z")

</div>

NIFTI file format is causing lot of trouble, as its specification contains lots of unnecesary complexity (redundancies and ambiguities). Therefore we are not keen on spending time with it, which means nobody ventured to implement support for 4D NIFTI files (except for displacement fields). Therefore, if you export a segmentation into NIFTI format from Slicer, the output will always be a 3D file.

One possible solution is to write the segmentation to NRRD file format and then read it and then write in NIFTI format. You can implement this in a few lines in Python using pynrrd and nibabel packages.

If your input NIFTI file has size of (196, 240, 100, 1) then it means that it is actually a 3D image. Why is it important to save as a 4D image if the 4th dimension is singular?

---

<div class="post-metadata">

**Author:** ![chopraamhk](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chopraamhk/32/66309_2.png) [@chopraamhk](https://discourse.slicer.org/u/chopraamhk)\
**Post date:** [June 8, 2023, 12:17pm UTC](https://discourse.slicer.org/t/loosing-4th-dimension-after-segmentation/29881/3 "2023-06-08T12:17:45Z")

</div>

Thank you for your reply. I have converted my dicom images initially to nifti using dcm2niix. Later, I am doing segmentation and doing it manually using 3d slicer. I need time information because I am using a python code which checks the quality of Nifti files with respect to time and, later, calculates the area. Either i am not doing segmentation properly or I need to follow some other approach to convert 1. dicom to nifti and, later, 2. nifti to segmented nifti.

For now, i will convert my dicom to nrrd file (as you suggested) and later, will convert it to nifti and try it in different cases. I will check if it gives me time information as well. (My dicom images does have time information)

---

<div class="post-metadata">

**Author:** ![chopraamhk](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chopraamhk/32/66309_2.png) [@chopraamhk](https://discourse.slicer.org/u/chopraamhk)\
**Post date:** [June 12, 2023, 2:10pm UTC](https://discourse.slicer.org/t/loosing-4th-dimension-after-segmentation/29881/4 "2023-06-12T14:10:42Z")

</div>

my converted 100 dicom images to nifti has header -

sizeof\_hdr : 348  
data\_type : b’’  
db\_name : b’’  
extents : 0  
session\_error : 0  
regular : b’r’  
dim\_info : 57  
dim : [4 240 196 1 100 1 1 1]  
intent\_p1 : 0.0  
intent\_p2 : 0.0  
intent\_p3 : 0.0  
intent\_code : none  
datatype : int16  
bitpix : 16  
slice\_start : 0  
pixdim : [-1. 1.5833334 1.5833334 6. 0.028 0.  
0. 0. ]  
vox\_offset : 0.0  
scl\_slope : nan  
scl\_inter : nan  
slice\_end : 0  
slice\_code : unknown  
xyzt\_units : 10  
cal\_max : 0.0  
cal\_min : 0.0  
slice\_duration : 0.0  
toffset : 0.0  
glmax : 0  
glmin : 0  
descrip : b’TE=1.2;Time=103829.298;phase=1’  
aux\_file : b’RR 872 +/- 61; 9 heartb’  
qform\_code : scanner  
sform\_code : scanner  
quatern\_b : 0.0  
quatern\_c : 1.0  
quatern\_d : 0.0  
qoffset\_x : 191.80186  
qoffset\_y : -134.34802  
qoffset\_z : 43.5763  
srow\_x : [-1.5833334 0. -0. 191.80186]  
srow\_y : [-0. 1.5833334 -0. -134.34802]  
srow\_z : [0. 0. 6. 43.5763]  
intent\_name : b’’  
magic : b’n+1’

whereas my segmentation file doesn’t have time stamp  
sizeof\_hdr : 348  
data\_type : b’’  
db\_name : b’’  
extents : 0  
session\_error : 0  
regular : b’r’  
dim\_info : 0  
dim : [4 240 196 1 100 1 1 1]  
intent\_p1 : 0.0  
intent\_p2 : 0.0  
intent\_p3 : 0.0  
intent\_code : none  
datatype : uint16  
bitpix : 16  
slice\_start : 0  
pixdim : [-1. 1.5833334 1.5833334 6. 0.028 0.  
0. 0. ]  
vox\_offset : 0.0  
scl\_slope : nan  
scl\_inter : nan  
slice\_end : 0  
slice\_code : unknown  
xyzt\_units : 2  
cal\_max : 0.0  
cal\_min : 0.0  
slice\_duration : 0.0  
toffset : 0.0  
glmax : 0  
glmin : 0  
descrip : b’’  
aux\_file : b’’  
qform\_code : scanner  
sform\_code : scanner  
quatern\_b : -0.0  
quatern\_c : 1.0  
quatern\_d : 0.0  
qoffset\_x : 191.80186  
qoffset\_y : -134.34802  
qoffset\_z : 43.5763  
srow\_x : [-1.5833334 -0. 0. 191.80186]  
srow\_y : [-0. 1.5833334 -0. -134.34802]  
srow\_z : [0. 0. 6. 43.5763]  
intent\_name : b’’  
magic : b’n+1’

Could you please suggest me how can i get the time stamp and i believe i am loosing some other informattion here as well…

---

<div class="post-metadata">

**Author:** ![chopraamhk](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chopraamhk/32/66309_2.png) [@chopraamhk](https://discourse.slicer.org/u/chopraamhk)\
**Post date:** [June 12, 2023, 2:13pm UTC](https://discourse.slicer.org/t/loosing-4th-dimension-after-segmentation/29881/5 "2023-06-12T14:13:58Z")

</div>

and by converting dicom to nrrd :

OrderedDict([(‘type’, ‘unsigned short’), (‘dimension’, 3), (‘space’, ‘left-posterior-superior’), (‘sizes’, array([240, 196, 100])), (‘space directions’, array([[1.58333337, 0. , 0.],  
[0. , 1.58333337, 0.],  
[0. , 0. , 1.]])), (‘kinds’, [‘domain’, ‘domain’, ‘domain’]), (‘endian’, ‘little’), (‘encoding’, ‘gzip’), (‘space origin’, array([-191.80186367, -174.40197062, 43.57630157]))])

i am not getting the required information.
