Convert 3D image into 4D image with time

I am using ITK and RTK to generate several 3D images (x,y,z) with different time. I want to save them into one .mha file, that’s to say, the desired data format is (x,y,z,t).
I am doing this on Python and I hope ‘itk.JoinSeriesImageFilter[ImageType, VolumeSeriesType]’ can help (not SimpelITK), where ImageType = itk.Image[itk.F, 3]
VolumeSeriesType = itk.Image[itk.F, 4]. However, I am told that JoinSeriesImageFilter wouldn’t accecpt 3D data as Input, I am confused because it seems doesn’t make sense if ImageType can only be 2D image. I am noe sure whether I do something wrong or ITK-Python just ask JoinSeriesImageFilter accepy only 2D image?

Hello @Zhehao_Zhang,

Welcome to the ITK Community :sun_with_face:!

To save time series, it is recommended to covert the images to an xarray DataArray, concatenate over an additional time dimension, t, then save to a format like Zarr with .to_zarr. Use the function itk.xarray_from_image and itk.image_from_xarray available in itk 5.1.

Ok got it.Thank you for your reply and I will try it this way.

1 Like