Commit d436514b authored by Cédric Traizet's avatar Cédric Traizet
Browse files

ENH : replaced vector by unordered maps

No related merge requests found
Showing with 21 additions and 17 deletions
+21 -17
...@@ -125,20 +125,22 @@ private: ...@@ -125,20 +125,22 @@ private:
labelStatsFilter->SetInputLabelImage(labelIn); labelStatsFilter->SetInputLabelImage(labelIn);
AddProcess(labelStatsFilter->GetStreamer() , "Computing stats on input image ..."); AddProcess(labelStatsFilter->GetStreamer() , "Computing stats on input image ...");
labelStatsFilter->Update(); labelStatsFilter->Update();
// Convert Map to Vector // Convert Map to Unordered map
auto labelPopulationMap = labelStatsFilter->GetLabelPopulationMap(); auto labelPopulationMap = labelStatsFilter->GetLabelPopulationMap();
std::vector<double> labelPopulation; std::unordered_map< unsigned int,double> labelPopulation;
for (unsigned int i =0; i <= labelPopulationMap.rbegin()->first; i++) for (population : labelPopulationMap)
{ {
labelPopulation.push_back(labelPopulationMap[i]); labelPopulation[population.first]=population.second;
} }
auto meanValueMap = labelStatsFilter->GetMeanValueMap(); auto meanValueMap = labelStatsFilter->GetMeanValueMap();
std::vector<itk::VariableLengthVector<double> > meanValues; std::unordered_map< unsigned int, itk::VariableLengthVector<double> > meanValues;
for (unsigned int i =0; i <= meanValueMap.rbegin()->first; i++) for (mean : meanValueMap)
{ {
meanValues.push_back(meanValueMap[i]); meanValues[mean.first] = mean.second;
} }
// Compute the LUT from the original label image to the merged output label image. // Compute the LUT from the original label image to the merged output label image.
auto regionMergingFilter = LabelImageSmallRegionMergingFilterType::New(); auto regionMergingFilter = LabelImageSmallRegionMergingFilterType::New();
......
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
#include "otbPersistentImageFilter.h" #include "otbPersistentImageFilter.h"
#include "otbPersistentFilterStreamingDecorator.h" #include "otbPersistentFilterStreamingDecorator.h"
#include <unordered_map>
namespace otb namespace otb
{ {
...@@ -76,9 +78,10 @@ public: ...@@ -76,9 +78,10 @@ public:
typedef itk::VariableLengthVector<double> RealVectorPixelType; typedef itk::VariableLengthVector<double> RealVectorPixelType;
typedef std::map<InputLabelType, std::set<InputLabelType> > NeigboursMapType; typedef std::map<InputLabelType, std::set<InputLabelType> > NeigboursMapType;
typedef std::vector<RealVectorPixelType > LabelStatisticType;
typedef std::vector<double> LabelPopulationType; typedef std::unordered_map<InputLabelType , RealVectorPixelType > LabelStatisticType;
typedef std::vector<InputLabelType> LUTType; typedef std::unordered_map<InputLabelType , double> LabelPopulationType;
typedef std::unordered_map<InputLabelType , InputLabelType> LUTType;
/** Set/Get size of segments to be merged */ /** Set/Get size of segments to be merged */
itkGetMacro(Size , unsigned int); itkGetMacro(Size , unsigned int);
...@@ -88,12 +91,12 @@ public: ...@@ -88,12 +91,12 @@ public:
void SetLabelPopulation( LabelPopulationType const & labelPopulation ) void SetLabelPopulation( LabelPopulationType const & labelPopulation )
{ {
m_LabelPopulation = labelPopulation; m_LabelPopulation = labelPopulation;
// Initialize m_CorrespondingMap to the identity (i.e. m[label] = label) // Initialize m_CorrespondingMap to the identity (i.e. m[label] = label)
m_LUT.resize( labelPopulation.size() ); for (label : m_LabelPopulation)
for (unsigned int i =0; i <labelPopulation.size(); i++)
{ {
m_LUT[ i ] = i; m_LUT[label.first] = label.first;
} }
} }
/** Get the Label population */ /** Get the Label population */
......
...@@ -210,7 +210,6 @@ PersistentLabelImageSmallRegionMergingFilter< TInputLabelImage > ...@@ -210,7 +210,6 @@ PersistentLabelImageSmallRegionMergingFilter< TInputLabelImage >
{ {
assert( !itN.IsAtEnd() ); assert( !itN.IsAtEnd() );
int currentLabel = FindCorrespondingLabel(it.Get()); int currentLabel = FindCorrespondingLabel(it.Get());
if ( m_LabelPopulation[currentLabel] == m_Size ) if ( m_LabelPopulation[currentLabel] == m_Size )
{ {
for (auto ci = itN.Begin() ; !ci.IsAtEnd(); ci++) for (auto ci = itN.Begin() ; !ci.IsAtEnd(); ci++)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment