# How to get PixelType from Image

**URL:** <https://discourse.itk.org/t/how-to-get-pixeltype-from-image/374>\
**Category:** Beginner Questions\
**Tags:** python\
**Created:** [October 31, 2017, 3:10am UTC](https://discourse.itk.org/t/how-to-get-pixeltype-from-image/374 "2017-10-31T03:10:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![benjaminhon](https://discourse.itk.org/user_avatar/discourse.itk.org/benjaminhon/32/83_2.png) [@benjaminhon](https://discourse.itk.org/u/benjaminhon)\
**Post date:** [October 31, 2017, 3:10am UTC](https://discourse.itk.org/t/how-to-get-pixeltype-from-image/374/1 "2017-10-31T03:10:08Z")

</div>

Hi is it possible to get the Pixel type from an ITK Image? It seems like Simple ITK has GetPixelDValue. I can’t find any examples of how to do this is ITK though.

Thanks,  
Benjamin

---

<div class="post-metadata">

**Author:** ![fbudin](https://discourse.itk.org/user_avatar/discourse.itk.org/fbudin/32/14_2.png) [@fbudin](https://discourse.itk.org/u/fbudin)\
**Post date:** [October 31, 2017, 1:15pm UTC](https://discourse.itk.org/t/how-to-get-pixeltype-from-image/374/2 "2017-10-31T13:15:38Z")

</div>

With ITK Python, you can get any template argument with:  
`itk.template(image) #`image`is an itk.Image but it would work with any itk object (<itkTemplate itk::Image>, (<itkCType signed short>, 3))`

You will get a tuple as a result with all the template arguments of your object. You can then call again this function on one element of the tuple if needed.

---

<div class="post-metadata">

**Author:** ![benjaminhon](https://discourse.itk.org/user_avatar/discourse.itk.org/benjaminhon/32/83_2.png) [@benjaminhon](https://discourse.itk.org/u/benjaminhon)\
**Post date:** [November 6, 2017, 3:03am UTC](https://discourse.itk.org/t/how-to-get-pixeltype-from-image/374/3 "2017-11-06T03:03:43Z")

</div>

Thanks, ill check it out!

---

<div class="post-metadata">

**Author:** ![benjaminhon](https://discourse.itk.org/user_avatar/discourse.itk.org/benjaminhon/32/83_2.png) [@benjaminhon](https://discourse.itk.org/u/benjaminhon)\
**Post date:** [November 8, 2017, 8:28am UTC](https://discourse.itk.org/t/how-to-get-pixeltype-from-image/374/4 "2017-11-08T08:28:01Z")

</div>

Hi fbudin,

I am trying to do the following, however, I don’t think the format returned by the template can be used immediately, is it always the second tuple? or how would you suggest using the template as it is to construct a filter?

```auto
def CastFilter(input, outputType):
    caster = itk.CastImageFilter[itk.template(input), ItkTypes.IUC3].New()
    caster.SetInput(input.GetOutput())
    caster.Update()
    return caster

```

Thanks!

---

<div class="post-metadata">

**Author:** ![benjaminhon](https://discourse.itk.org/user_avatar/discourse.itk.org/benjaminhon/32/83_2.png) [@benjaminhon](https://discourse.itk.org/u/benjaminhon)\
**Post date:** [November 8, 2017, 8:54am UTC](https://discourse.itk.org/t/how-to-get-pixeltype-from-image/374/5 "2017-11-08T08:54:33Z")

</div>

ahh I just read your ITK post in the blog, I can just use type(image)

great!

---

<div class="post-metadata">

**Author:** ![fbudin](https://discourse.itk.org/user_avatar/discourse.itk.org/fbudin/32/14_2.png) [@fbudin](https://discourse.itk.org/u/fbudin)\
**Post date:** [November 8, 2017, 5:54pm UTC](https://discourse.itk.org/t/how-to-get-pixeltype-from-image/374/6 "2017-11-08T17:54:57Z")

</div>

Yes, using `type(image)` works. It is also possible to write:  
`itk.CastImageFilter[input,itk.Image.UC3].New()`
