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

ENH : Code review

No related merge requests found
Showing with 18 additions and 11 deletions
+18 -11
...@@ -63,7 +63,7 @@ private: ...@@ -63,7 +63,7 @@ private:
{ {
SetName("SmallRegionsMerging"); SetName("SmallRegionsMerging");
SetDescription("This application merges small regions of a segmentation " SetDescription("This application merges small regions of a segmentation "
"result to connected region."); "result.");
SetDocName("Small Region Merging"); SetDocName("Small Region Merging");
SetDocLongDescription("Given a segmentation result and the original image," SetDocLongDescription("Given a segmentation result and the original image,"
...@@ -173,7 +173,7 @@ private: ...@@ -173,7 +173,7 @@ private:
const auto & LUT = regionMergingFilter->GetLUT(); const auto & LUT = regionMergingFilter->GetLUT();
for (auto label : LUT) for (auto const & label : LUT)
{ {
if (label.first != label.second) if (label.first != label.second)
{ {
......
...@@ -69,10 +69,11 @@ PersistentLabelImageSmallRegionMergingFilter< TInputLabelImage > ...@@ -69,10 +69,11 @@ PersistentLabelImageSmallRegionMergingFilter< TInputLabelImage >
double proximity = itk::NumericTraits<double>::max(); double proximity = itk::NumericTraits<double>::max();
InputLabelType label = neighbours.first; InputLabelType label = neighbours.first;
InputLabelType closestNeighbour = label; InputLabelType closestNeighbour = label;
auto const& statsLabel = m_LabelStatistic[ label ];
for (auto neighbour : neighbours.second) for (auto neighbour : neighbours.second)
{ {
auto statsLabel = m_LabelStatistic[ label ]; auto const & statsNeighbour = m_LabelStatistic[ neighbour ];
auto statsNeighbour = m_LabelStatistic[ neighbour ];
assert( statsLabel.Size() == statsNeighbour.Size() ); assert( statsLabel.Size() == statsNeighbour.Size() );
double distance = (statsLabel - statsNeighbour).GetSquaredNorm(); double distance = (statsLabel - statsNeighbour).GetSquaredNorm();
...@@ -106,16 +107,22 @@ PersistentLabelImageSmallRegionMergingFilter< TInputLabelImage > ...@@ -106,16 +107,22 @@ PersistentLabelImageSmallRegionMergingFilter< TInputLabelImage >
// Update statistics : for each newly merged segments, sum the population, and // Update statistics : for each newly merged segments, sum the population, and
// recompute the mean. // recompute the mean.
for (auto label : m_LUT) for (auto const & label : m_LUT)
{ {
if((m_LabelPopulation[label.first]!=0) && (label.second != label.first)) if ((label.second != label.first) && (m_LabelPopulation[label.first]!=0))
{ {
// Cache values to reduce number of lookups
auto const & populationFirst = m_LabelPopulation[label.first];
auto const & populationSecond = m_LabelPopulation[label.second];
auto const & statisticFirst = m_LabelStatistic[label.first];
auto const & statisticSecond = m_LabelStatistic[label.second];
m_LabelStatistic[ label.second ] = m_LabelStatistic[ label.second ] =
( m_LabelStatistic[label.first]*m_LabelPopulation[label.first] ( (statisticFirst * populationFirst)
+ m_LabelStatistic[label.second]*m_LabelPopulation[label.second] ) + (statisticSecond * populationSecond) )
/ (m_LabelPopulation[label.first]+m_LabelPopulation[label.second]); / (populationFirst + populationSecond);
m_LabelPopulation[ label.second ] += m_LabelPopulation[ label.first ] ; m_LabelPopulation[ label.second ] += populationFirst;
// Do not use this label anymore // Do not use this label anymore
m_LabelPopulation[ label.first ] = 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