- //DD(input1->GetLargestPossibleRegion());
- //DD(input2->GetLargestPossibleRegion());
-
- // Compute overlap image
- ImagePointer image_union = clitk::Clone<ImageType>(input1);
- ImagePointer image_intersection = clitk::Clone<ImageType>(input1);
- clitk::Or<ImageType>(image_union, input2, GetBackgroundValue());
- clitk::And<ImageType>(image_intersection, input2, GetBackgroundValue());
-
- //writeImage<ImageType>(image_union, "union.mha");
- //writeImage<ImageType>(image_intersection, "intersection.mha");
-
- // Compute size
- typedef itk::LabelStatisticsImageFilter<ImageType, ImageType> StatFilterType;
- typename StatFilterType::Pointer statFilter = StatFilterType::New();
- statFilter->SetInput(image_union);
- statFilter->SetLabelInput(image_union);
- statFilter->Update();
- int u = statFilter->GetCount(GetLabel1());
-
- statFilter->SetInput(image_intersection);
- statFilter->SetLabelInput(image_intersection);
- statFilter->Update();
- int inter = statFilter->GetCount(GetLabel1());
-
- statFilter->SetInput(m_Input1);
- statFilter->SetLabelInput(m_Input1);
- statFilter->Update();
- int in1 = statFilter->GetCount(GetLabel1());
-
- statFilter->SetInput(m_Input2);
- statFilter->SetLabelInput(m_Input2);
- statFilter->Update();
- int in2 = statFilter->GetCount(GetLabel1());
-
- std::cout << in1 << " " << in2 << " " << inter << " " << u << " "
- << 2.0*(double)inter/(double)(in1+in2) << std::endl;
+ /*
+ if (GetVerboseFlag()) {
+ std::cout << "Resize images to the union of bounding boxes: "
+ << input1->GetLargestPossibleRegion().GetSize() << std::endl;
+ }
+ */
+
+ /*
+ int width = 6;
+ std::cout << std::setw(width) << in1 << " "
+ << std::setw(width) << in2 << " "
+ << std::setw(width) << inter << " "
+ << std::setw(width) << u << " "
+ << std::setw(width) << l1notIn2 << " "
+ << std::setw(width) << l2notIn1 << " "
+ << std::setw(width) << dice << " "; //std::endl;
+ */
+
+ // Compute overlap, dice
+ typedef itk::LabelOverlapMeasuresImageFilter<ImageType> FilterType;
+ typename FilterType::Pointer diceFilter = FilterType::New();
+ diceFilter->SetSourceImage(input1);
+ diceFilter->SetTargetImage(input2);
+ diceFilter->Update();
+
+ // Display information
+ if (!GetLongFlag()) {
+ if (GetVerboseFlag()) {
+ std::cout << "Dice : ";
+ }
+ std::cout << diceFilter->GetDiceCoefficient() << std::endl;
+ }
+ else { // long options
+ if (GetVerboseFlag()) {
+ std::cout << "Dice Jaccard Source Target Inter Union SrComp TarComp" << std::endl;
+ }
+ typename FilterType::MapType m = diceFilter->GetLabelSetMeasures();
+ int width = 6;
+ std::cout << std::setw(width) << diceFilter->GetDiceCoefficient() << " "
+ << std::setw(width) << diceFilter->GetJaccardCoefficient() << " "
+ << std::setw(width) << m[m_Label1].m_Source << " "
+ << std::setw(width) << m[m_Label2].m_Target << " "
+ << std::setw(width) << m[m_Label1].m_Intersection << " "
+ << std::setw(width) << m[m_Label1].m_Union << " "
+ << std::setw(width) << m[m_Label1].m_SourceComplement << " "
+ << std::setw(width) << m[m_Label2].m_TargetComplement << " "
+ << std::endl;
+ }
+