# RuntimeError: No suitable template parameter can be found

**URL:** <https://discourse.itk.org/t/runtimeerror-no-suitable-template-parameter-can-be-found/4159>\
**Category:** Beginner Questions\
**Tags:** python\
**Created:** [May 26, 2021, 12:48pm UTC](https://discourse.itk.org/t/runtimeerror-no-suitable-template-parameter-can-be-found/4159 "2021-05-26T12:48:28Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![nbob](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/59ef9b/32.png) [@nbob](https://discourse.itk.org/u/nbob)\
**Post date:** [May 26, 2021, 12:48pm UTC](https://discourse.itk.org/t/runtimeerror-no-suitable-template-parameter-can-be-found/4159/1 "2021-05-26T12:48:28Z")

</div>

Hello,

I am trying to replicate the code from this notebook [ITK-Watershed to Label Bubbles | Kaggle](https://www.kaggle.com/kmader/itk-watershed-to-label-bubbles/execution) for 3D watershed segmentation locally. It runs in the notebook, however, locally, `itk.GetArrayFromImage(watershedOp)` yields RuntimeError: No suitable parameter can be found. I am not sure how to resolve this. Thanks.

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [May 26, 2021, 1:11pm UTC](https://discourse.itk.org/t/runtimeerror-no-suitable-template-parameter-can-be-found/4159/2 "2021-05-26T13:11:21Z")

</div>

Which line produces the error? Which version of ITK are you using?

---

<div class="post-metadata">

**Author:** ![nbob](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/59ef9b/32.png) [@nbob](https://discourse.itk.org/u/nbob)\
**Post date:** [May 26, 2021, 1:43pm UTC](https://discourse.itk.org/t/runtimeerror-no-suitable-template-parameter-can-be-found/4159/3 "2021-05-26T13:43:44Z")

</div>

Thanks for your response:

```auto
def apply_watershed(in_vol, 
                    threshold = 0.01, 
                    level = 0.5):
    """
    threshold: is used to set the absolute minimum height value used during processing. 
        Raising this threshold percentage effectively decreases the number of local minima in the input, 
        resulting in an initial segmentation with fewer regions. 
        The assumption is that the shallow regions that thresholding removes are of of less interest.
    level: parameter controls the depth of metaphorical flooding of the image. 
        That is, it sets the maximum saliency value of interest in the result. 
        Raising and lowering the Level influences the number of segments 
        in the basic segmentation that are merged to produce the final output. 
        A level of 1.0 is analogous to flooding the image up to a 
        depth that is 100 percent of the maximum value in the image. 
        A level of 0.0 produces the basic segmentation, which will typically be very oversegmented. 
        Level values of interest are typically low (i.e. less than about 0.40 or 40% ), 
        since higher values quickly start to undersegment the image.
    """
    #(A rule of thumb is to set the Threshold to be about 1 / 100 of the Level.)
    Dimension = len(np.shape(in_vol))
    # convert to itk array and normalize
    itk_vol_img = itk.GetImageFromArray((in_vol*255.0).clip(0,255).astype(np.uint8))
    InputImageType = itk.Image[itk.ctype('unsigned char'), Dimension]
    OutputImageType = itk.Image[itk.ctype('float'), Dimension]
    dmapOp = itk.SignedMaurerDistanceMapImageFilter[InputImageType, OutputImageType].New(Input = itk_vol_img)
    dmapOp.SetInsideIsPositive(False)
    watershedOp = itk.WatershedImageFilter.New(Input=dmapOp.GetOutput())
    watershedOp.SetThreshold(threshold)
    watershedOp.SetLevel(level)
    watershedOp.Update()
    return itk.GetArrayFromImage(dmapOp), itk.GetArrayFromImage(watershedOp)

```

The error occurs in the return statement of this function for `itk.GetArrayFromImage(watershedOp)`. I am using ITK version 5.2 with Python 3.8.8 but have also tried ITK version 5.1.2 and Python 3.6.4 like in the notebook. I am using a conda environment.

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [May 26, 2021, 2:38pm UTC](https://discourse.itk.org/t/runtimeerror-no-suitable-template-parameter-can-be-found/4159/4 "2021-05-26T14:38:49Z")

</div>

> [@nbob](#):
>
> `return itk.GetArrayFromImage(dmapOp), itk.GetArrayFromImage(watershedOp)`

Try changing the last line into: `return itk.GetArrayFromImage(dmapOp.GetOutput()), itk.GetArrayFromImage(watershedOp.GetOutput())`

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [May 26, 2021, 2:40pm UTC](https://discourse.itk.org/t/runtimeerror-no-suitable-template-parameter-can-be-found/4159/5 "2021-05-26T14:40:27Z")

</div>

Or for easier debuggability, into a few lines:

```auto
distance_image = itk.GetArrayFromImage(dmapOp.GetOutput())
segmentation = itk.GetArrayFromImage(watershedOp.GetOutput())
return distance_image, segmentation
```

---

<div class="post-metadata">

**Author:** ![nbob](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/59ef9b/32.png) [@nbob](https://discourse.itk.org/u/nbob)\
**Post date:** [May 26, 2021, 2:47pm UTC](https://discourse.itk.org/t/runtimeerror-no-suitable-template-parameter-can-be-found/4159/6 "2021-05-26T14:47:53Z")

</div>

The same RuntimeError still occurs in the segmentation line.

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [May 26, 2021, 3:10pm UTC](https://discourse.itk.org/t/runtimeerror-no-suitable-template-parameter-can-be-found/4159/7 "2021-05-26T15:10:49Z")

</div>

Ah, you might be affected by [issue 2551](https://github.com/InsightSoftwareConsortium/ITK/issues/2551). Does numpy support 64-bit unsigned element type?

---

<div class="post-metadata">

**Author:** ![nbob](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/59ef9b/32.png) [@nbob](https://discourse.itk.org/u/nbob)\
**Post date:** [May 26, 2021, 3:40pm UTC](https://discourse.itk.org/t/runtimeerror-no-suitable-template-parameter-can-be-found/4159/8 "2021-05-26T15:40:56Z")

</div>

> [@dzenanz](#):
>
> Does numpy support 64-bit unsigned element type?

Numpy has np.uint64 as a data type if that is what you mean?  
`watershedOp.GetOutput()` produces `<itk.itkImagePython.itkImageULL3; proxy of <Swig Object of type 'itkImageULL3`  
Sorry, I am not sure how to interpret a solution from that issue in this case.

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [May 26, 2021, 3:55pm UTC](https://discourse.itk.org/t/runtimeerror-no-suitable-template-parameter-can-be-found/4159/9 "2021-05-26T15:55:12Z")

</div>

I think that the problem is absence of `ULL` from this list of types for PyBuffer which does conversion between ITK and Numpy:

> <https://github.com/InsightSoftwareConsortium/ITK/blob/v5.2.0/Modules/Bridge/NumPy/wrapping/itkPyBuffer.wrap#L5>

If you could create a short, self-contained example I could verify this and create a patch to fix it.

---

<div class="post-metadata">

**Author:** ![nbob](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/59ef9b/32.png) [@nbob](https://discourse.itk.org/u/nbob)\
**Post date:** [May 26, 2021, 4:32pm UTC](https://discourse.itk.org/t/runtimeerror-no-suitable-template-parameter-can-be-found/4159/10 "2021-05-26T16:32:54Z")

</div>

```auto
import numpy as np
import itk
from skimage.io import imread, imsave

def apply_watershed(in_vol, threshold=0.01, level=0.5):
    Dimension = len(np.shape(in_vol))
    # convert to itk array and normalize
    itk_vol_img = itk.GetImageFromArray((in_vol*255.0).clip(0,255).astype(np.uint8))
    InputImageType = itk.Image[itk.ctype('unsigned char'), Dimension]
    OutputImageType = itk.Image[itk.ctype('float'), Dimension]
    dmapOp = itk.SignedMaurerDistanceMapImageFilter[InputImageType, OutputImageType].New(Input = itk_vol_img)

    dmapOp.SetInsideIsPositive(False)
    watershedOp = itk.WatershedImageFilter.New(Input=dmapOp.GetOutput())
    watershedOp.SetThreshold(threshold)
    watershedOp.SetLevel(level)
    watershedOp.Update()
    distance_image = itk.GetArrayFromImage(dmapOp.GetOutput())
    segmentation = itk.GetArrayFromImage(watershedOp.GetOutput())
    return distance_image, segmentation

if __name__ == ' __main__':
    image = imread('plateau_border.tif')
    dist_img, seg_img = apply_watershed(image)

```

The attached zip contains the tif file I obtained from [ITK-Watershed to Label Bubbles | Kaggle](https://www.kaggle.com/kmader/itk-watershed-to-label-bubbles/data).  
[plateau\_border.zip](https://discourse.itk.org/uploads/short-url/A4OmyE7hgyMzNSfMbwkpyT5fAST.zip) (1.3 MB)

I hope this is enough for you to work with. Thank you very much for your time and looking into this.

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [May 26, 2021, 7:30pm UTC](https://discourse.itk.org/t/runtimeerror-no-suitable-template-parameter-can-be-found/4159/11 "2021-05-26T19:30:38Z")

</div>

I created [PR 2554](https://github.com/InsightSoftwareConsortium/ITK/pull/2554). If you build ITK yourself, it would be good if you tried the fix now. If not, you will have to wait for the next patch release.

---

<div class="post-metadata">

**Author:** ![jhlegarreta](https://discourse.itk.org/user_avatar/discourse.itk.org/jhlegarreta/32/476_2.png) [@jhlegarreta](https://discourse.itk.org/u/jhlegarreta)\
**Post date:** [May 26, 2021, 8:21pm UTC](https://discourse.itk.org/t/runtimeerror-no-suitable-template-parameter-can-be-found/4159/12 "2021-05-26T20:21:15Z")

</div>

Sorry, I’m late to the conversation.

Thanks for reporting issue @nbob, and thanks for addressing the issue @dzenanz 💯.

For the sake of completeness, adding Kevin’s example to the ITKSphinxExamples is still a long stating task that has been lying on my end:

> <https://github.com/InsightSoftwareConsortium/ITKSphinxExamples/pull/86>
>
> Add watershed with distance map example.
> 
> Resolves #48.

I am sorry; have not found the energy and time to give it a new try. But it will come at some point. Thanks for the patience.

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [May 26, 2021, 8:25pm UTC](https://discourse.itk.org/t/runtimeerror-no-suitable-template-parameter-can-be-found/4159/13 "2021-05-26T20:25:36Z")

</div>

Maybe @nbob might be interested in picking up your work? The Python code can be significantly shortened and simplified by using the newer, procedural interface of ITK.

---

<div class="post-metadata">

**Author:** ![nbob](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/59ef9b/32.png) [@nbob](https://discourse.itk.org/u/nbob)\
**Post date:** [May 27, 2021, 7:30am UTC](https://discourse.itk.org/t/runtimeerror-no-suitable-template-parameter-can-be-found/4159/14 "2021-05-27T07:30:54Z")

</div>

Thank you both for your time. @dzenanz I do not have any experience with ITK or contributing to software. While I am intrigued, I also have no idea what to do to be honest.

---

<div class="post-metadata">

**Author:** ![jhlegarreta](https://discourse.itk.org/user_avatar/discourse.itk.org/jhlegarreta/32/476_2.png) [@jhlegarreta](https://discourse.itk.org/u/jhlegarreta)\
**Post date:** [May 28, 2021, 1:32pm UTC](https://discourse.itk.org/t/runtimeerror-no-suitable-template-parameter-can-be-found/4159/15 "2021-05-28T13:32:43Z")

</div>

> [@dzenanz](#):
>
> The Python code can be significantly shortened and simplified by using the newer, procedural interface of ITK

Yes, ITK has greatly evolved since then, and this is something that was not complete at the time, so I should have a look at that.

> [@nbob](#):
>
> I do not have any experience with ITK or contributing to software. While I am intrigued, I also have no idea what to do to be honest.

Thanks @nbob. If you feel like you want to give it a try, you can start having a look at more simple examples to see how the framework is designed to pick up the code, show the images, etc.

Other than this specific case, examples demonstrating the many other ITK classes are also more than welcome 💯.

We grant that we should add a `CONTRIBUTING` file to the documentation.

Kevin’s example is a little bit more complex since it has many parts that I decided to split and put into (hopefully) re-usable files/methods. But last time I gave the example a try, I was not able not reproduce the results on the Kaggle website, and had issues with some Python statements. I should revisit that to see how things are now.
