Watershed filter: casting issue


Is there a way to cast the itk::WatershedImageFilter< TInputImage > filter to a itk::ImageToImageFilter< TInputImage, TOutputImage > type?

where TInputImage = TOutputImage = itk::Image<float, 3u>

All the other filters in the pipeline use the above type, and I was storing the filters to the pipeline having this specific type, but the watershed has a different output type, i.e. itk::IdentifierType (unsigned).

Any suggestions would help.

Thank you in advance.


Hello Bipul,

The WatershedImageFilter inherits directly from :
ImageToImageFilter<TInputImage, Image<IdentifierType,TInputImage::ImageDimension>>
As you said, IdentifierType is an unsigned integer, so as far as I know you can’t cast it to float.

Two solutions :
-You can derive you own “WatershedImageFilter” by copying the code of the filter, and modifying it to accept any type,
-You can use the MorphologicalWatershedImageFilter, which is the same method but implemented through mathematical morphology (refer to the doc here, and the journal contribution here ), that doesn’t force the output type, and takes the same syntax as any ImageToImageFilter.



You can also add a cast filter in the pipeline right after watershed.