# Squeeze dicom from 4D to 3D in C#

**URL:** <https://discourse.itk.org/t/squeeze-dicom-from-4d-to-3d-in-c/5668>\
**Category:** Beginner Questions\
**Tags:** simpleitk\
**Created:** [February 2, 2023, 10:22am UTC](https://discourse.itk.org/t/squeeze-dicom-from-4d-to-3d-in-c/5668 "2023-02-02T10:22:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Endian](https://discourse.itk.org/letter_avatar_proxy/v4/letter/e/8baadc/32.png) [@Endian](https://discourse.itk.org/u/Endian)\
**Post date:** [February 2, 2023, 10:22am UTC](https://discourse.itk.org/t/squeeze-dicom-from-4d-to-3d-in-c/5668/1 "2023-02-02T10:22:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)\
**Post date:** [February 2, 2023, 2:16pm UTC](https://discourse.itk.org/t/squeeze-dicom-from-4d-to-3d-in-c/5668/2 "2023-02-02T14:16:15Z")

</div>

Hello,

The Python slicing syntactic sugar is implemented using a combination of the [SliceImageFilter](https://simpleitk.org/doxygen/latest/html/classitk_1_1simple_1_1SliceImageFilter.html) and the [ExtractImageFilter](https://simpleitk.org/doxygen/latest/html/classitk_1_1simple_1_1ExtractImageFilter.html).

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

```auto
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](https://simpleitk.readthedocs.io/en/master/link_AdvancedImageReading_docs.html)
