1 #include <tclap/CmdLine.h> 3 #include <itkTimeProbe.h> 7 int main(
int argc,
const char** argv)
11 TCLAP::CmdLine cmd(
"INRIA / IRISA - VisAGeS/Empenn Team",
' ',ANIMA_VERSION);
13 TCLAP::MultiArg<std::string> inputArg(
"i",
"input",
"Input images to segment (up to 5, e.g. T1, T2, DP, FLAIR, T1-Gd)",
14 true,
"input images",cmd);
16 TCLAP::ValueArg<std::string> maskFileArg(
"m",
"mask",
"Brain mask",
false,
"",
"brain mask",cmd);
17 TCLAP::ValueArg<std::string> sourcesMaskFileArg(
"",
"sof",
"Sources input image",
true,
"",
"Sources input image",cmd);
18 TCLAP::ValueArg<std::string> sinksMaskFileArg(
"",
"sif",
"Sinks input image",
true,
"",
"Sinks input image",cmd);
19 TCLAP::ValueArg<std::string> sourcesProbaFileArg(
"",
"sopf",
"Probabilities sources input image",
false,
"",
"Probabilities sources input image",cmd);
20 TCLAP::ValueArg<std::string> sinksProbaFileArg(
"",
"sipf",
"Probabilities sinks input image",
false,
"",
"Probabilities sinks input image",cmd);
21 TCLAP::SwitchArg verboseArg(
"V",
"verbose",
"verbose mode (default: false)",cmd,
false);
23 TCLAP::SwitchArg notUseSpecGradArg(
"U",
"no-usg",
"Do not use spectral gradient (default: false)",cmd,
false);
24 TCLAP::ValueArg<int> TLinkModeArg(
"",
"mode",
"Graph cut computation mode (0: single Gaussian, 1: STREM mode, default: 0)",
false,0,
"graph cut computation mode",cmd);
25 TCLAP::ValueArg<double> multiVarSourcesArg(
"",
"mv",
"Coefficient to multiply the variance value of the sources seed (default: 1)",
false,1,
"sources multiply variance",cmd);
26 TCLAP::ValueArg<double> multiVarSinksArg(
"",
"ms",
"Coefficient to multiply the variance value of the seed (default: 1)",
false,1,
"sinks multiply variance",cmd);
27 TCLAP::ValueArg<double> sigmaArg(
"s",
"sigma",
"sigma value (default: 0.6)",
false,0.6,
"sigma",cmd);
28 TCLAP::ValueArg<double> alphaArg(
"a",
"alpha",
"Alpha value (default: 10)",
false,10,
"alpha",cmd);
29 TCLAP::ValueArg<std::string> matrixGradArg(
"",
"mat",
"Spectral gradient matrix file",
false,
"",
"spectral gradient matrix file",cmd);
31 TCLAP::ValueArg<std::string> outputGCFileArg(
"o",
"out",
"Output segmentation",
true,
"",
"output segmentation",cmd);
37 catch (TCLAP::ArgException& e)
39 std::cerr <<
"Error: " << e.error() <<
"for argument " << e.argId() << std::endl;
43 const unsigned int Dimension = 3;
44 typedef itk::Image <double,Dimension> InputImageTypeD;
45 typedef itk::Image <unsigned char,Dimension> InputImageTypeUC;
49 FilterTypeGraphCut::Pointer GraphCutFilter = FilterTypeGraphCut::New();
51 for (
unsigned int i = 0;i < inputArg.getValue().size();++i)
52 GraphCutFilter->SetInputImage(i,anima::readImage<InputImageTypeD>(inputArg.getValue()[i]));
54 if( sourcesProbaFileArg.getValue()!=
"" )
56 GraphCutFilter->SetInputSeedSourcesProba( anima::readImage<InputImageTypeD>(sourcesProbaFileArg.getValue()) );
59 if( sinksProbaFileArg.getValue()!=
"" )
61 GraphCutFilter->SetInputSeedSinksProba( anima::readImage<InputImageTypeD>(sinksProbaFileArg.getValue()) );
64 if( maskFileArg.getValue()!=
"" )
65 GraphCutFilter->SetMask( anima::readImage<InputImageTypeUC>(maskFileArg.getValue()) );
68 InputImageTypeUC::Pointer maskImage = InputImageTypeUC::New();
69 maskImage->SetRegions(GraphCutFilter->GetInput(0)->GetLargestPossibleRegion());
70 maskImage->SetSpacing(GraphCutFilter->GetInput(0)->GetSpacing());
71 maskImage->SetOrigin(GraphCutFilter->GetInput(0)->GetOrigin());
72 maskImage->SetDirection(GraphCutFilter->GetInput(0)->GetDirection());
74 maskImage->Allocate();
75 maskImage->FillBuffer(1);
77 GraphCutFilter->SetMask(maskImage);
80 if( sourcesMaskFileArg.getValue()!=
"" )
82 GraphCutFilter->SetInputSeedSourcesMask( anima::readImage<InputImageTypeUC>(sourcesMaskFileArg.getValue()) );
85 if( sinksMaskFileArg.getValue()!=
"" )
87 GraphCutFilter->SetInputSeedSinksMask( anima::readImage<InputImageTypeUC>(sinksMaskFileArg.getValue()) );
91 GraphCutFilter->SetVerbose( verboseArg.getValue() );
92 GraphCutFilter->SetUseSpectralGradient( !(notUseSpecGradArg.getValue()) );
93 GraphCutFilter->SetTLinkMode( (
TLinkMode) TLinkModeArg.getValue() );
94 GraphCutFilter->SetMultiVarSources( multiVarSourcesArg.getValue() );
95 GraphCutFilter->SetMultiVarSinks( multiVarSinksArg.getValue() );
96 GraphCutFilter->SetAlpha( alphaArg.getValue() );
97 GraphCutFilter->SetSigma( sigmaArg.getValue() );
98 GraphCutFilter->SetMatrixGradFilename( matrixGradArg.getValue() );
99 GraphCutFilter->SetOutputFilename( outputGCFileArg.getValue() );
103 itk::TimeProbe timer;
109 GraphCutFilter->Update();
110 GraphCutFilter->WriteOutputs();
112 catch (itk::ExceptionObject &e)
114 std::cerr << e << std::endl;
120 std::cout <<
"Elapsed Time: " << timer.GetTotal() << timer.GetUnit() << std::endl;
int main(int argc, const char **argv)
Class performing grah cut segmentation. First the sources and sinks probabilities maps are computed u...