# How to use itk.cast\_image\_filter (in Python)?

**URL:** https://discourse.itk.org/t/how-to-use-itk-cast-image-filter-in-python/7638
**Category:** Uncategorized
**Created:** [September 21, 2025, 7:55am UTC](https://discourse.itk.org/t/how-to-use-itk-cast-image-filter-in-python/7638 "2025-09-21T07:55:08Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![constantine](https://discourse.itk.org/user_avatar/discourse.itk.org/constantine/32/3915_2.png) [@constantine](https://discourse.itk.org/u/constantine)
#### Post date: [September 21, 2025, 7:55am UTC](https://discourse.itk.org/t/how-to-use-itk-cast-image-filter-in-python/7638/1 "2025-09-21T07:55:08Z")

</div>

When I try this:

```auto
# Here deformation_field is of type itk.Image[itk.Vector[itk.F, 2], 2].
deformation_field_d = itk.cast_image_filter(deformation_field, ttype=itk.Image[itk.Vector[itk.D, 2], 2])

```

I get this error:

`File “...\Lib\site-packages\itk\itkCastImageFilterPython.py”, line 36927, in cast_image_filter`  
`instance = itk.CastImageFilter.New(*args, **kwargs)`  
`File “...\Lib\site-packages\itk\support\template_class.py”, line 703, in New`  
`raise RuntimeError(`  
`…<2 lines>…`  
`)`  
`RuntimeError: Expected 2 template parameters. 1 parameters given.`

What is the correct way of using `cast_image_filter` in this case? How can I cast from `itk.itkImagePython.itkImageVF22` to `itk.itkImagePython.itkImageVD22` please?

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [September 22, 2025, 11:45am UTC](https://discourse.itk.org/t/how-to-use-itk-cast-image-filter-in-python/7638/2 "2025-09-22T11:45:01Z")

</div>

Hi Constantine,

For `ttype`, the argument is a Python tuple of the template type parameters for the filter, the input image type and the output image type.

It is easier to use `cast_image_filter` via the `astype` method on `Image`, which just takes the output pixel type, i.e.

```python
deformation_field_d = deformation_field.astype(itk.Vector\[itk.D, 2\])

```
