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

Method InitializeByLabeledImageProcessing

Modules/Multilabel/src/mitkLabelSetImage.cpp:1177–1246  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1175
1176template <typename MultiLabelSegmentationType, typename ImageType>
1177void mitk::MultiLabelSegmentation::InitializeByLabeledImageProcessing(MultiLabelSegmentationType *labelSetImage, const ImageType *image)
1178{
1179 typedef itk::ImageRegionConstIteratorWithIndex<ImageType> SourceIteratorType;
1180 typedef itk::ImageRegionIterator<MultiLabelSegmentationType> TargetIteratorType;
1181
1182 TargetIteratorType targetIter(labelSetImage, labelSetImage->GetRequestedRegion());
1183 targetIter.GoToBegin();
1184
1185 SourceIteratorType sourceIter(image, image->GetRequestedRegion());
1186 sourceIter.GoToBegin();
1187
1188 mitk::MultiLabelSegmentation::LabelValueType maxLabelValue = 0;
1189 std::vector<mitk::Label*> addedLabels;
1190
1191 while (!sourceIter.IsAtEnd())
1192 {
1193 const auto originalSourceValue = sourceIter.Get();
1194 const auto sourceValue = static_cast<LabelValueType>(originalSourceValue);
1195
1196 if (originalSourceValue > mitk::Label::MAX_LABEL_VALUE)
1197 {
1198 mitkThrow() << "Cannot initialize MultiLabelSegmentation by image. Image contains a pixel "
1199 << "value that exceeds the label value range.Invalid pixel value : "
1200 << originalSourceValue;
1201 }
1202
1203 targetIter.Set(sourceValue);
1204
1205 if (MultiLabelSegmentation::UNLABELED_VALUE!=sourceValue && !this->ExistLabel(sourceValue))
1206 {
1207 if (this->GetTotalNumberOfLabels() >= mitk::Label::MAX_LABEL_VALUE)
1208 {
1209 mitkThrow() << "Cannot initialize MultiLabelSegmentation by image. "
1210 << "Image contains to many labels.";
1211 }
1212
1213 double rgba[4];
1214 this->GetLookupTable()->GetTableValue(sourceValue, rgba);
1215
1216 mitk::Color color;
1217 color.SetRed(rgba[0]);
1218 color.SetGreen(rgba[1]);
1219 color.SetBlue(rgba[2]);
1220
1221 auto label = mitk::Label::New();
1222 label->SetColor(color);
1223 label->SetOpacity(rgba[3]);
1224 label->SetValue(sourceValue);
1225
1226 addedLabels.push_back(label); // this is used for faster access in next loop.
1227 //we need to do the adding here already to ensure correct checking and correction of labels
1228 this->AddLabel(label,0,false);
1229
1230 maxLabelValue = std::max(maxLabelValue, sourceValue);
1231 }
1232
1233 ++sourceIter;
1234 ++targetIter;

Callers

nothing calls this directly

Calls 15

ExistLabelMethod · 0.95
AddLabelMethod · 0.95
GetRequiredDigitsFunction · 0.85
NewFunction · 0.50
GoToBeginMethod · 0.45
GetMethod · 0.45
SetMethod · 0.45
GetTableValueMethod · 0.45
GetLookupTableMethod · 0.45
SetColorMethod · 0.45
SetOpacityMethod · 0.45

Tested by

no test coverage detected