| 206 | }; |
| 207 | |
| 208 | mitk::Image::Pointer loadMaskImage(std::string filepath, std::string labelName = "") |
| 209 | { |
| 210 | auto maskRaw = mitk::IOUtil::Load(filepath).front(); |
| 211 | |
| 212 | if (auto maskImage = dynamic_cast<mitk::Image*>(maskRaw.GetPointer())) |
| 213 | return maskImage; |
| 214 | |
| 215 | if (auto maskMultiLabelImage = dynamic_cast<mitk::MultiLabelSegmentation*>(maskRaw.GetPointer())) |
| 216 | { |
| 217 | if (maskMultiLabelImage->GetTotalNumberOfLabels() == 1) |
| 218 | return mitk::CreateLabelMask(maskMultiLabelImage, maskMultiLabelImage->GetAllLabelValues().front()); |
| 219 | |
| 220 | if (labelName.empty()) |
| 221 | { |
| 222 | MITK_INFO << "Selected mask has multiple labels. Using first one. If you want a certain label, please specify via the --movingMaskLabel / --targetMaskLabel argument."; |
| 223 | return mitk::CreateLabelMask(maskMultiLabelImage, maskMultiLabelImage->GetAllLabelValues().front()); |
| 224 | } |
| 225 | |
| 226 | mitk::MultiLabelSegmentation::LabelValueVectorType labelValues; |
| 227 | for (mitk::MultiLabelSegmentation::GroupIndexType groupIndex = 0; groupIndex < maskMultiLabelImage->GetNumberOfGroups(); ++groupIndex) |
| 228 | { |
| 229 | auto groupLabels = maskMultiLabelImage->GetLabelValuesByName(groupIndex, labelName); |
| 230 | labelValues.insert(labelValues.end(), groupLabels.begin(), groupLabels.end()); |
| 231 | } |
| 232 | |
| 233 | if (labelValues.size() == 0) |
| 234 | { |
| 235 | MITK_ERROR << "No label '" << labelName << "' found for the segmentation " << filepath; |
| 236 | return nullptr; |
| 237 | } |
| 238 | if (labelValues.size() > 1) |
| 239 | { |
| 240 | MITK_ERROR << "Multiple labels called '" << labelName << "' found for the segmentation " << filepath; |
| 241 | return nullptr; |
| 242 | } |
| 243 | |
| 244 | return mitk::CreateLabelMask(maskMultiLabelImage, labelValues.front()); |
| 245 | } |
| 246 | |
| 247 | MITK_ERROR << "Selected image mask is neither an image nor a MultiLabelSegmentation: " << filepath; |
| 248 | return nullptr; |
| 249 | } |
| 250 | |
| 251 | template <typename TValueType> |
| 252 | map::core::MetaPropertyBase::Pointer |
no test coverage detected