]> Creatis software - clitk.git/commitdiff
new tool = gaussian blur filtering + improved gradient magnitude tool + added help...
authorBenoît Presles <benoit.presles@creatis.insa-lyon.fr>
Fri, 17 Jan 2014 18:16:49 +0000 (19:16 +0100)
committerBenoît Presles <benoit.presles@creatis.insa-lyon.fr>
Fri, 17 Jan 2014 18:16:49 +0000 (19:16 +0100)
tools/CMakeLists.txt
tools/clitkBlurImage.cxx [new file with mode: 0644]
tools/clitkBlurImage.ggo [new file with mode: 0644]
tools/clitkBlurImageGenericFilter.h [new file with mode: 0644]
tools/clitkBlurImageGenericFilter.txx [new file with mode: 0644]
tools/clitkImageGradientMagnitude.ggo
tools/clitkImageGradientMagnitudeGenericFilter.txx
tools/clitkImageLaplacian.ggo

index 3e7a20bb69ba9a7d9b2aa765d2ae638373410a3e..144fa6f2dda79953c40a04e44feb81a89cc48e10 100644 (file)
@@ -320,6 +320,10 @@ IF (CLITK_BUILD_TOOLS)
   TARGET_LINK_LIBRARIES(clitkImageIntensityWindowing clitkCommon )
   SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkImageIntensityWindowing)
 
+  WRAP_GGO(clitkBlurImage_GGO_C clitkBlurImage.ggo)
+  ADD_EXECUTABLE(clitkBlurImage clitkBlurImage.cxx ${clitkBlurImage_GGO_C})
+  TARGET_LINK_LIBRARIES(clitkBlurImage clitkCommon )
+  SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkBlurImage)
 
   #=========================================================
   option(CLITK_USE_ROOT "Build experimental tools using root" OFF)
diff --git a/tools/clitkBlurImage.cxx b/tools/clitkBlurImage.cxx
new file mode 100644 (file)
index 0000000..2aa80d8
--- /dev/null
@@ -0,0 +1,50 @@
+/*=========================================================================
+  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
+===========================================================================**/
+
+/* =================================================
+ * @file   clitkBlurImageGenericFilter.txx
+ * @author xxx <xxx@creatis.insa-lyon.fr>
+ * @date   29 June 2029
+ *
+ * @brief BlurImage an image
+ *
+ ===================================================*/
+
+// clitk
+#include "clitkBlurImage_ggo.h"
+#include "clitkBlurImageGenericFilter.h"
+
+//--------------------------------------------------------------------
+int main(int argc, char * argv[])
+{
+
+  // Init command line
+  GGO(clitkBlurImage, args_info);
+  CLITK_INIT;
+
+  // Filter
+  typedef clitk::BlurImageGenericFilter<args_info_clitkBlurImage> FilterType;
+  FilterType::Pointer filter = FilterType::New();
+
+  filter->SetArgsInfo(args_info);
+  filter->Update();
+
+  return EXIT_SUCCESS;
+}// end main
+
+//--------------------------------------------------------------------
diff --git a/tools/clitkBlurImage.ggo b/tools/clitkBlurImage.ggo
new file mode 100644 (file)
index 0000000..a97becd
--- /dev/null
@@ -0,0 +1,14 @@
+#File clitkBlurImage.ggo
+package "clitkBlurImage"
+version "1.0"
+purpose "Filter the input image with a Gaussian"
+
+option "config"                -       "Config file"                     string        optional
+option "verbose"       v       "Verbose"                         flag          off
+
+option "imagetypes"    -       "Display allowed image types"     flag          off
+
+option "input"         i       "Input image filename"            string        required
+option "output"        o       "Output image filename"           string        required
+
+option "variance"       -      "value of the gaussian variance (multiple values=number of image dimension)"    double  required    multiple
diff --git a/tools/clitkBlurImageGenericFilter.h b/tools/clitkBlurImageGenericFilter.h
new file mode 100644 (file)
index 0000000..be79889
--- /dev/null
@@ -0,0 +1,69 @@
+/*=========================================================================
+  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 CLITKBlurImageGENERICFILTER_H
+#define CLITKBlurImageGENERICFILTER_H
+#include "clitkIO.h"
+#include "clitkImageToImageGenericFilter.h"
+
+//--------------------------------------------------------------------
+namespace clitk
+{
+
+template<class args_info_type>
+class ITK_EXPORT BlurImageGenericFilter:
+        public ImageToImageGenericFilter<BlurImageGenericFilter<args_info_type> >
+{
+
+public:
+
+    //--------------------------------------------------------------------
+    BlurImageGenericFilter();
+
+    //--------------------------------------------------------------------
+    typedef BlurImageGenericFilter             Self;
+    typedef itk::SmartPointer<Self>            Pointer;
+    typedef itk::SmartPointer<const Self>      ConstPointer;
+
+    //--------------------------------------------------------------------
+    // Method for creation through the object factory
+    // and Run-time type information (and related methods)
+    itkNewMacro(Self);
+    itkTypeMacro(BlurImageGenericFilter, LightObject);
+
+    //--------------------------------------------------------------------
+    void SetArgsInfo(const args_info_type & a);
+
+    //--------------------------------------------------------------------
+    // 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;
+
+}; // end class
+//--------------------------------------------------------------------
+
+} // end namespace clitk
+
+#ifndef ITK_MANUAL_INSTANTIATION
+#include "clitkBlurImageGenericFilter.txx"
+#endif
+
+#endif // #define clitkBlurImageGenericFilter_h
diff --git a/tools/clitkBlurImageGenericFilter.txx b/tools/clitkBlurImageGenericFilter.txx
new file mode 100644 (file)
index 0000000..6868320
--- /dev/null
@@ -0,0 +1,120 @@
+/*=========================================================================
+  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 clitkBlurImageGenericFilter_txx
+#define clitkBlurImageGenericFilter_txx
+
+/* =================================================
+ * @file   clitkBlurImageGenericFilter.txx
+ * @author Jef Vandemeulebroucke <jef@creatis.insa-lyon.fr>
+ * @date   29 june 2009
+ *
+ * @brief
+ *
+ ===================================================*/
+
+// itk include
+#include "itkDiscreteGaussianImageFilter.h"
+#include <clitkCommon.h>
+
+namespace clitk
+{
+
+//--------------------------------------------------------------------
+template<class args_info_type>
+BlurImageGenericFilter<args_info_type>::BlurImageGenericFilter():
+  ImageToImageGenericFilter<Self>("BlurImage")
+{
+  InitializeImageType<2>();
+  InitializeImageType<3>();
+  //InitializeImageType<4>();
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template<class args_info_type>
+template<unsigned int Dim>
+void BlurImageGenericFilter<args_info_type>::InitializeImageType()
+{
+  ADD_DEFAULT_IMAGE_TYPES(Dim);
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template<class args_info_type>
+void BlurImageGenericFilter<args_info_type>::SetArgsInfo(const args_info_type & a)
+{
+  mArgsInfo=a;
+  this->SetIOVerbose(mArgsInfo.verbose_flag);
+  if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes();
+
+  if (mArgsInfo.input_given) {
+    this->SetInputFilename(mArgsInfo.input_arg);
+  }
+  if (mArgsInfo.output_given) {
+    this->SetOutputFilename(mArgsInfo.output_arg);
+  }
+}
+//--------------------------------------------------------------------
+
+//--------------------------------------------------------------------
+// Update with the number of dimensions and the pixeltype
+//--------------------------------------------------------------------
+template<class args_info_type>
+template<class InputImageType>
+void
+BlurImageGenericFilter<args_info_type>::UpdateWithInputImageType()
+{
+  const unsigned int dim = InputImageType::ImageDimension;
+  double varianceArray[dim];
+
+  //std::cout<<"mArgsInfo.variance_given"<<mArgsInfo.variance_given<<std::endl;
+
+  if (mArgsInfo.variance_given != dim) {
+    std::cerr << "The number of variance parameters must be equal to the image dimension." << std::endl;
+    return;
+  }
+
+  for (unsigned int i = 0; i < dim; i++) {
+    //std::cout<<"mArgsInfo.variance_arg[i]"<<mArgsInfo.variance_arg[i]<<std::endl;
+    varianceArray[i] = mArgsInfo.variance_arg[i];
+  }
+  // Reading input
+  typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
+
+  // Main filter
+  typedef typename InputImageType::PixelType PixelType;
+  typedef itk::Image<float, InputImageType::ImageDimension> OutputImageType;
+
+  // Filter
+  typedef itk::DiscreteGaussianImageFilter<InputImageType, OutputImageType> DiscreteGaussianImageFilterType;
+  typename DiscreteGaussianImageFilterType::Pointer gaussianFilter=DiscreteGaussianImageFilterType::New();
+  gaussianFilter->SetInput(input);
+  gaussianFilter->SetVariance(varianceArray);
+  gaussianFilter->Update();
+
+  // Write/Save results
+  this->template SetNextOutput<OutputImageType>(gaussianFilter->GetOutput());
+}
+//--------------------------------------------------------------------
+
+
+}//end clitk
+
+#endif //#define clitkBlurImageGenericFilter_txx
index 4677ac303eba532cfa89e1f493daa36e69fd5e20..3863262dc5ca6deab29e3c59647e422031d8831d 100644 (file)
@@ -1,7 +1,7 @@
 #File clitkImageGradientMagnitude.ggo
 package "clitkImageGradientMagnitude"
 version "1.0"
-purpose ""
+purpose "Compute the gradient magnitude of the input image"
 
 option "config"                -       "Config file"                     string        optional
 option "verbose"       v       "Verbose"                         flag          off
@@ -12,3 +12,4 @@ option "input"                i       "Input image filename"            string        required
 option "mask"          m       "Mask input image filename"       string        optional
 option "output"        o       "Output image filename"           string        required
 option "normalize"      n       "Normalize the output image between 0 and 1"    flag off
+option "gaussian_filter" g      "Gaussian filtering"              flag          off
index 95ac742f6d09cbd0558e929de7d5a938a1e0ac67..19bf8236f8958c191b8d304f0ee0b236c34de3ff 100644 (file)
@@ -29,6 +29,7 @@
 
 // itk include
 #include "itkGradientMagnitudeImageFilter.h"
+#include "itkGradientMagnitudeRecursiveGaussianImageFilter.h"
 #include "itkLabelStatisticsImageFilter.h"
 #include "itkMaskImageFilter.h"
 #include "itkMaskNegatedImageFilter.h"
@@ -127,13 +128,24 @@ namespace clitk
         IteratorOutputType ito = IteratorOutputType(outputImage, outputImage->GetLargestPossibleRegion());
 
         // Filter
+        typename OutputImageType::Pointer outputGradientFilter;
+        if (mArgsInfo.gaussian_filter_flag == 0) {
         typedef itk::GradientMagnitudeImageFilter<InputImageType, OutputImageType> GradientMagnitudeImageFilterType;
         typename GradientMagnitudeImageFilterType::Pointer gradientFilter=GradientMagnitudeImageFilterType::New();
         gradientFilter->SetInput(input);
         gradientFilter->Update();
+        outputGradientFilter = gradientFilter->GetOutput();
+        }
+        else {
+            typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<InputImageType, OutputImageType> GradientMagnitudeImageFilterType;
+            typename GradientMagnitudeImageFilterType::Pointer gradientFilter=GradientMagnitudeImageFilterType::New();
+            gradientFilter->SetInput(input);
+            gradientFilter->Update();
+            outputGradientFilter = gradientFilter->GetOutput();
+        }
         // Set iterator
         typedef itk::ImageRegionIterator<OutputImageType> IteratorType;
-        IteratorType it(gradientFilter->GetOutput(), gradientFilter->GetOutput()->GetLargestPossibleRegion());
+        IteratorType it(outputGradientFilter, outputGradientFilter->GetLargestPossibleRegion());
 
         // Set mask iterator
         typedef itk::ImageRegionIterator<MaskImageType> IteratorMaskType;
@@ -141,12 +153,12 @@ namespace clitk
 
         //typedef itk::MinimumMaximumImageCalculator <OutputImageType> ImageCalculatorFilterType;
         //typename ImageCalculatorFilterType::Pointer imageCalculatorFilter = ImageCalculatorFilterType::New();
-        //imageCalculatorFilter->SetImage(gradientFilter->GetOutput());
+        //imageCalculatorFilter->SetImage(outputGradientFilter);
         //imageCalculatorFilter->Compute();
         typedef itk::LabelStatisticsImageFilter< OutputImageType, MaskImageType > LabelStatisticsImageFilterType;
         typename LabelStatisticsImageFilterType::Pointer labelStatisticsImageFilter = LabelStatisticsImageFilterType::New();
         labelStatisticsImageFilter->SetLabelInput( mask );
-        labelStatisticsImageFilter->SetInput(gradientFilter->GetOutput());
+        labelStatisticsImageFilter->SetInput(outputGradientFilter);
         labelStatisticsImageFilter->Update();
 
         //std::cout << "Number of labels: " << labelStatisticsImageFilter->GetNumberOfLabels() << std::endl;
@@ -172,7 +184,7 @@ namespace clitk
             ++itm;
         }
 
-        //typename OutputImageType::Pointer outputImage = gradientFilter->GetOutput();
+        //typename OutputImageType::Pointer outputImage = outputGradientFilter;
         this->template SetNextOutput<OutputImageType>(outputImage);
     }
     //--------------------------------------------------------------------
index f97ef9b2957ad5f41753b67a5b4a70de050fbc61..4ba1afdbdeb4f4e4add6786a8c63d9716243e2fd 100644 (file)
@@ -1,7 +1,7 @@
 #File clitkImageLaplacian.ggo
 package "clitkImageLaplacian"
 version "1.0"
-purpose ""
+purpose "Compute the laplacian of the input image"
 
 option "config"                -       "Config file"                     string        optional
 option "verbose"       v       "Verbose"                         flag          off