]> Creatis software - FrontAlgorithms.git/blobdiff - lib/fpa/Common/SliceBySliceRandomWalker.hxx
...
[FrontAlgorithms.git] / lib / fpa / Common / SliceBySliceRandomWalker.hxx
index d1fbd9cfdf495e39a5036db6fdbc1e2ba96c9c12..1cad2a110938e9705b4f8f6498c91ac1b584a797 100644 (file)
@@ -57,10 +57,7 @@ GenerateData( )
     this->m_VesselnessThreshold * this->m_VesselnessMax / TScalar( 100 );
 
   // Composite image
-  typename TScalarImage::Pointer composite = TScalarImage::New( );
-  composite->CopyInformation( vesselness );
-  composite->SetBufferedRegion( vesselness->GetBufferedRegion( ) );
-  composite->Allocate( );
+  typename TScalarImage::Pointer composite;
   this->_Composite( composite, labels, vesselness );
 
   // Extract slices
@@ -90,8 +87,8 @@ GenerateData( )
   } // rof
 
   // Random walker slice-by-slice
-  this->_GoDown( binaryTree, data3D, fusion, numSlices );
-  this->_GoUp( binaryTree, data3D, fusion, numSlices );
+  this->_RandomWalker( binaryTree, data3D, fusion, true );
+  this->_RandomWalker( binaryTree, data3D, fusion, false );
 
   // Join results
   typedef itk::JoinSeriesImageFilter< _TSliceImage, TImage > _TJoin;
@@ -121,7 +118,7 @@ _Composite(
   typename TScalarImage::RegionType region = labels->GetRequestedRegion( );
 
   // Composite image
-  typename TScalarImage::Pointer composite = TScalarImage::New( );
+  composite = TScalarImage::New( );
   composite->CopyInformation( vesselness );
   composite->SetBufferedRegion( vesselness->GetBufferedRegion( ) );
   composite->Allocate( );
@@ -163,11 +160,11 @@ template< class _TImage, class _TLabels, class _TScalarImage >
 template< class _TBinaryTree, class _TData3D, class _TFusion >
 void
 fpa::Common::SliceBySliceRandomWalker< _TImage, _TLabels, _TScalarImage >::
-_GoDown(
+_RandomWalker(
   _TBinaryTree& binaryTree,
   const _TData3D& data3D,
   const _TFusion& fusion,
-  int numSlices
+  bool down
   )
 {
   typedef typename _TBinaryTree::value_type     _TSliceBinaryPtr;
@@ -178,14 +175,16 @@ _GoDown(
   typedef typename _TSliceFusionPtr::ObjectType _TSliceFusion;
   typedef typename _TSliceFusion::PixelType     _TSliceScalar;
 
-  int z = -1;
-  while( z < numSlices - 2 )
+  int numSlices = binaryTree.size( );
+  int z = ( down )? -1: numSlices;
+  int o = ( down )? 1: -1;
+  while( ( down && z < numSlices - 2 ) || ( !down && z > 1 ) )
   {
-    z++;
+    z += o;
     _TSliceBinaryPtr tmp = binaryTree[ z ];
-    _TSliceBinaryPtr next = binaryTree[ z  + 1 ];
-    _TSliceData3DPtr data = data3D[ z + 1 ];
-    _TSliceFusionPtr vess = fusion[ z + 1 ];
+    _TSliceBinaryPtr next = binaryTree[ z + o ];
+    _TSliceData3DPtr data = data3D[ z + o ];
+    _TSliceFusionPtr vess = fusion[ z + o ];
     typename _TSliceBinary::RegionType region = tmp->GetRequestedRegion( );
 
     // Create seeds and background
@@ -245,31 +244,15 @@ _GoDown(
     rw->SetEdgeFunction( edge );
 
     // Keep maximum
-    /* TODO
-       typedef itk::MaximumImageFilter<SliceType> MaxFilterType;
-       MaxFilterType::Pointer maxFilter = MaxFilterType::New();
-       maxFilter->SetInput(0, img2);
-       maxFilter->SetInput(1, next);
-       maxFilter->Update();
-
-       SliceType::Pointer sth = maxFilter->GetOutput();
-       ImageAlgorithm::Copy(sth.GetPointer(), binaryTree[z + 1].GetPointer(), sth->GetRequestedRegion(), binaryTree[z + 1]->GetRequestedRegion());
-       delete[] probs;
-    */
-  }
-}
-
-// -------------------------------------------------------------------------
-template< class _TImage, class _TLabels, class _TScalarImage >
-template< class _TBinaryTree, class _TData3D, class _TFusion >
-void
-_GoUp(
-  _TBinaryTree& binaryTree,
-  const _TData3D& data3D,
-  const _TFusion& fusion,
-  int numSlices
-  )
-{
+    typedef itk::MaximumImageFilter< _TSliceBinary > _TMax;
+    _TMax::Pointer max = _TMax::New();
+    max->SetInput( 0, rw->GetOutput( ) );
+    max->SetInput( 1, next );
+    max->Update( );
+    binaryTree[ z + o ] = max->GetOutput( );
+    binaryTree[ z + o ]->DisconnectPipeline( );
+
+  } // elihw
 }
 
 #endif // __fpa__Common__SliceBySliceRandomWalker__hxx__