# Sitk C# Scale Image Up

**URL:** <https://discourse.itk.org/t/sitk-c-scale-image-up/6561>\
**Category:** Beginner Questions\
**Tags:** simpleitk\
**Created:** [April 11, 2024, 3:45pm UTC](https://discourse.itk.org/t/sitk-c-scale-image-up/6561 "2024-04-11T15:45:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![G\_Y](https://discourse.itk.org/user_avatar/discourse.itk.org/g_y/32/3996_2.png) [@G\_Y](https://discourse.itk.org/u/G_Y)\
**Post date:** [April 11, 2024, 3:45pm UTC](https://discourse.itk.org/t/sitk-c-scale-image-up/6561/1 "2024-04-11T15:45:17Z")

</div>

Hi all, I want to scale up an image twice as big using Sitk C#:

```auto
var img = Sitk.ReadImage(file);
var scale = new ScaleTransform(2, new VectorDouble(2) { 0.5, 0.5 });
var imageScaled = Sitk.Resample(img, scale, InterpolatorEnum.sitkBSpline, 0.0 );
Sitk.WriteImage(imageScaled, dirOut + "resampled.png");

```

The imageScaled has the same width & height and spacing as the input image, it shows quarter of the original content, twice as big. How can I resize the whole image, so the result has width \* 2, height \* 2, and still show the full content? Seems a very simple problem but I just couldn’t get it work…

Thanks for help!

---

<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:** [April 11, 2024, 4:42pm UTC](https://discourse.itk.org/t/sitk-c-scale-image-up/6561/2 "2024-04-11T16:42:11Z")

</div>

The simplest way would be to use the [ExandImageFilter](https://simpleitk.org/doxygen/latest/html/classitk_1_1simple_1_1ExpandImageFilter.html), which increases the resolution by a fixed integer.

Alternatively please review the model ITK uses to represent the Image and its geometry:  
[https://simpleitk.readthedocs.io/en/master/fundamentalConcepts.html#images](https://simpleitk.readthedocs.io/en/master/fundamentalConcepts.html#images)

Commonly it is desirable to maintain the physical location of the image data while “scaling” up the image. This could be done by using the input image (img) as a reference image for the ResampleImageFilter, and then change the spacing and origin to match the desired resampling resolution and location.

---

<div class="post-metadata">

**Author:** ![G\_Y](https://discourse.itk.org/user_avatar/discourse.itk.org/g_y/32/3996_2.png) [@G\_Y](https://discourse.itk.org/u/G_Y)\
**Post date:** [April 12, 2024, 2:16pm UTC](https://discourse.itk.org/t/sitk-c-scale-image-up/6561/3 "2024-04-12T14:16:41Z")

</div>

Thanks! So does that mean Resample() etc. are designed to keep the physical location and change the spacing, other than those common paint or photo editing software just change the number of pixels?

---

<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:** [April 12, 2024, 2:20pm UTC](https://discourse.itk.org/t/sitk-c-scale-image-up/6561/4 "2024-04-12T14:20:23Z")

</div>

Yes, the Resample filter ( as with most of ITK ) is designed to operate in physical space and not just pixel space the way photo editing software is.

---

<div class="post-metadata">

**Author:** ![G\_Y](https://discourse.itk.org/user_avatar/discourse.itk.org/g_y/32/3996_2.png) [@G\_Y](https://discourse.itk.org/u/G_Y)\
**Post date:** [April 12, 2024, 2:22pm UTC](https://discourse.itk.org/t/sitk-c-scale-image-up/6561/5 "2024-04-12T14:22:30Z")

</div>

Thank you Blowekamp!

Just for the completeness of this post, so the simplest way to do it in C#:  
`var imgExpand = Sitk.Expand(img, new VectorUInt32(new uint[] { 2, 2 }), InterpolatorEnum.sitkLinear);`
