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

ENH : code modernization

No related merge requests found
Showing with 17 additions and 22 deletions
+17 -22
...@@ -157,12 +157,14 @@ private: ...@@ -157,12 +157,14 @@ private:
changeLabelFilter->SetInput(labelIn); changeLabelFilter->SetInput(labelIn);
const auto & LUT = regionMergingFilter->GetLUT(); const auto & LUT = regionMergingFilter->GetLUT();
for (auto label : LUT) for (auto label : LUT)
{ {
if (label.first != label.second) if (label.first != label.second)
{
changeLabelFilter->SetChange(label.first, label.second); changeLabelFilter->SetChange(label.first, label.second);
}
} }
SetParameterOutputImage("out", changeLabelFilter->GetOutput()); SetParameterOutputImage("out", changeLabelFilter->GetOutput());
RegisterPipeline(); RegisterPipeline();
clock_t toc = clock(); clock_t toc = clock();
......
...@@ -123,12 +123,12 @@ public: ...@@ -123,12 +123,12 @@ public:
return m_LUT; return m_LUT;
} }
virtual void Reset(void); virtual void Reset(void) override;
virtual void Synthetize(void); virtual void Synthetize(void) override;
protected: protected:
/** The input requested region should be padded by a radius of 1 to use the neigbourhood iterator*/ /** The input requested region should be padded by a radius of 1 to use the neigbourhood iterator*/
void GenerateInputRequestedRegion(); void GenerateInputRequestedRegion() override;
/** Threaded Generate Data : find the neighbours of each segments of size m_Size for each tile and store them in /** Threaded Generate Data : find the neighbours of each segments of size m_Size for each tile and store them in
* an accumulator */ * an accumulator */
...@@ -248,7 +248,7 @@ protected: ...@@ -248,7 +248,7 @@ protected:
~LabelImageSmallRegionMergingFilter() override = default; ~LabelImageSmallRegionMergingFilter() override = default;
/** Generate Data method (Update LabelImageSmallRegionMergingFilterType recursively) */ /** Generate Data method (Update LabelImageSmallRegionMergingFilterType recursively) */
void GenerateData(); void GenerateData() override;
private: private:
LabelImageSmallRegionMergingFilter(const Self &) = delete; LabelImageSmallRegionMergingFilter(const Self &) = delete;
......
...@@ -99,27 +99,20 @@ PersistentLabelImageSmallRegionMergingFilter< TInputLabelImage > ...@@ -99,27 +99,20 @@ PersistentLabelImageSmallRegionMergingFilter< TInputLabelImage >
} }
// Update the LUT // Update the LUT
for(InputLabelType label = 0; label < m_LUT.size(); ++label) for (auto & label : m_LUT)
{ {
InputLabelType can = label; label.second = FindCorrespondingLabel( label.first );
while(m_LUT[can] != can)
{
can = m_LUT[can];
}
m_LUT[label] = can;
} }
// Update Statistics // Update statistics
for(InputLabelType label = 0; label < m_LUT.size(); ++label) for (auto label : m_LUT)
{ {
InputLabelType correspondingLabel = m_LUT[label]; if((m_LabelPopulation[label.first]!=0) && (label.second != label.first))
if((m_LabelPopulation[label]!=0) && (correspondingLabel != label))
{ {
m_LabelStatistic[ correspondingLabel ] = (m_LabelStatistic[correspondingLabel]*m_LabelPopulation[correspondingLabel] + m_LabelStatistic[ label.second ] = (m_LabelStatistic[label.second]*m_LabelPopulation[label.second] +
m_LabelStatistic[label]*m_LabelPopulation[label] ) / (m_LabelPopulation[label]+m_LabelPopulation[correspondingLabel]); m_LabelStatistic[label.first]*m_LabelPopulation[label.first] ) / (m_LabelPopulation[label.first]+m_LabelPopulation[label.second]);
m_LabelPopulation[ correspondingLabel ] += m_LabelPopulation[ label ] ; m_LabelPopulation[ label.second ] += m_LabelPopulation[ label.first ] ;
m_LabelPopulation[ label ] = 0; m_LabelPopulation[ label.first ] = 0;
} }
} }
} }
......
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