# Developing General Purpose Functions using ITK with Function Templates

**URL:** <https://discourse.itk.org/t/developing-general-purpose-functions-using-itk-with-function-templates/652>\
**Category:** Engineering\
**Created:** [February 8, 2018, 10:19am UTC](https://discourse.itk.org/t/developing-general-purpose-functions-using-itk-with-function-templates/652 "2018-02-08T10:19:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![WillScottJackson](https://discourse.itk.org/user_avatar/discourse.itk.org/willscottjackson/32/190_2.png) [@WillScottJackson](https://discourse.itk.org/u/WillScottJackson)\
**Post date:** [February 8, 2018, 10:19am UTC](https://discourse.itk.org/t/developing-general-purpose-functions-using-itk-with-function-templates/652/1 "2018-02-08T10:19:59Z")

</div>

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?

Thanks!

---

<div class="post-metadata">

**Author:** ![tim-evain](https://discourse.itk.org/user_avatar/discourse.itk.org/tim-evain/32/220_2.png) [@tim-evain](https://discourse.itk.org/u/tim-evain)\
**Post date:** [February 8, 2018, 10:38am UTC](https://discourse.itk.org/t/developing-general-purpose-functions-using-itk-with-function-templates/652/2 "2018-02-08T10:38:18Z")

</div>

Hi,

[ImportImageFilter](https://itk.org/Doxygen/html/classitk_1_1ImportImageFilter.html) 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;`

HTH,

Tim

---

<div class="post-metadata">

**Author:** ![WillScottJackson](https://discourse.itk.org/user_avatar/discourse.itk.org/willscottjackson/32/190_2.png) [@WillScottJackson](https://discourse.itk.org/u/WillScottJackson)\
**Post date:** [February 8, 2018, 10:40am UTC](https://discourse.itk.org/t/developing-general-purpose-functions-using-itk-with-function-templates/652/3 "2018-02-08T10:40:50Z")

</div>

Works fine now! Perfect!

Thanks Tim!
