]> Creatis software - FrontAlgorithms.git/blobdiff - appli/CTBronchi/MoriLabelling.cxx
...
[FrontAlgorithms.git] / appli / CTBronchi / MoriLabelling.cxx
index 96575b420d5935bfa6aa8c529216b7cf3a860639..78544b5ed98b094493c71e849f4c26e09721e9bb 100644 (file)
@@ -10,6 +10,7 @@
 #include <itkImageFileReader.h>
 #include <itkImageFileWriter.h>
 #include <itkRegionOfInterestImageFilter.h>
+#include <itkMinimumMaximumImageCalculator.h>
 
 #include <fpa/Filters/BaseMarksInterface.h>
 #include <fpa/Filters/Image/SeedsFromLabelsInterface.h>
 
 // -------------------------------------------------------------------------
 const unsigned int Dim = 3;
-typedef short         TPixel;
-typedef unsigned char TLabel;
-typedef itk::Image< TPixel, Dim > TImage;
-typedef itk::Image< TLabel, Dim > TLabels;
+typedef short                                  TPixel;
+typedef unsigned char                          TLabel;
+typedef itk::NumericTraits< TPixel >::RealType TScalar;
+typedef itk::Image< TPixel, Dim >              TImage;
+typedef itk::Image< TLabel, Dim >              TLabels;
+typedef itk::Image< TScalar, Dim >             TScalarImage;
 
 /**
  */
@@ -65,6 +68,7 @@ public:
   itkGetConstMacro( MaxVertex, TVertex );
 
   fpaFilterInputMacro( InputLabels, TLabels );
+  fpaFilterInputMacro( InputVesselness, TScalarImage );
 
 public:
   TInputValue GetUpperThreshold( ) const
@@ -79,9 +83,11 @@ public:
 protected:
   MoriLabelling( )
   : Superclass( ),
-    m_LastThreshold( TInputValue( 0 ) )
+    m_LastThreshold( TInputValue( 0 ) ),
+    m_VesselnessThr( TScalar( 0.05 ) )
     {
       fpaFilterInputConfigureMacro( InputLabels, TLabels );
+      fpaFilterInputConfigureMacro( InputVesselness, TScalarImage );
       this->m_Functor = TFunctor::New( );
       this->SetPredicate( this->m_Functor );
     }
@@ -98,6 +104,12 @@ protected:
     {
       this->Superclass::_BeforeGenerateData( );
       this->m_FirstVertex = true;
+
+      typedef itk::MinimumMaximumImageCalculator< TScalarImage > _TMinMax;
+      _TMinMax::Pointer minMax = _TMinMax::New( );
+      minMax->SetImage( this->GetInputVesselness( ) );
+      minMax->Compute( );
+      this->m_MaxVesselness = ( 1.0  - this->m_VesselnessThr ) * minMax->GetMaximum( );
     }
 
   virtual void _PostComputeOutputValue( TNode& n ) override
@@ -107,13 +119,20 @@ protected:
       {
         const TImage* input = this->GetInput( );
         const TLabels* labels = this->GetInputLabels( );
+        const TScalarImage* vesselness = this->GetInputVesselness( );
         double x = input->GetPixel( n.Vertex );
         /* TODO
            double a = std::fabs( x - double( this->m_Functor->GetUpperThreshold( ) ) );
            double b = std::fabs( x - double( this->m_LastThreshold ) );
         */
-        if( labels->GetPixel( n.Vertex ) == 0 /* && b < a*/ )
-          n.Value = 0;
+        if( labels->GetPixel( n.Vertex ) == 0 )
+        {
+          if( vesselness->GetPixel( n.Vertex ) > this->m_MaxVesselness )
+            n.Value = this->GetInsideValue( );
+          else
+            n.Value = 0;
+
+        } // fi
 
         if( !( this->m_FirstVertex ) )
         {
@@ -148,6 +167,9 @@ protected:
   bool m_FirstVertex;
   TVertex m_MinVertex;
   TVertex m_MaxVertex;
+
+  TScalar m_MaxVesselness;
+  TScalar m_VesselnessThr;
 };
 
 // -------------------------------------------------------------------------
@@ -217,8 +239,9 @@ bool ParseArgs(
   mandatory.insert( "in" );
   mandatory.insert( "out" );
   mandatory.insert( "labels" );
+  mandatory.insert( "vesselness" );
 
-  args[ "upper_threshold" ] = "-600";
+  args[ "upper_threshold" ] = "-650";
 
   int i = 1;
   while( i < argc )
@@ -240,6 +263,7 @@ bool ParseArgs(
       << "\t-in filename" << std::endl
       << "\t-out filename" << std::endl
       << "\t-labels filename" << std::endl
+      << "\t-vesselness filename" << std::endl
       << "\t[-roi] filename" << std::endl
       << "\t[-upper_threshold value]" << std::endl;
     return( false );
@@ -264,11 +288,17 @@ int main( int argc, char* argv[] )
       TLabels::Pointer input_labels;
       ReadImage( input_labels, args[ "labels" ] );
 
+      // Read vesselness image
+      TScalarImage::Pointer input_vesselness;
+      ReadImage( input_vesselness, args[ "vesselness" ] );
+
       // Mori labelling
       MoriLabelling::Pointer labelling = MoriLabelling::New( );
       labelling->SetInput( input_image );
       labelling->SetInputLabels( input_labels );
+      labelling->SetInputVesselness( input_vesselness );
       labelling->SetOutsideValue( 2 );
+      labelling->SetFillValue( 2 );
       labelling->SetInsideValue( 1 );
       labelling->SetUpperThreshold(
         TPixel( std::atof( args[ "upper_threshold" ].c_str( ) ) )