| 127 | } |
| 128 | |
| 129 | std::vector<BaseData::Pointer> LegacyLabelSetImageIO::DoRead() |
| 130 | { |
| 131 | itk::NrrdImageIO::Pointer nrrdImageIO = itk::NrrdImageIO::New(); |
| 132 | |
| 133 | std::vector<BaseData::Pointer> result; |
| 134 | |
| 135 | auto rawimage = ItkImageIO::LoadRawMitkImageFromImageIO(nrrdImageIO, this->GetLocalFileName()); |
| 136 | |
| 137 | const itk::MetaDataDictionary& dictionary = nrrdImageIO->GetMetaDataDictionary(); |
| 138 | |
| 139 | std::vector<Image::Pointer> groupImages = { rawimage }; |
| 140 | if (rawimage->GetChannelDescriptor().GetPixelType().GetPixelType() == itk::IOPixelEnum::VECTOR) |
| 141 | { |
| 142 | groupImages = SplitVectorImage(rawimage); |
| 143 | } |
| 144 | |
| 145 | auto labelsets = ExtractLabelSetsFromMetaData(dictionary); |
| 146 | |
| 147 | if (labelsets.size() != groupImages.size()) |
| 148 | { |
| 149 | mitkThrow() << "Loaded data is in an invalid state. Number of extracted layer images and labels sets does not match. Found layer images: " << groupImages.size() << "; found labelsets: " << labelsets.size(); |
| 150 | } |
| 151 | |
| 152 | auto props = ItkImageIO::ExtractMetaDataAsPropertyList(nrrdImageIO->GetMetaDataDictionary(), this->GetMimeType()->GetName(), this->m_DefaultMetaDataKeys); |
| 153 | |
| 154 | const Options userOptions = this->GetOptions(); |
| 155 | |
| 156 | const auto multiLayerStrategy = userOptions.find(OPTION_NAME_MULTI_LAYER)->second.ToString(); |
| 157 | |
| 158 | if (multiLayerStrategy == OPTION_NAME_MULTI_LAYER_SPLIT) |
| 159 | { //just split layers in different multi label images |
| 160 | auto labelSetIterator = labelsets.begin(); |
| 161 | for (auto image : groupImages) |
| 162 | { |
| 163 | auto output = ConvertImageToLabelSetImage(image); |
| 164 | output->ReplaceGroupLabels(0, *labelSetIterator); |
| 165 | |
| 166 | //meta data handling |
| 167 | for (auto& [name, prop] : *(props->GetMap())) |
| 168 | { |
| 169 | output->SetProperty(name, prop->Clone()); //need to clone to avoid that all outputs pointing to the same prop instances. |
| 170 | } |
| 171 | // Handle UID |
| 172 | //Remark if we split the legacy label set into distinct layer images, the outputs should have new IDs. So we don't get the old one. |
| 173 | |
| 174 | result.push_back(output.GetPointer()); |
| 175 | labelSetIterator++; |
| 176 | } |
| 177 | } |
| 178 | else |
| 179 | { //Avoid label id collision. |
| 180 | MultiLabelSegmentation::LabelValueType maxValue = MultiLabelSegmentation::UNLABELED_VALUE; |
| 181 | auto imageIterator = groupImages.begin(); |
| 182 | std::vector<mitk::MultiLabelSegmentation::LabelVectorType> adaptedLabelSets; |
| 183 | |
| 184 | for (auto labelset : labelsets) |
| 185 | { |
| 186 | const auto setValues = MultiLabelSegmentation::ExtractLabelValuesFromLabelVector(labelset); |
nothing calls this directly
no test coverage detected