Squeeze dicom from 4D to 3D in C#

Is there a way to reshape a 4D sitk image to 3D e.g. [256, 256, 256, 1] to [256, 256, 256] in C#?
In python it is done with slicing:
image = image[:,:,:,0]
How is this done in C#?

Hello,

The Python slicing syntactic sugar is implemented using a combination of the SliceImageFilter and the ExtractImageFilter.

For the particular operation of reducing the dimension and removing the 4th dimension the following pseudo code should work:

sizex, sizey, sizez, sizec = 4d_img.GetSize() 
filter = sitk.ExtractImageFilter()
filter.SetSize([ sizex, sizey, sizez, 0])
3d_img = filter.Execute(4d_img)

A more advance way of doing the above is through the reader’s SetExtractSize method. Some details of the process involve are in the following example:

https://simpleitk.readthedocs.io/en/master/link_AdvancedImageReading_docs.html

2 Likes