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

ENH : replaced vector by unordered maps

parent 424152d5
......@@ -125,20 +125,22 @@ private:
labelStatsFilter->SetInputLabelImage(labelIn);
AddProcess(labelStatsFilter->GetStreamer() , "Computing stats on input image ...");
labelStatsFilter->Update();
// Convert Map to Vector
// Convert Map to Unordered map
auto labelPopulationMap = labelStatsFilter->GetLabelPopulationMap();
std::vector<double> labelPopulation;
for (unsigned int i =0; i <= labelPopulationMap.rbegin()->first; i++)
std::unordered_map< unsigned int,double> labelPopulation;
for (population : labelPopulationMap)
{
labelPopulation.push_back(labelPopulationMap[i]);
labelPopulation[population.first]=population.second;
}
auto meanValueMap = labelStatsFilter->GetMeanValueMap();
std::vector<itk::VariableLengthVector<double> > meanValues;
for (unsigned int i =0; i <= meanValueMap.rbegin()->first; i++)
std::unordered_map< unsigned int, itk::VariableLengthVector<double> > meanValues;
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.
auto regionMergingFilter = LabelImageSmallRegionMergingFilterType::New();
......
......@@ -24,6 +24,8 @@
#include "otbPersistentImageFilter.h"
#include "otbPersistentFilterStreamingDecorator.h"
#include <unordered_map>
namespace otb
{
......@@ -76,9 +78,10 @@ public:
typedef itk::VariableLengthVector<double> RealVectorPixelType;
typedef std::map<InputLabelType, std::set<InputLabelType> > NeigboursMapType;
typedef std::vector<RealVectorPixelType > LabelStatisticType;
typedef std::vector<double> LabelPopulationType;
typedef std::vector<InputLabelType> LUTType;
typedef std::unordered_map<InputLabelType , RealVectorPixelType > LabelStatisticType;
typedef std::unordered_map<InputLabelType , double> LabelPopulationType;
typedef std::unordered_map<InputLabelType , InputLabelType> LUTType;
/** Set/Get size of segments to be merged */
itkGetMacro(Size , unsigned int);
......@@ -88,12 +91,12 @@ public:
void SetLabelPopulation( LabelPopulationType const & labelPopulation )
{
m_LabelPopulation = labelPopulation;
// Initialize m_CorrespondingMap to the identity (i.e. m[label] = label)
m_LUT.resize( labelPopulation.size() );
for (unsigned int i =0; i <labelPopulation.size(); i++)
for (label : m_LabelPopulation)
{
m_LUT[ i ] = i;
}
m_LUT[label.first] = label.first;
}
}
/** Get the Label population */
......
......@@ -210,7 +210,6 @@ PersistentLabelImageSmallRegionMergingFilter< TInputLabelImage >
{
assert( !itN.IsAtEnd() );
int currentLabel = FindCorrespondingLabel(it.Get());
if ( m_LabelPopulation[currentLabel] == m_Size )
{
for (auto ci = itN.Begin() ; !ci.IsAtEnd(); ci++)
......
Markdown is supported
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