I am segmentation fault with geodesic active contour.
my code:
using SmoothingFilterType_Heart_Seg = itk::CurvatureAnisotropicDiffusionImageFilter<InternalImageType, InternalImageType>;
auto SmoothingFilter_Heart_Seg = SmoothingFilterType_Heart_Seg::New();
SmoothingFilter_Heart_Seg->SetTimeStep(0.0425);
SmoothingFilter_Heart_Seg->SetNumberOfIterations(5);
SmoothingFilter_Heart_Seg->SetConductanceParameter(3.0);
SmoothingFilter_Heart_Seg->SetInput(ROIFilter_Heart->GetOutput());
using GradientFilterType_Heart_Seg = itk::GradientMagnitudeRecursiveGaussianImageFilter<InternalImageType, InternalImageType>;
auto gradientMagnitude_Heart_Seg = GradientFilterType_Heart_Seg::New();
gradientMagnitude_Heart_Seg->SetSigma(sigma);
gradientMagnitude_Heart_Seg->SetInput(SmoothingFilter_Heart_Seg->GetOutput());
using SigmoidFilterType_Heart_Seg = itk::SigmoidImageFilter<InternalImageType, InternalImageType>;
auto sigmoid_Heart_Seg = SigmoidFilterType_Heart_Seg::New();
sigmoid_Heart_Seg->SetOutputMinimum(0.0);
sigmoid_Heart_Seg->SetOutputMaximum(1.0);
sigmoid_Heart_Seg->SetAlpha(-1.0);
sigmoid_Heart_Seg->SetBeta(3);
sigmoid_Heart_Seg->SetInput(SmoothingFilter_Heart_Seg->GetOutput());
using FastMarchingFilterType_Heart = itk::FastMarchingImageFilter<InternalImageType, InternalImageType>;
auto fastMarching_Heart = FastMarchingFilterType_Heart::New();
// fastMarching_Heart->SetInput(sigmoid_Heart_Seg->GetOutput());
using GeodesicActiveContourFilterType_Heart = itk::GeodesicActiveContourLevelSetImageFilter<InternalImageType, InternalImageType>;
auto geodesicActiveContour_heart = GeodesicActiveContourFilterType_Heart::New();
geodesicActiveContour_heart->SetPropagationScaling(propagationScaling);
geodesicActiveContour_heart->SetCurvatureScaling(std::stod(argv[24]));
geodesicActiveContour_heart->SetAdvectionScaling(std::stod(argv[25]));
geodesicActiveContour_heart->SetMaximumRMSError(std::stod(argv[26]));
geodesicActiveContour_heart->SetNumberOfIterations(numberOfIterations);
geodesicActiveContour_heart->SetInput(fastMarching_Heart->GetOutput());
geodesicActiveContour_heart->SetFeatureImage(gradientMagnitude_Heart_Seg->GetOutput());
using ThresholdingFilterType_Heart = itk::BinaryThresholdImageFilter<InternalImageType, InternalImageType>;
auto thresholder_heart = ThresholdingFilterType_Heart::New();
thresholder_heart->SetLowerThreshold(-1000.0);
thresholder_heart->SetUpperThreshold(0.0);
thresholder_heart->SetOutsideValue(0);
thresholder_heart->SetInsideValue(255);
thresholder_heart->SetInput(geodesicActiveContour_heart->GetOutput());
using NodeContainer_Heart = FastMarchingFilterType_Heart::NodeContainer;
using NodeType_Heart = FastMarchingFilterType_Heart::NodeType;
InternalImageType::IndexType seedPosition_AGC;
InternalImageType::IndexType seedPosition_AGC2;
InternalImageType::IndexType seedPosition_AGC3;
InternalImageType::IndexType seedPosition_AGC4;
seedPosition_AGC=seed1Position_heart;
seedPosition_AGC2=seed2Position_heart;
seedPosition_AGC3=seed3Position_heart;
seedPosition_AGC4=seed4Position_heart;
auto seeds = NodeContainer_Heart::New();
NodeType_Heart node_heart;
node_heart.SetValue(seedValue);
node_heart.SetIndex(seedPosition_AGC);
seeds->Initialize();
seeds->InsertElement(0, node_heart);
node_heart.SetValue(seedValue);
node_heart.SetIndex(seedPosition_AGC2);
seeds->InsertElement(1, node_heart);
node_heart.SetValue(seedValue);
node_heart.SetIndex(seedPosition_AGC3);
seeds->InsertElement(2, node_heart);
node_heart.SetValue(seedValue);
node_heart.SetIndex(seedPosition_AGC4);
seeds->InsertElement(3, node_heart);
fastMarching_Heart->SetTrialPoints(seeds);
fastMarching_Heart->SetSpeedConstant(1.0);
fastMarching_Heart->SetOutputDirection(inImage->GetDirection());
fastMarching_Heart->SetOutputOrigin(inImage->GetOrigin());
fastMarching_Heart->SetOutputRegion(inImage->GetBufferedRegion());
fastMarching_Heart->SetOutputSpacing(inImage->GetSpacing());
const char * outputDirectoryHeart = argv[20];
itksys::SystemTools::MakeDirectory(outputDirectoryHeart);
using NumericSeriesFileNames_Type = itk::NumericSeriesFileNames;
auto namesGenerator_Heart_Seg = NumericSeriesFileNames_Type::New();
std::string format = "Segmented Heart";
format += "_%d.tiff";
namesGenerator_Heart_Seg->SetSeriesFormat(format.c_str());
namesGenerator_Heart_Seg->SetStartIndex(0);
namesGenerator_Heart_Seg->SetEndIndex(Heart_ROI_Depth);
namesGenerator_Heart_Seg->SetIncrementIndex(1);
using InternalImageType_2D = itk::Image<float, 2>;
using SeriesWriterType_Heart = itk::ImageSeriesWriter<InternalImageType, InternalImageType_2D>;
auto seriesWriter_Heart = SeriesWriterType_Heart::New();
seriesWriter_Heart->SetInput(thresholder_heart->GetOutput());
seriesWriter_Heart->SetFileName(argv[20]);
seriesWriter_Heart->SetFileNames(namesGenerator_Heart_Seg->GetFileNames());
try
{
seriesWriter_Heart->Update();
}
catch (itk::ExceptionObject & excp)
{
std::cerr << "Exception thrown while writing the series " << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}