]> Creatis software - clitk.git/commitdiff
Median Filter + some bug corrections in Resample Image Filter
authorBenoît Presles <benoit.presles@creatis.insa-lyon.fr>
Thu, 5 Sep 2013 17:07:55 +0000 (19:07 +0200)
committerBenoît Presles <benoit.presles@creatis.insa-lyon.fr>
Thu, 5 Sep 2013 17:07:55 +0000 (19:07 +0200)
cmake/dependencies.cmake
itk/clitkResampleImageWithOptionsFilter.h
itk/clitkResampleImageWithOptionsFilter.txx
tools/CMakeLists.txt
tools/clitkMedianImageGenericFilter.h
tools/clitkMedianImageGenericFilter.txx
tools/clitkResampleImageGenericFilter.txx

index 1ba42ec4568fb48fc16e9525c3e74f16578e6bba..7b389c246203d2ac0601a59045184739ffef363e 100644 (file)
@@ -70,6 +70,6 @@ ELSE(ITK_VERSION_MAJOR LESS "4")
     SET(CLITK_USE_SYSTEM_GDCM TRUE)
   ENDIF()
 ENDIF(ITK_VERSION_MAJOR LESS "4")
-
+SET(CLITK_USE_SYSTEM_GDCM FALSE)
 #DD(CLITK_USE_SYSTEM_GDCM)
 
index b526207be8f9784869a3af0c79394e3c94201124..4b6b409d37caaa492ef14769dc4f45b127898323 100644 (file)
@@ -60,6 +60,8 @@ namespace clitk {
   typedef typename OutputImageType::PixelType    OutputImagePixelType;
   typedef typename OutputImageType::SpacingType  OutputImageSpacingType;
   typedef typename OutputImageType::SizeType     OutputImageSizeType;
+  typedef typename OutputImageType::PointType    OutputImageOriginType;
+  typedef typename OutputImageType::DirectionType        OutputImageDirectionType;
     
   typedef itk::AffineTransform<double, InputImageType::ImageDimension> TransformType;
   typedef typename InputImageType::SpacingType                         GaussianSigmaType;
@@ -96,6 +98,10 @@ namespace clitk {
   itkGetMacro(OutputSpacing, OutputImageSpacingType);
   itkSetMacro(OutputSize, OutputImageSizeType);
   itkGetMacro(OutputSize, OutputImageSizeType);
+  itkSetMacro(OutputOrigin, OutputImageOriginType);
+  itkGetMacro(OutputOrigin, OutputImageOriginType);
+  itkSetMacro(OutputDirection, OutputImageDirectionType);
+  itkGetMacro(OutputDirection, OutputImageDirectionType);
   itkGetMacro(InterpolationType, InterpolationTypeEnumeration);
   itkSetMacro(InterpolationType, InterpolationTypeEnumeration);    
   itkGetMacro(GaussianFilteringEnabled, bool);
@@ -124,7 +130,9 @@ namespace clitk {
   int m_BSplineOrder;
   int m_BLUTSamplingFactor;    
   OutputImageSizeType m_OutputSize;
-  OutputImageSpacingType m_OutputSpacing;  
+  OutputImageSpacingType m_OutputSpacing;
+  OutputImageOriginType    m_OutputOrigin;
+  OutputImageDirectionType m_OutputDirection;
   typename TransformType::Pointer m_Transform;
   GaussianSigmaType m_GaussianSigma;
   OutputImagePixelType m_DefaultPixelValue;
index ddaa8a077b41f2ffcf2456836c2eeb7a4f0119fc..35eae54c2f0206a337a3c75b765ac468809d560a 100644 (file)
@@ -54,6 +54,8 @@ ResampleImageWithOptionsFilter():itk::ImageToImageFilter<InputImageType, OutputI
     m_OutputSpacing[i] = -1;
     m_GaussianSigma[i] = -1;
   }
+  m_OutputOrigin.Fill(0);
+  m_OutputDirection.SetIdentity();
   m_VerboseOptions = false;
   SetDefaultPixelValue(0);
 }
@@ -234,10 +236,10 @@ GenerateData()
   filter->SetTransform(m_Transform);
   filter->SetSize(m_OutputSize);
   filter->SetOutputSpacing(m_OutputSpacing);
-  filter->SetOutputOrigin(origin);
+  filter->SetOutputOrigin(m_OutputOrigin);
   filter->SetDefaultPixelValue(m_DefaultPixelValue);
   filter->SetNumberOfThreads(this->GetNumberOfThreads()); 
-  filter->SetOutputDirection(input->GetDirection()); // <-- NEEDED if we want to keep orientation (in case of PermutAxes for example)
+  filter->SetOutputDirection(m_OutputDirection); // <-- NEEDED if we want to keep orientation (in case of PermutAxes for example)
 
   // Select interpolator
   switch (m_InterpolationType) {
index 6d70fc3e80f0e65b3b9d672997c49b049d915e40..7ab7971afd2bc79d5311893f8a7963898cbf859f 100644 (file)
@@ -157,10 +157,10 @@ IF (CLITK_BUILD_TOOLS)
   TARGET_LINK_LIBRARIES(clitkFooImage clitkCommon )
   SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkFooImage)
 
-  #WRAP_GGO(clitkMedianImageFilter_GGO_C clitkMedianImageFilter.ggo)
-  #ADD_EXECUTABLE(clitkMedianImageFilter clitkMedianImageFilter.cxx ${clitkMedianImageFilter_GGO_C})
-  #TARGET_LINK_LIBRARIES(clitkMedianImageFilter clitkMedianImageFilterLib clitkCommon)
-  #SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkMedianImageFilter)
+  WRAP_GGO(clitkMedianImageFilter_GGO_C clitkMedianImageFilter.ggo)
+  ADD_EXECUTABLE(clitkMedianImageFilter clitkMedianImageFilter.cxx ${clitkMedianImageFilter_GGO_C})
+  TARGET_LINK_LIBRARIES(clitkMedianImageFilter clitkMedianImageFilterLib clitkCommon)
+  SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkMedianImageFilter)
 
   ADD_EXECUTABLE(clitkResampleImage clitkResampleImage.cxx)
   TARGET_LINK_LIBRARIES(clitkResampleImage clitkResampleImageLib clitkCommon)
index 58fac09b3816d5332601851ed2b981cc59670cbb..f6dc478618331b989ee5919f05cf3c93c9712203 100644 (file)
@@ -61,10 +61,11 @@ namespace clitk
   public:
 
     //--------------------------------------------------------------------
-   MedianImageGenericFilter();
+    MedianImageGenericFilter();
 
     //--------------------------------------------------------------------
-    typedef MedianImageGenericFilter         Self;
+    typedef MedianImageGenericFilter           Self;
+    typedef ImageToImageGenericFilter<MedianImageGenericFilter<args_info_type> > Superclass;
     typedef itk::SmartPointer<Self>            Pointer;
     typedef itk::SmartPointer<const Self>      ConstPointer;
    
@@ -81,15 +82,15 @@ namespace clitk
     // Main function called each time the filter is updated
     template<class InputImageType>  
     void UpdateWithInputImageType();
-    
-
 
   protected:
     template<unsigned int Dim> void InitializeImageType();
-    
     args_info_type mArgsInfo;
-    
+
+  private:
+    MedianImageGenericFilter(const Self&); //purposely not implemented
+    void operator=(const Self&); //purposely not implemented
+
   }; // end class
   //--------------------------------------------------------------------
     
index 7e4a426539e6b0ecc9c64973f118e4da2ee9b94d..75567c496b5cb6856043ea16ccbd060d11dccde9 100644 (file)
@@ -89,28 +89,26 @@ MedianImageGenericFilter<args_info_type>::UpdateWithInputImageType()
 
   // typedef itk::Image<PixelType,InputImageType::ImageDimension> OutputImageType;
 
-  // Main filter
-  typedef itk::Image<PixelType, InputImageType::ImageDimension> OutputImageType;
-  typename InputImageType::SizeType indexRadius;
-
   // Filter
-  typedef itk::MedianImageFilter<InputImageType, OutputImageType> MedianImageFilterType;
-  typename MedianImageFilterType::Pointer thresholdFilter=MedianImageFilterType::New();
-  thresholdFilter->SetInput(input);
-
-  for (unsigned i = 0; i < InputImageType::ImageDimension; ++i)
-    indexRadius[i]=mArgsInfo.radius_arg[i];
-
-  // indexRadius[0] = 1;
-  // indexRadius[1] = 1;
-
-  thresholdFilter->SetRadius( indexRadius );
-
-  typename OutputImageType::Pointer outputImage = thresholdFilter->GetOutput();
-  thresholdFilter->Update();
+  typedef itk::MedianImageFilter<InputImageType, InputImageType> MedianImageFilterType;
+  typename MedianImageFilterType::Pointer medianFilter=MedianImageFilterType::New();
+  typename MedianImageFilterType::InputSizeType radius;
+  radius.Fill(1);
+  medianFilter->SetInput(input);
+
+  if(mArgsInfo.radius_given) {
+      for (unsigned i = 0; i < InputImageType::ImageDimension; ++i)
+          radius[i]=mArgsInfo.radius_arg[i];
+  }
+  //
+  std::cout<<"radius median filter= "<<radius<<std::endl;
+  //
+  medianFilter->SetRadius( radius );
 
+  medianFilter->Update();
   // Write/Save results
-  this->template SetNextOutput<OutputImageType>(outputImage);
+  typename InputImageType::Pointer outputImage = medianFilter->GetOutput();
+  this->template SetNextOutput<InputImageType>(outputImage);
 }
 
 //--------------------------------------------------------------------
index 3448227a370cd0feb79276624fc40c2f4bea9f09..b42d18349f2f943cb95ed5ca092c931d20986b60 100644 (file)
@@ -49,6 +49,8 @@ clitk::ResampleImageGenericFilter::UpdateWithInputImageType()
   static const unsigned int dim = OutputImageType::ImageDimension;
   typename OutputImageType::SpacingType spacing;
   typename OutputImageType::SizeType size;
+  typename OutputImageType::PointType origin;
+  typename OutputImageType::DirectionType direction;
 
   if (mArgsInfo.like_given) {
     itk::ImageIOBase::Pointer header = clitk::readImageHeader(mArgsInfo.like_arg);
@@ -56,9 +58,17 @@ clitk::ResampleImageGenericFilter::UpdateWithInputImageType()
       for(unsigned int i=0; i<dim; i++){
         spacing[i] = header->GetSpacing(i);
         size[i] = header->GetDimensions(i);
+        origin[i] = header->GetOrigin(i);
+      }
+      for(unsigned int i=0; i<dim; i++) {
+        for(unsigned int j=0;j<dim;j++) {
+            direction(i,j) = header->GetDirection(i)[j];
+        }
       }
       filter->SetOutputSpacing(spacing);
       filter->SetOutputSize(size);
+      filter->SetOutputOrigin(origin);
+      filter->SetOutputDirection(direction);
     }
     else {
       std::cerr << "*** Warning : I could not read '" << mArgsInfo.like_arg << "' ***" << std::endl;
@@ -91,6 +101,17 @@ clitk::ResampleImageGenericFilter::UpdateWithInputImageType()
         size[i] = mArgsInfo.size_arg[i];
       filter->SetOutputSize(size);
     }
+    itk::ImageIOBase::Pointer header = clitk::readImageHeader(mArgsInfo.input_arg);
+    for(unsigned int i=0; i<dim; i++){
+      origin[i] = header->GetOrigin(i);
+    }
+    for(unsigned int i=0; i<dim; i++) {
+      for(unsigned int j=0;j<dim;j++) {
+          direction(i,j) = header->GetDirection(i)[j];
+      }
+    }
+    filter->SetOutputOrigin(origin);
+    filter->SetOutputDirection(direction);
   }
 
   // Set temporal dimension