MCPcopy Create free account
hub / github.com/MITK/MITK / CreateFilteredGroupImage

Method CreateFilteredGroupImage

Modules/Multilabel/src/mitkLabelSetImageConverter.cpp:412–455  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

410}
411
412mitk::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
458std::pair<mitk::Image::Pointer, mitk::IDToLabelClassNameMapType> mitk::CreateLabelClassMap(const MultiLabelSegmentation* segmentation, MultiLabelSegmentation::GroupIndexType groupID, const MultiLabelSegmentation::LabelValueVectorType& selectedLabels)

Callers

nothing calls this directly

Calls 15

ExistGroupMethod · 0.80
GetDimensionsMethod · 0.80
SetTimeGeometryMethod · 0.80
GetLabelValuesByGroupMethod · 0.80
GetPointerMethod · 0.80
GetConstLabelsByValueMethod · 0.80
ClearImageBufferFunction · 0.70
NewFunction · 0.50
GetPixelTypeFunction · 0.50
InitializeMethod · 0.45
GetDimensionMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected