Skip to content
Snippets Groups Projects
Commit e1b2b1e5 authored by Cédric Traizet's avatar Cédric Traizet
Browse files

ENH : LabelImageSmallRegionMergingFilter is now a ProcessObject instead of a ImageToImageFilter

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