# How to change pixel size (Image Spacing) without changing of matrix size

**URL:** <https://discourse.slicer.org/t/how-to-change-pixel-size-image-spacing-without-changing-of-matrix-size/20511>\
**Category:** Support\
**Created:** [November 7, 2021, 12:27pm UTC](https://discourse.slicer.org/t/how-to-change-pixel-size-image-spacing-without-changing-of-matrix-size/20511 "2021-11-07T12:27:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shahrokh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/shahrokh/32/1499_2.png) [@shahrokh](https://discourse.slicer.org/u/shahrokh)\
**Post date:** [November 7, 2021, 12:27pm UTC](https://discourse.slicer.org/t/how-to-change-pixel-size-image-spacing-without-changing-of-matrix-size/20511/1 "2021-11-07T12:27:45Z")

</div>

**Dear Users and Developers**

I want to change _pixel size_ ( **Image Spacing** ) without changing of _matrix size_ ( **Image Dimensions** ).  
I check some modules such as **Resample Scalar Volume** and **Resize Image**. I do not success to do it. At these modules, the _matrix size_ and _pixel size_ are changed simultaneously that I do not mean.

Anyway, I am able to do it very simply by changing the **Image Spacing** values in the module of **Volume**. This is OK.

At now, my questions are mentioned as:  
1- How can I do this through another module (without **Volume** module)?  
2- Is my method correct in doing so (using **Volume** module to change _pixel size_ with changing _matrix size_ using **Volume** module)?

Please guide me.  
Best regards.  
Shahrokh

---

<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:** [November 7, 2021, 5:18pm UTC](https://discourse.slicer.org/t/how-to-change-pixel-size-image-spacing-without-changing-of-matrix-size/20511/2 "2021-11-07T17:18:14Z")

</div>

> [@shahrokh](#):
>
> How can I do this through another module (without **Volume** module)?

You can change spacing value by calling `SetSpacing` method of the volume node.

> [@shahrokh](#):
>
> Is my method correct in doing so (using **Volume** module to change _pixel size_ with changing _matrix size_ using **Volume** module)?

Changing the pixel size would change the physical size of an object so, it is normally not needed. There are only a few exceptions when it is valid to change the pixel size, for example when the volume is loaded from a format where image spacing is not available and you need to change the default 1.0 value to the actual value.

Why are you considering changing the image spacing without resampling the image? What would you like to achieve?

---

<div class="post-metadata">

**Author:** ![shahrokh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/shahrokh/32/1499_2.png) [@shahrokh](https://discourse.slicer.org/u/shahrokh)\
**Post date:** [November 8, 2021, 12:49pm UTC](https://discourse.slicer.org/t/how-to-change-pixel-size-image-spacing-without-changing-of-matrix-size/20511/3 "2021-11-08T12:49:03Z")

</div>

Thanks a lot for your guidance.  
In summary, I want to determine the **patient setup error** in radiotherapy by automatically registering two EPID and DRR images.

I want to first make the DRR and EPID images identical in the aspect of pixel size ( **Image Spacing** ). At first, I must mentioned that these two images are different from these two aspects.

DRR:  
Image Dimensions: 512 512 1  
Image Spacing: 2.1864mm 2.1864mm 1.0000mm

EPID:  
Image Dimensions: 1024 1024 1  
Image Spacing: 0.4mm 0.4mm 1.0mm

The following figure is shown this issue.

 ![1](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/7/6/76f9869318db174cc18d918d9d1add541bfc3049.png)

As you mentioned, I can do it by calling `SetSpacing` method of the volume node. Thanks a lot.  
Result:

 ![2](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/7/272514917a5e6efe9f2e2a2b414546a3cf5f116e.png)

At this moment, I can match the centers of these two images with **Center Volume** in **Volume** module. In practice, the centers of these two images are the place through which the central axis of the radiation field of LINAC passes.

Now, with the guidance you gave me in my topics entitled “ **Crop regions outside the radiation field of the DRR image** ”, I can crop out-of-field areas of the DRR image.

After completing these steps, I want to compare the two images matrices **row** by **row**. I assume these rows as the spatial one-dimensional signals. I think that I can do it with numpy arrays.

After doing it, I want to evaluate the similarity of these two signals (from DRR cropped and EPID) with a tool like xcor. This work must be done for finding similar signals (rows). I interpret that two similar signals correspond to the same anatomical regions.

If this is true, I can determine the amount of spatial shift of the two similar signals. This value of spatial shift can be a patient setup error in the _Right - Left_ direction of the patient.

The same can be done for the columns of EPID and DRR and determine patient setup error in the _Inferior - Superior_ direction of the patient.

I’ll be happy to receive your feedback on these steps.

‌Best regards.  
Shahrokh

---

<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:** [November 8, 2021, 1:17pm UTC](https://discourse.slicer.org/t/how-to-change-pixel-size-image-spacing-without-changing-of-matrix-size/20511/4 "2021-11-08T13:17:49Z")

</div>

You should be able to register these images fully automatically after an approximate initial alignment. All the automatic registration methods in Slicer are set up for 3D (multi-slice) images, so you need to change their parameters to constrain the transformation to 2D (or split the síngle-slice image to 3-5 identical slice.

You may also consider using SimpleITK for this registration, as the basic ITK registration framework could be sufficient for this and there are many 2D Image registration examples online for SimpleITK. If you get stuck you can ask help for this on the [ITK forum](https://discourse.itk.org/).

---

<div class="post-metadata">

**Author:** ![simonoxen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/simonoxen/32/66398_2.png) [@simonoxen](https://discourse.slicer.org/u/simonoxen)\
**Post date:** [November 8, 2021, 3:41pm UTC](https://discourse.slicer.org/t/how-to-change-pixel-size-image-spacing-without-changing-of-matrix-size/20511/5 "2021-11-08T15:41:39Z")

</div>

Hi, not sure if this helps, but you can do 2D registration with SlicerANTs Extension. See the **dimensionality** property under **Settings**
