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

Method CreateLabelMask

Modules/Multilabel/src/mitkLabelSetImageConverter.cpp:376–410  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

374}
375
376mitk::Image::Pointer mitk::CreateLabelMask(const MultiLabelSegmentation* segmentation, MultiLabelSegmentation::LabelValueType labelValue, bool createBinaryMap)
377{
378 if (nullptr==segmentation)
379 mitkThrow() << "Error, cannot create label mask. Passed segmentation is nullptr.";
380
381 if (!segmentation->ExistLabel(labelValue))
382 mitkThrow() << "Error, cannot create label mask. Label ID is invalid. Invalid ID: " << labelValue;
383
384 auto mask = mitk::Image::New();
385
386 // mask->Initialize(segmentation) does not work here if this label set image has a single slice,
387 // since the mask would be automatically flattened to a 2-d image, whereas we expect the
388 // original dimension of this label set image. Hence, initialize the mask more explicitly:
389 mask->Initialize(MultiLabelSegmentation::GetPixelType(), segmentation->GetDimension(), segmentation->GetDimensions().data());
390 mask->SetTimeGeometry(segmentation->GetTimeGeometry()->Clone());
391
392 ClearImageBuffer(mask);
393
394 auto destinationLabel = segmentation->GetLabel(labelValue)->Clone();
395 if (createBinaryMap) destinationLabel->SetValue(1);
396
397 const auto groupID = segmentation->GetGroupIndexOfLabel(labelValue);
398 const auto groupImage = segmentation->GetGroupImage(groupID);
399
400 TransferLabelContent(groupImage,
401 mask.GetPointer(),
402 { destinationLabel },
403 MultiLabelSegmentation::UNLABELED_VALUE,
404 MultiLabelSegmentation::UNLABELED_VALUE, false,
405 { { labelValue, destinationLabel->GetValue()} },
406 MultiLabelSegmentation::MergeStyle::Replace,
407 MultiLabelSegmentation::OverwriteStyle::IgnoreLocks);
408
409 return mask;
410}
411
412mitk::Image::Pointer mitk::CreateFilteredGroupImage(const MultiLabelSegmentation* segmentation, MultiLabelSegmentation::GroupIndexType groupID, const MultiLabelSegmentation::LabelValueVectorType& selectedLabels)
413{

Callers

nothing calls this directly

Calls 15

ExistLabelMethod · 0.80
GetDimensionsMethod · 0.80
SetTimeGeometryMethod · 0.80
GetGroupIndexOfLabelMethod · 0.80
GetPointerMethod · 0.80
ClearImageBufferFunction · 0.70
NewFunction · 0.50
GetPixelTypeFunction · 0.50
InitializeMethod · 0.45
GetDimensionMethod · 0.45
dataMethod · 0.45
CloneMethod · 0.45

Tested by

no test coverage detected