Hi,
I am trying to run WatershedImageFilter class function with this arguments(image -{0.,0.,0.,0.,1.f/4503599627370496.f,0.,0.}, 1.0(Level), 0.0(Threshold)).
#include "itkWatershedImageFilter.h"
#include "itkCastImageFilter.h"
#include "itkRelabelComponentImageFilter.h"
#include <vector>
#include <math.h>
int main( int argc, char *argv[] ) {
typedef float InternalPixelType;
const unsigned int Dimension = 2;
typedef itk::Image< float, Dimension > InputImageType;
typedef itk::Image< double, Dimension > OutputImageType;
InputImageType::Pointer image = InputImageType::New();
int width = 7;
int height = 1;
InputImageType::SizeType size;
size[0] = width;
size[1] = height;
InputImageType::RegionType region;
region.SetSize( size );
image->SetRegions( region );
image->Allocate();
constexpr float gyot = (1.f/4503599627370496.f);
std::vector<float> arr = {0.,0.,0.,0.,gyot,0.,0.};
memcpy(image->GetBufferPointer(), arr.data(), width * height * sizeof(float));
typedef itk::WatershedImageFilter<InputImageType> WatershedFilterType;
typedef itk::Image<itk::IdentifierType, Dimension> FilteredImageType;
typedef itk::CastImageFilter<FilteredImageType, OutputImageType> CastFilterType;
typedef itk::RelabelComponentImageFilter<FilteredImageType, FilteredImageType> RelabelFilterType;
WatershedFilterType::Pointer watershedFilter = WatershedFilterType::New();
watershedFilter->SetInput( image );
watershedFilter->SetLevel( 1.0 );
watershedFilter->SetThreshold( 0.0 );
typename RelabelFilterType::Pointer relabeler = RelabelFilterType::New();
relabeler->SetInput(watershedFilter->GetOutput());
typename CastFilterType::Pointer caster = CastFilterType::New();
caster->SetInput(relabeler->GetOutput());
try
{
caster->Update();
}
catch( itk::ExceptionObject & excep )
{
std::cerr << "Exception caught !" << std::endl;
std::cerr << excep << std::endl;
return EXIT_FAILURE;
}
std::cout << "Success" << std::endl;
return EXIT_SUCCESS;
}
In Linux everything works fine.(Throws Description: itk::ERROR: itk::watershed::SegmentTreeGenerator::MergeSegments:: An unexpected and fatal error has occurred. This is probably the result of overthresholding of the input image.
)
But in Windows the result of this code is unstable: It may crash, throw exception or give some segmentation(After running that code several times).
I’m using ITK’s 5.0.0 version.
Does anyone know about this problem.
I would be appreciate any help.
Thanks Hrach.