I have written a class using ITK in CPP which reads all files in a directory and then averages them. I would like to use this class in a pipeline constructed using Python.
I had previously tried to use Swig to wrap template code but according to the swig documenation, it doesn't have template support and the type names need to explicitly specified. But when I use ITK in Python, the interface is very different to that I expect from Swig-generated template code (the type name is not specified in the function/class name at all, which is contrary to what Swig documentation says).
A small snippet from my code illustrating the usage of the class is shown below:
typedef unsigned char PixelType;
typedef itk::Image<PixelType, 2> ImageType;
typedef itk::NaryMeanImageFilter< ImageType, ImageType > FilterType; // custom class
typedef itk::ImageFileReader<ImageType> ReaderType;
typedef itk::ImageFileWriter<ImageType> WriterType;
ImageType::Pointer image = ImageType::New();
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
FilterType::Pointer filter = FilterType::New(); // custom class
for (unsigned int i = 0; i< fileNames.size(); ++i)
{
reader->SetFileName(fileNames[i]);
filter->SetInput(i, reader->GetOutput()); // custom class
}
writer->SetFileName(outName);
writer->SetInput(filter->GetOutput());
writer->Update();
The code for the class can be seen in the Git repository. I don't have an issue with increasing the dependencies of my project by using Boost::Python but I need a starting point to proceed. Any help would be extremely appreciated.
Thanks.
UPDATE:
Expected usage in Python would be,
readerType=itk.ImageFileReader[inputImageType]
reader=readerType.New()
filterType=itk.NaryMeanImageFilter[inputImageType,inputImageType]
filter=filterType.New()
for i in range(0, fileNames.size()):
reader.SetFileName(fileNames[i])
filter.SetInput(i, reader->GetOutput())