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

Function loadMaskImage

Modules/MatchPointRegistration/cmdapps/MatchImage.cpp:208–249  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

206};
207
208mitk::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
251template <typename TValueType>
252map::core::MetaPropertyBase::Pointer

Callers 1

mainFunction · 0.85

Calls 11

LoadFunction · 0.85
frontMethod · 0.80
GetPointerMethod · 0.80
GetAllLabelValuesMethod · 0.80
GetNumberOfGroupsMethod · 0.80
GetLabelValuesByNameMethod · 0.80
emptyMethod · 0.45
endMethod · 0.45
beginMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected