How to get PixelType from Image

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.


With ITK Python, you can get any template argument with:
itk.template(image) #imageis 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.

1 Like

Thanks, ill check it out!

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?

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


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


1 Like

Yes, using type(image) works. It is also possible to write: