Пример #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);
  }
Пример #2
0
  void TestExistsLabel()
  {
    mitk::Label::Pointer label = mitk::Label::New();
    label->SetName("Label2");
    mitk::Label::PixelType value = 200;
    label->SetValue(value);

    m_LabelSetImage->AddLayer();
    m_LabelSetImage->GetLabelSet(1)->AddLabel(label);
    m_LabelSetImage->SetActiveLayer(0);
    CPPUNIT_ASSERT_MESSAGE("Existing label was not found", m_LabelSetImage->ExistLabel(value) == true);

    CPPUNIT_ASSERT_MESSAGE("Non existing label was found", m_LabelSetImage->ExistLabel(10000) == false);
  }