I’m trying to convert a C++ ITK code in python, but i find some issues with this input: TemplateTypeError: itk.ImageFileReader is not wrapped for input type itk.Image[itk.UL,3]. But i don’t know hot to solve the problem because i use this function to enter a .mha file.
Code:
import itk
import sys
import os
path=input(“Enter the path”)
Dim=3
PixelType=itk.F
LabelPixelType=itk.UL
ImageType=itk.Image[PixelType,Dim]
LabeledImageType=itk.Image[LabelPixelType,Dim]
MaskPixelType=itk.UC
MaskImageType=itk.Image[MaskPixelType,Dim] #read the 3mm input volume
LabelReaderType=itk.ImageFileReader[LabeledImageType]
labelReader=LabelReaderType.New()
labelReader.SetFileName(path+“/T2.mha”)
I guess itk::Image is not instantiated with unsigned long by default, so that is not part of wheel distribution. Try LabelPixelType=itk.US. Alternatively build ITK with Python wrapping yourself, and enable unsigned long for the wrapping.
Thank you so much, with LabelPixelType=itk.US it seems to work. But i have another problem: if i want to use an iterator like iteratorType=itk.ImageRegionIterator[LabeledImageType] in python what i have to do, due to AttributeError: module 'itk' has no attribute 'ImageRegionIterator'. I read something about numpy, do you have some examples?
ImageRegionIterator is not wrapped on purpose, because accessing images via iterators from Python is way too slow. Here is how to convert to/from numpy.
You are trying to do in python what ITK does in c++, this is not performant. Better to compute it in c++ and then, expose it to python with the wrapping mechanisms of ITK. Especially if you already have the filter written in c++. Hope it helps!
The problem is that the code is very older (many years ago) and some libraries in c++ changed,so some functions are no more supported, so i have also to modify the code