Developing General Purpose Functions using ITK with Function Templates

Hi There

I’m working on an image processing library and using ITK functionality to achieve this. I’m trying to design this library so that it is as general purpose as possible and hoping function templates will do the job in achieving this. For example:

template<class Image, class OutputData>
bool Add(Image *pImgA, Image *pImgB, OutputData *pOutputData, bool scale, double &scale_factor) {

	// Define ITK types based on template 
	typedef OutputData PixelType;
	typedef itk::Image<OutputData, SliceDimension> InputImageType;
	typedef itk::ImportImageFilter<InputImageType> ImportFilterType;

In principle I could import an image of unspecified datatype; however, this isn’t working as intended. But when I try to initialise and use an instance of this import filter; Visual Studio won’t compile and will throw the error:
Error 4 error C2664: ‘itk::ImportImageFilter::SetImportPointer’ : cannot convert parameter 1 from ‘short *’ to ‘InputImageType *’

Any thoughts on this? Is there any easy to achieve a general purpose algorithm that can deal with a variety of datatypes? Or do I need to suck it up and write a load of overloaded functions instead?



ImportImageFilter template signature is not an image type, but the pixel type and dimensions.
So your typedef will probably be:
typedef itk::ImportImageFilter<OutputData,SliceDimension> ImportFilterType;




Works fine now! Perfect!

Thanks Tim!

1 Like