diff --git a/Modules/Applications/AppSegmentation/app/otbSmallRegionsMerging.cxx b/Modules/Applications/AppSegmentation/app/otbSmallRegionsMerging.cxx index d7391db9eebccb18c06715bed2ebd0375d58e8d5..12b73e6beb6b7d3713718712bd081bbbf6ddebb3 100644 --- a/Modules/Applications/AppSegmentation/app/otbSmallRegionsMerging.cxx +++ b/Modules/Applications/AppSegmentation/app/otbSmallRegionsMerging.cxx @@ -128,20 +128,19 @@ private: // Convert Map to Unordered map - auto labelPopulationMap = labelStatsFilter->GetLabelPopulationMap(); + auto labelPopulationMap = labelStatsFilter->GetLabelPopulationMap(); std::unordered_map< unsigned int,double> labelPopulation; - for (population : labelPopulationMap) + for (auto population : labelPopulationMap) { labelPopulation[population.first]=population.second; } - auto meanValueMap = labelStatsFilter->GetMeanValueMap(); + auto meanValueMap = labelStatsFilter->GetMeanValueMap(); std::unordered_map< unsigned int, itk::VariableLengthVector<double> > meanValues; - for (mean : meanValueMap) + for (const auto & mean : meanValueMap) { meanValues[mean.first] = mean.second; } - // Compute the LUT from the original label image to the merged output label image. auto regionMergingFilter = LabelImageSmallRegionMergingFilterType::New(); regionMergingFilter->SetInput( labelIn ); @@ -156,15 +155,14 @@ private: // Relabelling using the LUT auto changeLabelFilter = ChangeLabelImageFilterType::New(); changeLabelFilter->SetInput(labelIn); - auto LUT = regionMergingFilter->GetLUT(); - - for(unsigned int i = 0; i<LUT.size(); ++i) - { - if(i!=LUT[i]) - { - changeLabelFilter->SetChange(i,LUT[i]); - } - } + + const auto & LUT = regionMergingFilter->GetLUT(); + for (auto label : LUT) + { + if (label.first != label.second) + changeLabelFilter->SetChange(label.first, label.second); + } + SetParameterOutputImage("out", changeLabelFilter->GetOutput()); RegisterPipeline(); clock_t toc = clock(); diff --git a/Modules/Segmentation/Conversion/include/otbLabelImageSmallRegionMergingFilter.h b/Modules/Segmentation/Conversion/include/otbLabelImageSmallRegionMergingFilter.h index 15a91b8785ca35203643437015b7974deaf2d9f1..c0d1f5887ec89708c50e247b830edd984e4c65e8 100644 --- a/Modules/Segmentation/Conversion/include/otbLabelImageSmallRegionMergingFilter.h +++ b/Modules/Segmentation/Conversion/include/otbLabelImageSmallRegionMergingFilter.h @@ -81,7 +81,7 @@ public: typedef std::unordered_map<InputLabelType , RealVectorPixelType > LabelStatisticType; typedef std::unordered_map<InputLabelType , double> LabelPopulationType; - typedef std::unordered_map<InputLabelType , InputLabelType> LUTType; + typedef std::unordered_map<InputLabelType , InputLabelType> LUTType; /** Set/Get size of segments to be merged */ itkGetMacro(Size , unsigned int); @@ -93,7 +93,7 @@ public: m_LabelPopulation = labelPopulation; // Initialize m_CorrespondingMap to the identity (i.e. m[label] = label) - for (label : m_LabelPopulation) + for (auto label : m_LabelPopulation) { m_LUT[label.first] = label.first; }