# Padding of 3d images

**URL:** <https://discourse.slicer.org/t/padding-of-3d-images/25431>\
**Category:** Development\
**Created:** [September 26, 2022, 2:36am UTC](https://discourse.slicer.org/t/padding-of-3d-images/25431 "2022-09-26T02:36:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aditya\_Prabhakara\_Ka](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/aditya_prabhakara_ka/32/16695_2.png) [@Aditya\_Prabhakara\_Ka](https://discourse.slicer.org/u/Aditya_Prabhakara_Ka)\
**Post date:** [September 26, 2022, 2:36am UTC](https://discourse.slicer.org/t/padding-of-3d-images/25431/1 "2022-09-26T02:36:43Z")

</div>

Hi,  
I have a question regarding the padding of 3d images (.nrrd). Say my image dimension is [256,197,19] and I want my image to have a size of length and width of 256 and channel 30 making it [256,256,30]. What is the syntax for padding of zeros?

If i were to use np.pad(data,((256,----))then how do I adjust my channel width from 19 to 30?

Thank you so much!!!

---

<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:** [September 26, 2022, 2:46am UTC](https://discourse.slicer.org/t/padding-of-3d-images/25431/2 "2022-09-26T02:46:44Z")

</div>

Medical images are not just specified by a 3D array of voxels but also by the origin, spacing, and axis directions of the image. Therefore, _padding_ is generally not sufficient to bring images into the same space. Instead, images are _resampled_ to have matching array size, origin, spacing, and axis directions.

This is a built-in feature in many modules (e.g., when you export a segmentation then you can specify a reference volume that specifies the desired geometry) and there are also several modules developed specifically for just resampling (see for example how one is used in this [example](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#apply-random-deformations-to-image)). If you describe what you would like to achieve, then we can give more specific advice.
