# Resample a vector image with transform

**URL:** https://discourse.itk.org/t/resample-a-vector-image-with-transform/2438
**Category:** Uncategorized
**Tags:** simpleitk, python
**Created:** [November 25, 2019, 3:15pm UTC](https://discourse.itk.org/t/resample-a-vector-image-with-transform/2438 "2019-11-25T15:15:20Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![kayarre](https://discourse.itk.org/user_avatar/discourse.itk.org/kayarre/32/669_2.png) [@kayarre](https://discourse.itk.org/u/kayarre)
#### Post date: [November 25, 2019, 3:15pm UTC](https://discourse.itk.org/t/resample-a-vector-image-with-transform/2438/1 "2019-11-25T15:15:20Z")

</div>

I understand how to resample a single channel image, but am having trouble figuring out how to to do it with a rgb image.

I am creating and image from a numpy array, reading it in like:

```auto
f_sitk = sitk.GetImageFromArray(np_image, isVector=vector)
f_sitk.SetSpacing(spacing)
f_sitk.SetOrigin(origin)

```

This method does not work with the image using this approach :

```auto
 moving_resampled = sitk.Resample(t_sitk, f_sitk, transform, sitk.sitkLinear, 0.0, t_sitk.GetPixelID())

```

I think this would use something like the following:

```auto
Dimension = 2
PixelType = itk.RGBPixel[itk.UC]
ImageType = itk.Image[PixelType, Dimension]

```

the problem I think is that I want to do this in simpleITK, because otherwise I am mixing things together in a convoluted way, and having tried the above I get a type error.

either I need an equivalent SimpleITK version for RGB, or a way to convert a composite sitk transform to itk transform…

I have discovered this :

```auto
# Extract first three channels of joined image (assuming RGB)
select = sitk.VectorIndexSelectionCastImageFilter()
channel1_image = select.Execute(joined_image, 0, sitk.sitkUInt8)
channel2_image = select.Execute(joined_image, 1, sitk.sitkUInt8)
channel3_image = select.Execute(joined_image, 2, sitk.sitkUInt8)

```

I found that I can resample each component individually.

However from @blowekamp:

> [@Resample image python code.](https://discourse.itk.org/t/resample-image-python-code/408/5):
>
> SimpleITK’s Resample working with RGB or vector pixel types by default, so there is not need to run in on a per component basis.

So I must be missing something.

---

<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: [November 25, 2019, 3:20pm UTC](https://discourse.itk.org/t/resample-a-vector-image-with-transform/2438/2 "2019-11-25T15:20:35Z")

</div>

> [@kayarre](#):
>
> This method does not work with the image using this approach :
> 
> ```auto
> moving_resampled = sitk.Resample(t_sitk, f_sitk, transform, sitk.sitkLinear, 0.0, t_sitk.GetPixelID())
> 
> ```

Please elaborate on “does not work”. Do you get an error message?

---

<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: [November 25, 2019, 3:22pm UTC](https://discourse.itk.org/t/resample-a-vector-image-with-transform/2438/3 "2019-11-25T15:22:39Z")

</div>

> [@kayarre](#):
>
> ```auto
> moving_resampled = sitk.Resample(t_sitk, f_sitk, transform, sitk.sitkLinear, 0.0, t_sitk.GetPixelID())
> 
> ```

I’m going to get that `t_sitk.GetPixelID()`, the output pixel type is a scalar and not a vector image. Setting the output pixel type to the same as the input.

---

<div class="post-metadata">

### Author: ![kayarre](https://discourse.itk.org/user_avatar/discourse.itk.org/kayarre/32/669_2.png) [@kayarre](https://discourse.itk.org/u/kayarre)
#### Post date: [November 25, 2019, 5:57pm UTC](https://discourse.itk.org/t/resample-a-vector-image-with-transform/2438/4 "2019-11-25T17:57:37Z")

</div>

@blowekamp it returns an error, I will have to find it. it was something about types not being the same.

I think it was `vector of unit8 is not allowed.` or something like that,

what’s even more weird is that the above code works on the computer I am using at present, but it gave me the error on my home computer last night. I wonder if there is a difference between which types are wrapped with sitk?

---

<div class="post-metadata">

### Author: ![kayarre](https://discourse.itk.org/user_avatar/discourse.itk.org/kayarre/32/669_2.png) [@kayarre](https://discourse.itk.org/u/kayarre)
#### Post date: [November 25, 2019, 6:00pm UTC](https://discourse.itk.org/t/resample-a-vector-image-with-transform/2438/5 "2019-11-25T18:00:32Z")

</div>

@blowekamp  
I must have gotten confused, I think maybe I was calling Resample without passing the PixelID in and user defined function…

I will have to try again at home to see if the issue is between the seat and keyboard…
