| 410 | } |
| 411 | |
| 412 | mitk::Image::Pointer mitk::CreateFilteredGroupImage(const MultiLabelSegmentation* segmentation, MultiLabelSegmentation::GroupIndexType groupID, const MultiLabelSegmentation::LabelValueVectorType& selectedLabels) |
| 413 | { |
| 414 | if (nullptr == segmentation) mitkThrow() << "Error, cannot create label class map. Passed segmentation is nullptr."; |
| 415 | if (!segmentation->ExistGroup(groupID)) mitkThrow() << "Error, cannot create label class map. GroupID is invalid. Invalid ID: " << groupID; |
| 416 | |
| 417 | auto resultImage = mitk::Image::New(); |
| 418 | |
| 419 | // map->Initialize(segmentation) does not work here if this label set image has a single slice, |
| 420 | // since the map would be automatically flattened to a 2-d image, whereas we expect the |
| 421 | // original dimension of this label set image. Hence, initialize the map more explicitly: |
| 422 | resultImage->Initialize(MultiLabelSegmentation::GetPixelType(), segmentation->GetDimension(), segmentation->GetDimensions().data()); |
| 423 | resultImage->SetTimeGeometry(segmentation->GetTimeGeometry()->Clone()); |
| 424 | |
| 425 | ClearImageBuffer(resultImage); |
| 426 | |
| 427 | // get relevant labels (as intersect of groupLabels and selectedLabels |
| 428 | auto groupValues = segmentation->GetLabelValuesByGroup(groupID); |
| 429 | auto relevantDetectLambda = [&selectedLabels](MultiLabelSegmentation::LabelValueVectorType result, MultiLabelSegmentation::LabelValueType element) |
| 430 | { |
| 431 | if (std::find(selectedLabels.begin(), selectedLabels.end(), element) != selectedLabels.end()) |
| 432 | { |
| 433 | result.push_back(element); |
| 434 | } |
| 435 | return result; |
| 436 | }; |
| 437 | |
| 438 | auto relevantGroupValues = std::accumulate(groupValues.begin(), |
| 439 | groupValues.end(), |
| 440 | MultiLabelSegmentation::LabelValueVectorType(), |
| 441 | relevantDetectLambda); |
| 442 | |
| 443 | ConstLabelVector destLabels; |
| 444 | LabelValueMappingVector transferMapping; |
| 445 | |
| 446 | for (const auto& labelValue : relevantGroupValues) |
| 447 | { |
| 448 | transferMapping.emplace_back(std::make_pair(labelValue, labelValue)); |
| 449 | } |
| 450 | |
| 451 | TransferLabelContent(segmentation->GetGroupImage(groupID), resultImage.GetPointer(), |
| 452 | segmentation->GetConstLabelsByValue(relevantGroupValues), MultiLabelSegmentation::UNLABELED_VALUE, MultiLabelSegmentation::UNLABELED_VALUE, false, transferMapping, MultiLabelSegmentation::MergeStyle::Replace, MultiLabelSegmentation::OverwriteStyle::IgnoreLocks); |
| 453 | |
| 454 | return resultImage; |
| 455 | } |
| 456 | |
| 457 | |
| 458 | std::pair<mitk::Image::Pointer, mitk::IDToLabelClassNameMapType> mitk::CreateLabelClassMap(const MultiLabelSegmentation* segmentation, MultiLabelSegmentation::GroupIndexType groupID, const MultiLabelSegmentation::LabelValueVectorType& selectedLabels) |
nothing calls this directly
no test coverage detected