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

ENH : LabelImageSmallRegionMergingFilter is now a ProcessObject instead of a ImageToImageFilter

parent 77ff60fb
......@@ -143,7 +143,7 @@ private:
// Compute the LUT from the original label image to the merged output label image.
auto regionMergingFilter = LabelImageSmallRegionMergingFilterType::New();
regionMergingFilter->SetInput( labelIn );
regionMergingFilter->SetInputLabelImage( labelIn );
regionMergingFilter->SetLabelPopulation( labelPopulation );
regionMergingFilter->SetLabelStatistic( meanValues );
......
......@@ -25,6 +25,7 @@
#include "otbPersistentFilterStreamingDecorator.h"
#include <unordered_map>
#include <unordered_set>
namespace otb
{
......@@ -177,12 +178,12 @@ private:
*/
template <class TInputLabelImage>
class ITK_EXPORT LabelImageSmallRegionMergingFilter
: public itk::ImageToImageFilter<TInputLabelImage, TInputLabelImage>
: public itk::ProcessObject
{
public:
/** Standard Self typedef */
typedef LabelImageSmallRegionMergingFilter Self;
typedef itk::ImageToImageFilter<TInputLabelImage, TInputLabelImage> Superclass;
typedef itk::ProcessObject Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
......@@ -190,7 +191,7 @@ public:
itkNewMacro(Self);
/** Creation through object factory macro */
itkTypeMacro(LabelImageSmallRegionMergingFilter, itk::ImageToImageFilter);
itkTypeMacro(LabelImageSmallRegionMergingFilter, itk::ProcessObject);
// Small region merging filter typedefs
typedef PersistentLabelImageSmallRegionMergingFilter< TInputLabelImage > PersistentLabelImageSmallRegionMergingFilterType;
......@@ -205,6 +206,12 @@ public:
itkGetMacro(MinSize , unsigned int);
itkSetMacro(MinSize , unsigned int);
/** Set the Label population map */
void SetInputLabelImage( const TInputLabelImage * labelImage )
{
m_SmallRegionMergingFilter->GetFilter()->SetInput( labelImage );
}
/** Set the Label population map */
void SetLabelPopulation( LabelPopulationType const & labelPopulation )
{
......@@ -235,6 +242,8 @@ public:
return m_SmallRegionMergingFilter->GetFilter()->GetLUT();
}
void Update(void) override;
protected:
/** Constructor */
LabelImageSmallRegionMergingFilter();
......
......@@ -23,11 +23,9 @@
#define otbLabelImageSmallRegionMergingFilter_hxx
#include "otbLabelImageSmallRegionMergingFilter.h"
#include "itkImageConstIterator.h"
#include "itkConstShapedNeighborhoodIterator.h"
#include "itkProgressReporter.h"
#include <time.h>
namespace otb
{
template <class TInputLabelImage >
......@@ -64,7 +62,7 @@ PersistentLabelImageSmallRegionMergingFilter< TInputLabelImage >
// to the euclidian distance between the corresponding m_labelStatistic elements.
for (auto const & neighbours : neighboursMap)
{
double proximity = std::numeric_limits<double>::max();
double proximity = itk::NumericTraits<double>::max();
InputLabelType label = neighbours.first;
InputLabelType closestNeighbour = label;
for (auto const & neighbour : neighbours.second)
......@@ -72,11 +70,8 @@ PersistentLabelImageSmallRegionMergingFilter< TInputLabelImage >
auto statsLabel = m_LabelStatistic[ label ];
auto statsNeighbour = m_LabelStatistic[ neighbour ];
assert( statsLabel.Size() == statsNeighbour.Size() );
double distance = 0;
for (unsigned int i = 0 ; i < statsLabel.Size(); i++)
{
distance += (statsLabel[i] - statsNeighbour[i]) * (statsLabel[i] - statsNeighbour[i]);
}
double distance = (statsLabel - statsNeighbour).GetSquaredNorm();
if (distance < proximity)
{
proximity = distance;
......@@ -203,7 +198,6 @@ PersistentLabelImageSmallRegionMergingFilter< TInputLabelImage >
assert( !itN.IsAtEnd() );
int currentLabel = m_LUT[ it.Get() ];
if ( m_LabelPopulation[currentLabel] == m_Size )
{
for (auto ci = itN.Begin() ; !ci.IsAtEnd(); ci++)
......@@ -231,14 +225,20 @@ LabelImageSmallRegionMergingFilter< TInputLabelImage >
m_SmallRegionMergingFilter = LabelImageSmallRegionMergingFilterType::New();
}
template <class TInputLabelImage>
void
LabelImageSmallRegionMergingFilter<TInputLabelImage>
::Update(void)
{
this->GenerateData();
}
template <class TInputLabelImage >
void
LabelImageSmallRegionMergingFilter< TInputLabelImage >
::GenerateData()
{
this->SetProgress(0.0);
auto labelImage = this->GetInput();
m_SmallRegionMergingFilter->GetFilter()->SetInput( labelImage );
// Update the filter for all sizes.
for (unsigned int size = 1; size < m_MinSize; size++)
......
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