Exemplo n.º 1
0
  void TestRemoveLabels()
  {
    mitk::Image::Pointer image =
      dynamic_cast<mitk::Image*>(mitk::IOUtil::Load(GetTestDataFilePath("Multilabel/LabelSetTestInitializeImage.nrrd"))[0].GetPointer());
    m_LabelSetImage->InitializeByLabeledImage(image);

    CPPUNIT_ASSERT_MESSAGE("Image - number of labels is not 6", m_LabelSetImage->GetNumberOfLabels() == 6);
    // 2ndMin because of the exterior label = 0
    CPPUNIT_ASSERT_MESSAGE("Labels with value 1 and 3 was not remove from the image",
                           m_LabelSetImage->GetStatistics()->GetScalarValue2ndMin() == 1);
    CPPUNIT_ASSERT_MESSAGE("Label with value 7 was not remove from the image",
                           m_LabelSetImage->GetStatistics()->GetScalarValueMax() == 7);

    CPPUNIT_ASSERT_MESSAGE("Label with ID 3 does not exists after initialization",
                           m_LabelSetImage->ExistLabel(3) == true);
    CPPUNIT_ASSERT_MESSAGE("Label with ID 7 does not exists after initialization",
                           m_LabelSetImage->ExistLabel(7) == true);

    std::vector<mitk::Label::PixelType> labelsToBeRemoved;
    labelsToBeRemoved.push_back(1);
    labelsToBeRemoved.push_back(3);
    labelsToBeRemoved.push_back(7);
    m_LabelSetImage->RemoveLabels(labelsToBeRemoved);

    CPPUNIT_ASSERT_MESSAGE("Wrong number of labels after some have been removed",
                           m_LabelSetImage->GetNumberOfLabels() == 3);
    // Values within the image are 0, 1, 3, 5, 6, 7 - New Min/Max value should be 5 / 6
    // 2ndMin because of the exterior label = 0
    CPPUNIT_ASSERT_MESSAGE("Labels with value 1 and 3 was not remove from the image",
                           m_LabelSetImage->GetStatistics()->GetScalarValue2ndMin() == 5);
    CPPUNIT_ASSERT_MESSAGE("Label with value 7 was not remove from the image",
                           m_LabelSetImage->GetStatistics()->GetScalarValueMax() == 6);
  }
Exemplo n.º 2
0
 void TestInitializeByLabeledImage()
 {
   mitk::Image::Pointer image =
     dynamic_cast<mitk::Image*>(mitk::IOUtil::Load(GetTestDataFilePath("Multilabel/LabelSetTestInitializeImage.nrrd"))[0].GetPointer());
   m_LabelSetImage->InitializeByLabeledImage(image);
   CPPUNIT_ASSERT_MESSAGE("Image - number of labels is not 6", m_LabelSetImage->GetNumberOfLabels() == 6);
 }
Exemplo n.º 3
0
  void TestMergeLabel()
  {
    mitk::Image::Pointer image = dynamic_cast<mitk::Image*>(mitk::IOUtil::Load(GetTestDataFilePath("Multilabel/LabelSetTestInitializeImage.nrrd"))[0].GetPointer());
    m_LabelSetImage = 0;
    m_LabelSetImage = mitk::LabelSetImage::New();
    m_LabelSetImage->InitializeByLabeledImage(image);

    CPPUNIT_ASSERT_MESSAGE("Image - number of labels is not 6", m_LabelSetImage->GetNumberOfLabels() == 6);

    // 2ndMin because of the exterior label = 0
    CPPUNIT_ASSERT_MESSAGE("Wrong MIN value", m_LabelSetImage->GetStatistics()->GetScalarValueMin() == 0);
    CPPUNIT_ASSERT_MESSAGE("Wrong MAX value", m_LabelSetImage->GetStatistics()->GetScalarValueMax() == 7);

    m_LabelSetImage->GetActiveLabelSet()->SetActiveLabel(6);
    // Merge label 7 with label 0. Result should be that label 7 is not present any more
    m_LabelSetImage->MergeLabel(6, 7);
    CPPUNIT_ASSERT_MESSAGE("Label with value 7 was not remove from the image", m_LabelSetImage->GetStatistics()->GetScalarValueMax() == 6);
    m_LabelSetImage->GetStatistics()->GetScalarValue2ndMax();

    // Count all pixels with value 7 = 823
    // Count all pixels with value 6 = 507
    // Check if merge label has 507 + 823 = 1330 pixels
    CPPUNIT_ASSERT_MESSAGE("Label with value 7 was not remove from the image", m_LabelSetImage->GetStatistics()->GetCountOfMaxValuedVoxels() == 1330);
  }