| 374 | } |
| 375 | |
| 376 | mitk::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 | |
| 412 | mitk::Image::Pointer mitk::CreateFilteredGroupImage(const MultiLabelSegmentation* segmentation, MultiLabelSegmentation::GroupIndexType groupID, const MultiLabelSegmentation::LabelValueVectorType& selectedLabels) |
| 413 | { |
nothing calls this directly
no test coverage detected