ANIMA  4.0
animaFuzzyDiceMeasure.cxx
Go to the documentation of this file.
2 #include <itkImageRegionConstIterator.h>
3 #include <tclap/CmdLine.h>
4 #include <fstream>
5 
6 int main(int argc, char * *argv)
7 {
8  TCLAP::CmdLine cmd("Computes the generalized Dice measure as proposed by Crum et al. \nINRIA / IRISA - VisAGeS/Empenn Team", ' ', ANIMA_VERSION);
9 
10  TCLAP::ValueArg <std::string> refArg("r", "reffile", "Reference segmentation", true, "", "reference image", cmd);
11  TCLAP::ValueArg <std::string> testArg("t", "testfile", "Test segmentation", true, "", "test image", cmd);
12  TCLAP::SwitchArg jacArg("J", "jaccard", "Compute Jaccard similarity instead of Dice", cmd, false);
13 
14  try
15  {
16  cmd.parse(argc, argv);
17  }
18  catch (TCLAP::ArgException& e)
19  {
20  std::cerr << "Error: " << e.error() << "for argument " << e.argId() << std::endl;
21  return EXIT_FAILURE;
22  }
23 
24  typedef itk::Image <double, 3> ImageType;
25  typedef itk::ImageRegionConstIterator <ImageType> ImageIteratorType;
26 
27  ImageType::Pointer refImage = anima::readImage <ImageType> (refArg.getValue());
28  ImageType::Pointer testImage = anima::readImage <ImageType> (testArg.getValue());
29 
30  ImageIteratorType refIt (refImage, refImage->GetLargestPossibleRegion());
31  ImageIteratorType testIt (testImage, testImage->GetLargestPossibleRegion());
32 
33  double countRefImage = 0.0;
34  double countTestImage = 0.0;
35  double countIntersection = 0.0;
36 
37  while (!refIt.IsAtEnd())
38  {
39  double refValue = refIt.Get();
40  double testValue = testIt.Get();
41 
42  countRefImage += refValue;
43  countTestImage += testValue;
44 
45  countIntersection += std::min(refValue, testValue);
46 
47  ++refIt;
48  ++testIt;
49  }
50 
51  double diceValue = 2.0 * countIntersection / (countRefImage + countTestImage);
52 
53  if (jacArg.isSet())
54  diceValue = diceValue / (2.0 - diceValue);
55 
56  std::cout << diceValue << std::endl;
57 
58  return EXIT_SUCCESS;
59 }
60 
int main(int argc, char **argv)