]> Creatis software - clitk.git/commitdiff
Add filter to reconstruct labeled images with successive dilatation. Dilatation only...
authordsarrut <david.sarrut@gmail.com>
Fri, 6 May 2011 12:35:28 +0000 (14:35 +0200)
committerdsarrut <david.sarrut@gmail.com>
Fri, 6 May 2011 12:35:28 +0000 (14:35 +0200)
itk/clitkReconstructWithConditionalGrayscaleDilateImageFilter.h [new file with mode: 0644]
itk/clitkReconstructWithConditionalGrayscaleDilateImageFilter.txx [new file with mode: 0644]

diff --git a/itk/clitkReconstructWithConditionalGrayscaleDilateImageFilter.h b/itk/clitkReconstructWithConditionalGrayscaleDilateImageFilter.h
new file mode 100644 (file)
index 0000000..0b0de84
--- /dev/null
@@ -0,0 +1,108 @@
+/*=========================================================================
+  Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
+
+  Authors belong to:
+  - University of LYON              http://www.universite-lyon.fr/
+  - Léon Bérard cancer center       http://www.centreleonberard.fr
+  - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
+
+  This software is distributed WITHOUT ANY WARRANTY; without even
+  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+  PURPOSE.  See the copyright notices for more information.
+
+  It is distributed under dual licence
+
+  - BSD        See included LICENSE.txt file
+  - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+===========================================================================*/
+
+#ifndef clitkReconstructWithConditionalGrayscaleDilateImageFilter_h
+#define clitkReconstructWithConditionalGrayscaleDilateImageFilter_h
+
+// clitk include
+#include "clitkIO.h"
+#include "clitkCommon.h"
+#include "clitkConditionalGrayscaleDilateImageFilter.h"
+
+namespace clitk 
+{
+  /*
+    This filter takes as input a multilabel image (and a bg value).
+    It performs several greyscale dilatation of radius 1, but only in
+    the bg pixels. It means that when two objects (with different
+    labels) will dilate inside each other (collistion), the dilatation
+    is stopped.
+   */
+
+  template <class ImageType>
+  class ITK_EXPORT ReconstructWithConditionalGrayscaleDilateImageFilter :
+    public itk::ImageToImageFilter<ImageType, ImageType>
+  {
+  public:
+    //----------------------------------------
+    // ITK
+    //----------------------------------------
+    typedef ReconstructWithConditionalGrayscaleDilateImageFilter Self;
+    typedef itk::ImageToImageFilter<ImageType, ImageType>        Superclass;
+    typedef itk::SmartPointer<Self>                              Pointer;
+    typedef itk::SmartPointer<const Self>                        ConstPointer;
+   
+    // Method for creation through the object factory
+    itkNewMacro(Self);  
+
+    // Run-time type information (and related methods)
+    itkTypeMacro( ReconstructWithConditionalGrayscaleDilateImageFilter, ImageToImageFilter);
+
+    /** Dimension of the domain space. */
+    itkStaticConstMacro(ImageDimension, unsigned int, Superclass::InputImageDimension);
+
+    //----------------------------------------
+    // Typedefs
+    //----------------------------------------
+    typedef typename ImageType::PixelType PixelType;
+    typedef typename ImageType::SizeType SizeType;
+
+    //----------------------------------------
+    // Set & Get
+    //----------------------------------------    
+    itkBooleanMacro(Verbose);
+    itkSetMacro( Verbose, bool);
+    itkGetConstReferenceMacro( Verbose, bool);
+
+    itkSetMacro(IterationNumber, int);
+    itkGetConstMacro(IterationNumber, int);
+
+    itkSetMacro(BackgroundValue, PixelType);
+    itkGetConstMacro(BackgroundValue, PixelType);
+
+  protected:
+
+    //----------------------------------------  
+    // Constructor & Destructor
+    //----------------------------------------  
+    ReconstructWithConditionalGrayscaleDilateImageFilter();
+    ~ReconstructWithConditionalGrayscaleDilateImageFilter() {};
+
+    //----------------------------------------  
+    // Update
+    //----------------------------------------  
+    // Generate Data
+    void GenerateData(void);
+
+    //----------------------------------------  
+    // Data members
+    //----------------------------------------
+    bool m_Verbose;
+    PixelType m_BackgroundValue;
+    int m_IterationNumber;
+  };
+
+} // end namespace clitk
+
+#ifndef ITK_MANUAL_INSTANTIATION
+#include "clitkReconstructWithConditionalGrayscaleDilateImageFilter.txx"
+#endif
+
+#endif // #define clitkReconstructWithConditionalGrayscaleDilateImageFilter_h
+
+
diff --git a/itk/clitkReconstructWithConditionalGrayscaleDilateImageFilter.txx b/itk/clitkReconstructWithConditionalGrayscaleDilateImageFilter.txx
new file mode 100644 (file)
index 0000000..7a68818
--- /dev/null
@@ -0,0 +1,79 @@
+/*=========================================================================
+  Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
+
+  Authors belong to:
+  - University of LYON              http://www.universite-lyon.fr/
+  - Léon Bérard cancer center       http://www.centreleonberard.fr
+  - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
+
+  This software is distributed WITHOUT ANY WARRANTY; without even
+  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+  PURPOSE.  See the copyright notices for more information.
+
+  It is distributed under dual licence
+
+  - BSD        See included LICENSE.txt file
+  - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+===========================================================================*/
+
+#ifndef clitkReconstructWithConditionalGrayscaleDilateImageFilter_txx
+#define clitkReconstructWithConditionalGrayscaleDilateImageFilter_txx
+
+#include <itkGrayscaleDilateImageFilter.h>
+
+namespace clitk
+{
+
+  //-------------------------------------------------------------------
+  template<class ImageType>
+  ReconstructWithConditionalGrayscaleDilateImageFilter<ImageType>::ReconstructWithConditionalGrayscaleDilateImageFilter()
+  {
+   m_Verbose=false;
+   m_BackgroundValue=0;
+   m_IterationNumber = 5;
+  }
+  //-------------------------------------------------------------------
+
+  //-------------------------------------------------------------------
+  template<class ImageType> 
+  void 
+  ReconstructWithConditionalGrayscaleDilateImageFilter<ImageType>::GenerateData()
+  {
+    // Get input image 
+    typename ImageType::ConstPointer input = this->GetInput();
+
+    // Main loop
+    typename ImageType::Pointer output;
+    for(int r=0; r<GetIterationNumber(); r++) {
+      
+      // Create kernel for GrayscaleDilateImageFilter
+      typedef itk::BinaryBallStructuringElement<PixelType,ImageDimension > KernelType;
+      KernelType k;
+      k.SetRadius(1);
+      k.CreateStructuringElement();
+    
+      // Check that BG is 0, because ConditionalGrayscaleDilateImageFilter consider BG is 0
+      if (GetBackgroundValue() !=0) {
+        FATAL("FATAL -> BG is not 0, check ReconstructWithConditionalGrayscaleDilateImageFilter");
+        // TODO -> replace 0 with new label, replace BG with 0 ; reverse at the end
+      }
+      
+      // ConditionalGrayscaleDilateImageFilter -> Dilate only BG value
+      typedef itk::ConditionalGrayscaleDilateImageFilter<ImageType, ImageType, KernelType> FilterType;
+      typename FilterType::Pointer m = FilterType::New();
+      m->SetKernel(k);
+      if (r==0) {
+        m->SetInput(input); // First time
+      }
+      else m->SetInput(output);
+      m->Update();
+      output = m->GetOutput();
+    }
+
+    //---------------------------------
+    this->SetNthOutput(0, output);
+  }
+
+}//end clitk
+#endif //#define clitkReconstructWithConditionalGrayscaleDilateImageFilter_txx