I'm trying to create a pipeline for image segmentation, with the libraries from ITK. But, when I apply the itkMorphologicalWatershedFromMarkersFilter, the result is a blank image (binary image with only 1's).
Does anyone know how to apply this filter correctly?
My input image should be the gradient of an image, and the marker image should be the result of the application of a watershed filter on the same image.
input image
marker image
And this is the declaration and the application of the filter:
typedef itk::MorphologicalWatershedFromMarkersImageFilter < OutputImageType, OutputImageType >
MorphologicalWatershedFromMarkersImageFilterType;
MorphologicalWatershedFromMarkersImageFilterType::Pointer CwatershedFilter
= MorphologicalWatershedFromMarkersImageFilterType::New();
CwatershedFilter->SetInput1(reader1->GetOutput());
CwatershedFilter->SetMarkerImage(reader2->GetOutput());
CwatershedFilter->SetMarkWatershedLine(true);
try{
CwatershedFilter->Update();
}
catch (itk::ExceptionObject & error)
{
std::cerr << "Error: " << error << std::endl;
getchar();
return EXIT_FAILURE;
}
Also, this is the link to the documentation of this filter, from itk.org:
Thank you so much!!
While not C++ ITK, there is a SimpleITK Notebooks which demonstrates it's usage:
http://insightsoftwareconsortium.github.io/SimpleITK-Notebooks/32_Watersheds_Segmentation.html
Your marker image is just binary, and not a label image. By that I mean your image is only 0 and 1 ( or 255). In the linked example note the following:
min_img = sitk.RegionalMinima(feature_img, backgroundValue=0, foregroundValue=1.0, fullyConnected=False, flatIsMinima=True)
marker_img = sitk.ConnectedComponent(min_img, fullyConnected=False)
The "min_img" is a binary image, but then the image is processed with the "ConnectedComponent" image filter, which gives each "island" a unique number. This is what is expected for the marker ( or label ) image for the WatershedFromMarker filter.
I will also note that your input image has some boundary lines, that you may not want as input.