]> Creatis software - clitk.git/commitdiff
First version of clitkLabelImageOverlapMeasure
authorDavid Sarrut <david.sarrut@gmail.com>
Mon, 24 Oct 2011 06:24:08 +0000 (08:24 +0200)
committerDavid Sarrut <david.sarrut@gmail.com>
Mon, 24 Oct 2011 06:24:08 +0000 (08:24 +0200)
itk/clitkLabelImageOverlapMeasureFilter.h [new file with mode: 0644]
itk/clitkLabelImageOverlapMeasureFilter.txx [new file with mode: 0644]
tools/clitkLabelImageOverlapMeasure.cxx [new file with mode: 0644]
tools/clitkLabelImageOverlapMeasure.ggo [new file with mode: 0644]
tools/clitkLabelImageOverlapMeasureGenericFilter.h [new file with mode: 0644]
tools/clitkLabelImageOverlapMeasureGenericFilter.txx [new file with mode: 0644]

diff --git a/itk/clitkLabelImageOverlapMeasureFilter.h b/itk/clitkLabelImageOverlapMeasureFilter.h
new file mode 100644 (file)
index 0000000..9b4a458
--- /dev/null
@@ -0,0 +1,114 @@
+/*=========================================================================
+  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 CLITKLABELIMAGEOVERLAPMEASUREFILTER_H
+#define CLITKRELATIVEPOSITIONANALYZERFILTER_H
+
+// clitk
+#include "clitkFilterBase.h"
+#include "clitkCropLikeImageFilter.h"
+#include "clitkSegmentationUtils.h"
+// #include "itkLabelOverlapMeasuresImageFilter.h"
+
+// itk
+#include <itkImageToImageFilter.h>
+#include <itkLabelStatisticsImageFilter.h>
+
+namespace clitk {
+  
+  //--------------------------------------------------------------------
+  /*
+    Analyze the relative position of a Target (mask image) according
+    to some Object, in a given Support. Indicate the main important
+    position of this Target according the Object. 
+  */
+  //--------------------------------------------------------------------
+  
+  template <class ImageType>
+  class LabelImageOverlapMeasureFilter:
+    public virtual FilterBase,
+    public itk::ImageToImageFilter<ImageType, ImageType>
+  {
+
+  public:
+    /** Standard class typedefs. */
+    typedef itk::ImageToImageFilter<ImageType, ImageType>      Superclass;
+    typedef LabelImageOverlapMeasureFilter<ImageType>          Self;
+    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(LabelImageOverlapMeasureFilter, ImageToImageFilter);
+
+    /** Some convenient typedefs. */
+    typedef typename ImageType::ConstPointer ImageConstPointer;
+    typedef typename ImageType::Pointer      ImagePointer;
+    typedef typename ImageType::RegionType   RegionType; 
+    typedef typename ImageType::PixelType    PixelType;
+    typedef typename ImageType::SpacingType  SpacingType;
+    typedef typename ImageType::SizeType     SizeType;
+    typedef typename ImageType::IndexType    IndexType;
+    typedef typename ImageType::PointType    PointType;
+    
+    /** ImageDimension constants */
+    itkStaticConstMacro(ImageDimension, unsigned int, ImageType::ImageDimension);
+    FILTERBASE_INIT;
+    // Options
+    itkGetConstMacro(BackgroundValue, PixelType);
+    itkSetMacro(BackgroundValue, PixelType);
+
+    itkGetConstMacro(Label1, PixelType);
+    itkSetMacro(Label1, PixelType);
+
+    itkGetConstMacro(Label2, PixelType);
+    itkSetMacro(Label2, PixelType);
+
+    // I dont want to verify inputs information
+    virtual void VerifyInputInformation() { }
+    
+   protected:
+    LabelImageOverlapMeasureFilter();
+    virtual ~LabelImageOverlapMeasureFilter() {}
+    
+    PixelType m_BackgroundValue;
+    PixelType m_Label1;
+    PixelType m_Label2;
+    ImagePointer m_Input1;
+    ImagePointer m_Input2;
+
+    virtual void GenerateOutputInformation();
+    virtual void GenerateInputRequestedRegion();
+    virtual void GenerateData();
+
+  private:
+    LabelImageOverlapMeasureFilter(const Self&); //purposely not implemented
+    void operator=(const Self&); //purposely not implemented
+    
+  }; // end class
+  //--------------------------------------------------------------------
+
+} // end namespace clitk
+//--------------------------------------------------------------------
+
+#include "clitkLabelImageOverlapMeasureFilter.txx"
+
+#endif
diff --git a/itk/clitkLabelImageOverlapMeasureFilter.txx b/itk/clitkLabelImageOverlapMeasureFilter.txx
new file mode 100644 (file)
index 0000000..11c1e42
--- /dev/null
@@ -0,0 +1,126 @@
+/*=========================================================================
+  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
+  ===========================================================================**/
+
+//--------------------------------------------------------------------
+template <class ImageType>
+clitk::LabelImageOverlapMeasureFilter<ImageType>::
+LabelImageOverlapMeasureFilter():
+  clitk::FilterBase(),
+  itk::ImageToImageFilter<ImageType, ImageType>()
+{
+  this->SetNumberOfRequiredInputs(2);
+  SetLabel1(1);
+  SetLabel2(1);
+  SetBackgroundValue(0);
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template <class ImageType>
+void 
+clitk::LabelImageOverlapMeasureFilter<ImageType>::
+GenerateOutputInformation() 
+{ 
+  // DD("GenerateOutputInformation");
+  //ImagePointer input = dynamic_cast<ImageType*>(itk::ProcessObject::GetInput(0));
+  // ImagePointer outputImage = this->GetOutput(0);
+  // outputImage->SetRegions(outputImage->GetLargestPossibleRegion());
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template <class ImageType>
+void 
+clitk::LabelImageOverlapMeasureFilter<ImageType>::
+GenerateInputRequestedRegion() 
+{
+  // DD("GenerateInputRequestedRegion");
+  // Call default
+  itk::ImageToImageFilter<ImageType, ImageType>::GenerateInputRequestedRegion();
+  // Get input pointers and set requested region to common region
+  ImagePointer input1 = dynamic_cast<ImageType*>(itk::ProcessObject::GetInput(0));
+  ImagePointer input2 = dynamic_cast<ImageType*>(itk::ProcessObject::GetInput(1));
+  input1->SetRequestedRegion(input1->GetLargestPossibleRegion());
+  input2->SetRequestedRegion(input2->GetLargestPossibleRegion());
+}
+//--------------------------------------------------------------------
+
+//--------------------------------------------------------------------
+template <class ImageType>
+void 
+clitk::LabelImageOverlapMeasureFilter<ImageType>::
+GenerateData() 
+{
+  // DD("GenerateData");
+
+  // Get input pointer
+  m_Input1 = dynamic_cast<ImageType*>(itk::ProcessObject::GetInput(0));
+  m_Input2 = dynamic_cast<ImageType*>(itk::ProcessObject::GetInput(1));
+  static const unsigned int dim = ImageType::ImageDimension;
+
+  // Compute union of bounding boxes
+  typedef itk::BoundingBox<unsigned long, dim> BBType;
+  typename BBType::Pointer bb1 = BBType::New();
+  ComputeBBFromImageRegion<ImageType>(m_Input1, m_Input1->GetLargestPossibleRegion(), bb1);
+  typename BBType::Pointer bb2 = BBType::New();
+  ComputeBBFromImageRegion<ImageType>(m_Input2, m_Input2->GetLargestPossibleRegion(), bb2);
+  typename BBType::Pointer bbo = BBType::New();
+  ComputeBBUnion<dim>(bbo, bb1, bb2);
+
+  // Resize like the union
+  ImagePointer input1 = clitk::ResizeImageLike<ImageType>(m_Input1, bbo, GetBackgroundValue());
+  ImagePointer input2 = clitk::ResizeImageLike<ImageType>(m_Input2, bbo, GetBackgroundValue());
+
+  // Compute overlap image
+  ImagePointer image_union = clitk::Clone<ImageType>(input1);
+  ImagePointer image_intersection = clitk::Clone<ImageType>(input1);
+  clitk::Or<ImageType>(image_union, input2, GetBackgroundValue());
+  clitk::And<ImageType>(image_intersection, input2, GetBackgroundValue());
+  
+  writeImage<ImageType>(image_union, "union.mha");
+  writeImage<ImageType>(image_intersection, "intersection.mha");
+  
+  // Compute size
+  typedef itk::LabelStatisticsImageFilter<ImageType, ImageType> StatFilterType;
+  typename StatFilterType::Pointer statFilter = StatFilterType::New();
+  statFilter->SetInput(image_union);
+  statFilter->SetLabelInput(image_union);
+  statFilter->Update();
+  int u = statFilter->GetCount(GetLabel1());
+
+  statFilter->SetInput(image_intersection);
+  statFilter->SetLabelInput(image_intersection);
+  statFilter->Update();
+  int inter = statFilter->GetCount(GetLabel1());
+  
+  statFilter->SetInput(m_Input1);
+  statFilter->SetLabelInput(m_Input1);
+  statFilter->Update();
+  int in1 = statFilter->GetCount(GetLabel1());
+
+  statFilter->SetInput(m_Input2);
+  statFilter->SetLabelInput(m_Input2);
+  statFilter->Update();
+  int in2 = statFilter->GetCount(GetLabel1());
+
+  std::cout << in1 << " " << in2 << " " << inter << " " << u << " " << (double)inter/(double)u << std::endl;
+}
+//--------------------------------------------------------------------
+
diff --git a/tools/clitkLabelImageOverlapMeasure.cxx b/tools/clitkLabelImageOverlapMeasure.cxx
new file mode 100644 (file)
index 0000000..9a7b625
--- /dev/null
@@ -0,0 +1,46 @@
+/*=========================================================================
+  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
+===========================================================================**/
+
+// clitk
+#include "clitkIO.h"
+#include "clitkLabelImageOverlapMeasure_ggo.h"
+#include "clitkLabelImageOverlapMeasureGenericFilter.h"
+
+//--------------------------------------------------------------------
+int main(int argc, char * argv[]) {
+
+  // Init command line
+  GGO(clitkLabelImageOverlapMeasure, args_info);
+  CLITK_INIT;
+
+  // Filter
+  typedef clitk::LabelImageOverlapMeasureGenericFilter<args_info_clitkLabelImageOverlapMeasure> FilterType;
+  FilterType::Pointer filter = FilterType::New();
+  
+  filter->SetArgsInfo(args_info);
+  
+  try {
+    filter->Update();
+  } catch(std::runtime_error e) {
+    std::cout << e.what() << std::endl;
+    return EXIT_FAILURE;
+  }
+
+  return EXIT_SUCCESS;
+} // This is the end, my friend
+//--------------------------------------------------------------------
diff --git a/tools/clitkLabelImageOverlapMeasure.ggo b/tools/clitkLabelImageOverlapMeasure.ggo
new file mode 100644 (file)
index 0000000..17c28ed
--- /dev/null
@@ -0,0 +1,21 @@
+#File clitkLabelImageOverlapMeasure.ggo
+package "clitkLabelImageOverlapMeasure"
+version "1.0"
+purpose "Compute Dice and other coefficients between label images"
+
+section "General options"
+option "config"                -       "Config file"                     string        no
+option "verbose"       v       "Verbose"                         flag          off
+option "imagetypes"     -       "Display allowed image types"     flag          off
+
+section "Input"
+option "input1"         i      "Input mask 1"          string          yes
+option "input2"                j       "Input mask 2"          string          yes
+
+option "label1"                l       "Label in input1"       int          no      default="1"
+option "label2"                m       "Label in input2"       int          no      default="1"
+option "BG"            b       "Background value"      int          no      default="0"
+
+
+
+
diff --git a/tools/clitkLabelImageOverlapMeasureGenericFilter.h b/tools/clitkLabelImageOverlapMeasureGenericFilter.h
new file mode 100644 (file)
index 0000000..a6f8028
--- /dev/null
@@ -0,0 +1,76 @@
+/*=========================================================================
+  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 CLITKLABELIMAGEOVERLAPMEASUREGENERICFILTER_H
+#define CLITKLABELIMAGEOVERLAPMEASUREGENERICFILTER_H
+
+// clitk 
+#include "clitkImageToImageGenericFilter.h"
+#include "clitkLabelImageOverlapMeasureFilter.h"
+#include "clitkBoundingBoxUtils.h"
+#include "clitkCropLikeImageFilter.h"
+
+//--------------------------------------------------------------------
+namespace clitk 
+{
+
+  template<class ArgsInfoType>
+  class ITK_EXPORT LabelImageOverlapMeasureGenericFilter:
+    public ImageToImageGenericFilter<LabelImageOverlapMeasureGenericFilter<ArgsInfoType> >
+  {
+  public:
+    //--------------------------------------------------------------------
+    LabelImageOverlapMeasureGenericFilter();
+  
+    //--------------------------------------------------------------------
+    typedef ImageToImageGenericFilter<LabelImageOverlapMeasureGenericFilter<ArgsInfoType> > Superclass;
+    typedef LabelImageOverlapMeasureGenericFilter Self;
+    typedef itk::SmartPointer<Self>       Pointer;
+    typedef itk::SmartPointer<const Self> ConstPointer;
+   
+    //--------------------------------------------------------------------
+    itkNewMacro(Self);  
+    itkTypeMacro(LabelImageOverlapMeasureGenericFilter, LightObject);
+
+    //--------------------------------------------------------------------
+    void SetArgsInfo(const ArgsInfoType & a);
+    template<class FilterType> 
+      void SetOptionsFromArgsInfoToFilter(FilterType * f) ;
+
+    //--------------------------------------------------------------------
+    // Main function called each time the filter is updated
+    template<class ImageType>  
+    void UpdateWithInputImageType();
+
+  protected:
+    template<unsigned int Dim> void InitializeImageType();
+      ArgsInfoType mArgsInfo;
+
+  private:
+    LabelImageOverlapMeasureGenericFilter(const Self&); //purposely not implemented
+    void operator=(const Self&); //purposely not implemented
+    
+  };// end class
+  //--------------------------------------------------------------------
+} // end namespace clitk
+
+#ifndef ITK_MANUAL_INSTANTIATION
+#include "clitkLabelImageOverlapMeasureGenericFilter.txx"
+#endif
+
+#endif // #define CLITKRELATIVEPOSITIONANALYZERGENERICFILTER_H
diff --git a/tools/clitkLabelImageOverlapMeasureGenericFilter.txx b/tools/clitkLabelImageOverlapMeasureGenericFilter.txx
new file mode 100644 (file)
index 0000000..bb1b6eb
--- /dev/null
@@ -0,0 +1,100 @@
+/*=========================================================================
+  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
+  ===========================================================================**/
+
+//--------------------------------------------------------------------
+template<class ArgsInfoType>
+clitk::LabelImageOverlapMeasureGenericFilter<ArgsInfoType>::
+LabelImageOverlapMeasureGenericFilter():
+  ImageToImageGenericFilter<Self>("LabelImageOverlapMeasure")
+{
+  // Default values
+  cmdline_parser_clitkLabelImageOverlapMeasure_init(&mArgsInfo);
+  //InitializeImageType<2>();
+  InitializeImageType<3>();
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template<class ArgsInfoType>
+template<unsigned int Dim>
+void clitk::LabelImageOverlapMeasureGenericFilter<ArgsInfoType>::
+InitializeImageType() 
+{  
+  ADD_IMAGE_TYPE(Dim, uchar);
+}
+//--------------------------------------------------------------------
+  
+
+//--------------------------------------------------------------------
+template<class ArgsInfoType>
+void clitk::LabelImageOverlapMeasureGenericFilter<ArgsInfoType>::
+SetArgsInfo(const ArgsInfoType & a) 
+{
+  mArgsInfo=a;
+  SetIOVerbose(mArgsInfo.verbose_flag);
+  if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes();
+  if (mArgsInfo.input1_given) AddInputFilename(mArgsInfo.input1_arg);
+  if (mArgsInfo.input2_given) AddInputFilename(mArgsInfo.input2_arg);
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+// Update with the number of dimensions and the pixeltype
+//--------------------------------------------------------------------
+template<class ArgsInfoType>
+template<class FilterType>
+void clitk::LabelImageOverlapMeasureGenericFilter<ArgsInfoType>::
+SetOptionsFromArgsInfoToFilter(FilterType * f) 
+{
+  f->SetLabel1(mArgsInfo.label1_arg);  
+  f->SetLabel2(mArgsInfo.label2_arg);  
+}
+
+//--------------------------------------------------------------------
+// Update with the number of dimensions and the pixeltype
+//--------------------------------------------------------------------
+template<class ArgsInfoType>
+template<class ImageType>
+void clitk::LabelImageOverlapMeasureGenericFilter<ArgsInfoType>::
+UpdateWithInputImageType() 
+{ 
+  // Reading input
+  typename ImageType::Pointer input1 = this->template GetInput<ImageType>(0);
+  typename ImageType::Pointer input2 = this->template GetInput<ImageType>(1);
+
+  // Create filter
+  typedef clitk::LabelImageOverlapMeasureFilter<ImageType> FilterType;
+  typename FilterType::Pointer filter = FilterType::New();
+  
+  // Set global Options 
+  filter->SetInput(0, input1);
+  filter->SetInput(1, input2);
+  SetOptionsFromArgsInfoToFilter<FilterType>(filter);
+
+  // Go !
+  filter->Update();
+  
+  // Write/Save results
+  // typename ImageType::Pointer output = filter->GetOutput();
+  // this->template SetNextOutput<ImageType>(output); 
+}
+//--------------------------------------------------------------------
+
+