]> Creatis software - clitk.git/commitdiff
relative position 2D slice by slice (attempt)
authordsarrut <dsarrut>
Wed, 7 Jul 2010 13:39:07 +0000 (13:39 +0000)
committerdsarrut <dsarrut>
Wed, 7 Jul 2010 13:39:07 +0000 (13:39 +0000)
itk/clitkSliceBySliceRelativePositionFilter.h [new file with mode: 0644]
itk/clitkSliceBySliceRelativePositionFilter.txx [new file with mode: 0644]

diff --git a/itk/clitkSliceBySliceRelativePositionFilter.h b/itk/clitkSliceBySliceRelativePositionFilter.h
new file mode 100644 (file)
index 0000000..01f9cd9
--- /dev/null
@@ -0,0 +1,105 @@
+/*=========================================================================
+  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://oncora1.lyon.fnclcc.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 CLITKSLICEBYSLICERELATIVEPOSITIONFILTER_H
+#define CLITKSLICEBYSLICERELATIVEPOSITIONFILTER_H
+
+// clitk
+#include "clitkFilterBase.h"
+
+namespace clitk {
+  
+  //--------------------------------------------------------------------
+  /*
+    Perform Relative Position filtering in a slice by slice manner. 
+  */
+  //--------------------------------------------------------------------
+  
+  template <class ImageType>
+  class ITK_EXPORT SliceBySliceRelativePositionFilter:
+    public clitk::FilterBase, 
+    public itk::ImageToImageFilter<ImageType, ImageType> 
+  {
+
+  public:
+    /** Standard class typedefs. */
+    typedef itk::ImageToImageFilter<ImageType, ImageType> Superclass;
+    typedef SliceBySliceRelativePositionFilter              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(SliceBySliceRelativePositionFilter, ImageToImageFilter);
+    FILTERBASE_INIT;
+
+    /** 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;
+    
+    /** ImageDimension constants */
+    itkStaticConstMacro(ImageDimension, unsigned int, ImageType::ImageDimension);
+    typedef itk::Image<float, ImageDimension> FloatImageType;
+
+    /** Input : initial image and object */
+    void SetInput(const ImageType * image);
+    void SetInputObject(const ImageType * image);
+    
+    // Options
+    itkGetConstMacro(Direction, int);
+    itkSetMacro(Direction, int);
+    itkGetConstMacro(ObjectBackgroundValue, PixelType);
+    itkSetMacro(ObjectBackgroundValue, PixelType);
+
+  protected:
+    SliceBySliceRelativePositionFilter();
+    virtual ~SliceBySliceRelativePositionFilter() {}
+    
+    int m_Direction;
+    PixelType m_ObjectBackgroundValue;
+
+    virtual void GenerateOutputInformation();
+    virtual void GenerateInputRequestedRegion();
+    virtual void GenerateData();
+
+    ImagePointer input;
+    ImagePointer object;
+    ImagePointer m_working_input;
+    ImagePointer m_working_object;
+
+  private:
+    SliceBySliceRelativePositionFilter(const Self&); //purposely not implemented
+    void operator=(const Self&); //purposely not implemented
+    
+  }; // end class
+  //--------------------------------------------------------------------
+
+} // end namespace clitk
+//--------------------------------------------------------------------
+
+#ifndef ITK_MANUAL_INSTANTIATION
+#include "clitkSliceBySliceRelativePositionFilter.txx"
+#endif
+
+#endif
diff --git a/itk/clitkSliceBySliceRelativePositionFilter.txx b/itk/clitkSliceBySliceRelativePositionFilter.txx
new file mode 100644 (file)
index 0000000..af9c4c5
--- /dev/null
@@ -0,0 +1,203 @@
+/*=========================================================================
+  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://oncora1.lyon.fnclcc.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 "clitkSegmentationUtils.h"
+// #include "clitkBooleanOperatorLabelImageFilter.h"
+// #include "clitkAutoCropFilter.h"
+// #include "clitkResampleImageWithOptionsFilter.h"
+// #include "clitkBooleanOperatorLabelImageFilter.h"
+#include "clitkExtractSliceFilter.h"
+
+// // itk
+// #include <deque>
+// #include "itkStatisticsLabelMapFilter.h"
+// #include "itkLabelImageToStatisticsLabelMapFilter.h"
+// #include "itkRegionOfInterestImageFilter.h"
+// #include "itkBinaryThresholdImageFilter.h"
+// #include "itkBinaryErodeImageFilter.h"
+// #include "itkBinaryBallStructuringElement.h"
+
+// // itk [Bloch et al] 
+// #include "RelativePositionPropImageFilter.h"
+
+//--------------------------------------------------------------------
+template <class ImageType>
+clitk::SliceBySliceRelativePositionFilter<ImageType>::
+SliceBySliceRelativePositionFilter():
+  clitk::FilterBase(),
+  itk::ImageToImageFilter<ImageType, ImageType>()
+{
+  this->SetNumberOfRequiredInputs(2);
+  SetDirection(2);
+  SetObjectBackgroundValue(0);
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template <class ImageType>
+void 
+clitk::SliceBySliceRelativePositionFilter<ImageType>::
+SetInput(const ImageType * image) {
+  // Process object is not const-correct so the const casting is required.
+  this->SetNthInput(0, const_cast<ImageType *>(image));
+}
+//--------------------------------------------------------------------
+  
+
+//--------------------------------------------------------------------
+template <class ImageType>
+void 
+clitk::SliceBySliceRelativePositionFilter<ImageType>::
+SetInputObject(const ImageType * image) {
+  // Process object is not const-correct so the const casting is required.
+  this->SetNthInput(1, const_cast<ImageType *>(image));
+}
+//--------------------------------------------------------------------
+  
+
+//--------------------------------------------------------------------
+template <class ImageType>
+void 
+clitk::SliceBySliceRelativePositionFilter<ImageType>::
+GenerateOutputInformation() { 
+  ImagePointer input = dynamic_cast<ImageType*>(itk::ProcessObject::GetInput(0));
+  ImagePointer outputImage = this->GetOutput(0);
+  outputImage->SetRegions(input->GetLargestPossibleRegion());
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template <class ImageType>
+void 
+clitk::SliceBySliceRelativePositionFilter<ImageType>::
+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::SliceBySliceRelativePositionFilter<ImageType>::
+GenerateData() {
+  // Get input pointer
+  input = dynamic_cast<ImageType*>(itk::ProcessObject::GetInput(0));
+  object = dynamic_cast<ImageType*>(itk::ProcessObject::GetInput(1));
+
+  //--------------------------------------------------------------------
+  // Resample object to the same spacing than input
+  if (!clitk::HaveSameSpacing<ImageType, ImageType>(object, input)) {
+    StartNewStep("Resample object to the same spacing than input");
+    m_working_object = clitk::ResampleImageSpacing<ImageType>(object, input->GetSpacing());
+    StopCurrentStep<ImageType>(m_working_object);
+  }
+  else {
+    DD("no resampling");
+    m_working_object = object;
+  }
+  
+  //--------------------------------------------------------------------
+  // Pad object to the same size than input
+  if (!clitk::HaveSameSizeAndSpacing<ImageType, ImageType>(m_working_object, input)) {
+    StartNewStep("Pad object to the same size than input");
+    m_working_object = clitk::EnlargeImageLike<ImageType>(m_working_object, 
+                                                          input, 
+                                                          GetObjectBackgroundValue());
+    StopCurrentStep<ImageType>(m_working_object);
+  }
+  else {
+    DD("no pad");
+  }
+  
+  /*
+
+
+  //--------------------------------------------------------------------
+  // Extract input slices
+  StartNewStep("Extract input slices");
+  typedef clitk::ExtractSliceFilter<ImageType> ExtractSliceFilterType;
+  typename ExtractSliceFilterType::Pointer extractSliceFilter = Extractslicefilter::New();
+  extractSliceFilter->SetInput(input);
+  extractSliceFilter->SetDirection(GetDirection());
+  extractSliceFilter->Update();
+  typedef typename ExtractSliceFilterType::SliceType SliceType;
+  std::vector<typename SliceType::Pointer> & mInputSlices = extractSliceFilter->GetOutput();
+  DD(mInputSlices.size());
+  StopCurrentStep<SliceType>(mInputSlices[5]);
+  
+  //--------------------------------------------------------------------
+  // Extract object slices
+
+  StartNewStep("Extract object slices");
+  extractSliceFilter = Extractslicefilter::New();
+  extractSliceFilter->SetInput(input);
+  extractSliceFilter->SetDirection(GetDirection());
+  extractSliceFilter->Update();
+  std::vector<typename SliceType::Pointer> & mObjectSlices = extractSliceFilter->GetOutput();
+  DD(mObjectSlices.size());
+  StopCurrentStep<SliceType>(mInputSlices[5]);
+
+  
+  //--------------------------------------------------------------------
+  // Perform slice by slice relative position
+  StartNewStep("Perform slice by slice relative position");
+  for(int i=0; i<mInputSlices.size(); i++) {
+    DD(i);
+    typedef clitk::AddRelativePositionConstraintToLabelImageFilter<SliceType> RelPosFilterType;
+    typename RelPosFilterType::Pointer relPosFilter = RelPosFilterType::New();
+    relPosFilter->VerboseStepOff();
+    relPosFilter->WriteStepOff();
+    relPosFilter->SetInput(mInputSlices[i]); 
+    relPosFilter->SetInputObject(mObjectSlices[i]); 
+    relPosFilter->SetOrientationType(GetOrientationType());
+    relPosFilter->SetIntermediateSpacing(GetIntermediateSpacing());
+    relPosFilter->SetFuzzyThreshold(GetFuzzyThreshold());
+    relPosFilter->Update();
+    mInputSlices[i] = relPosFilter->GetOutput();
+  }
+  typedef itk::JoinSeriesImageFilter<SliceType, ImageType> JointSeriesFilterType;
+  typename JointSeriesFilterType::Pointer jointFilter = JointSeriesFilterType::New();
+  for(int i=0; i<mInputSlices.size(); i++) {
+    jointFilter->SetInput(i, mInputSlices[i]);
+  }
+  m_working_input = jointFilter->GetOutput();
+  DD(m_working_input->GetSpacing());
+  DD(m_working_input->GetOrigin());
+  StopCurrentStep<ImageType>(m_working_input);
+
+  */
+
+
+  //--------------------------------------------------------------------
+  //--------------------------------------------------------------------  
+  // Final Step -> set output
+  this->SetNthOutput(0, m_working_input);
+  return;
+}
+//--------------------------------------------------------------------
+