2 #include <itkImageRegionConstIterator.h> 3 #include <tclap/CmdLine.h> 6 int main(
int argc,
char * *argv)
8 TCLAP::CmdLine cmd(
"Computes the generalized Dice measure as proposed by Crum et al. \nINRIA / IRISA - VisAGeS/Empenn Team",
' ', ANIMA_VERSION);
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);
16 cmd.parse(argc, argv);
18 catch (TCLAP::ArgException& e)
20 std::cerr <<
"Error: " << e.error() <<
"for argument " << e.argId() << std::endl;
24 typedef itk::Image <double, 3> ImageType;
25 typedef itk::ImageRegionConstIterator <ImageType> ImageIteratorType;
27 ImageType::Pointer refImage = anima::readImage <ImageType> (refArg.getValue());
28 ImageType::Pointer testImage = anima::readImage <ImageType> (testArg.getValue());
30 ImageIteratorType refIt (refImage, refImage->GetLargestPossibleRegion());
31 ImageIteratorType testIt (testImage, testImage->GetLargestPossibleRegion());
33 double countRefImage = 0.0;
34 double countTestImage = 0.0;
35 double countIntersection = 0.0;
37 while (!refIt.IsAtEnd())
39 double refValue = refIt.Get();
40 double testValue = testIt.Get();
42 countRefImage += refValue;
43 countTestImage += testValue;
45 countIntersection += std::min(refValue, testValue);
51 double diceValue = 2.0 * countIntersection / (countRefImage + countTestImage);
54 diceValue = diceValue / (2.0 - diceValue);
56 std::cout << diceValue << std::endl;
int main(int argc, char **argv)