# Create image patches and reconstruct it back to the image

**URL:** https://discourse.itk.org/t/create-image-patches-and-reconstruct-it-back-to-the-image/3274
**Category:** Beginner Questions
**Tags:** python, dicom, simpleitk
**Created:** [July 9, 2020, 12:03pm UTC](https://discourse.itk.org/t/create-image-patches-and-reconstruct-it-back-to-the-image/3274 "2020-07-09T12:03:21Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [July 9, 2020, 1:23pm UTC](https://discourse.itk.org/t/create-image-patches-and-reconstruct-it-back-to-the-image/3274/2 "2020-07-09T13:23:11Z")

</div>

Hello @DL_Begin,

Yes, this is easily done, though not sure exactly about your goal, the exact code/approach depends on that. The most trivial solution below:

```auto
import SimpleITK as sitk
import numpy as np

# Create random image, note that numpy (z,y,x) and ITK/SimpleITK (x,y,z) index order are reveresed 
arr = np.random.random([284,143,143])
original_volume = sitk.GetImageFromArray(arr)

# Resample to the new desired size
new_size = [128, 128, original_volume.GetSize()[-1]]
resampled_volume = sitk.Resample(original_volume,new_size)

#Extract the slices into a list
slice_list = [resampled_volume[:,:,i] for i in range(resampled_volume.GetSize()[-1])]

```

If you want to perform some operation on a slice by slice fashion and then resample the volume to a new size I recommend using the Pythonic [slicing\_decorator](https://discourse.itk.org/t/resampleimagefilter-4d-images/2172/4) solution provided by @blowekamp and then resampling as above.

---

_[View the full topic](https://discourse.itk.org/t/create-image-patches-and-reconstruct-it-back-to-the-image/3274)._
