]> Creatis software - clitk.git/commitdiff
- binarize filter
authordsarrut <dsarrut>
Fri, 29 Jan 2010 07:28:33 +0000 (07:28 +0000)
committerdsarrut <dsarrut>
Fri, 29 Jan 2010 07:28:33 +0000 (07:28 +0000)
filters/clitkBinarizeImage.ggo [new file with mode: 0644]
filters/clitkBinarizeImageGenericFilter.cxx [new file with mode: 0644]
filters/clitkBinarizeImageGenericFilter.h [new file with mode: 0644]
filters/clitkBinarizeImageGenericFilter.txx [new file with mode: 0644]

diff --git a/filters/clitkBinarizeImage.ggo b/filters/clitkBinarizeImage.ggo
new file mode 100644 (file)
index 0000000..becf917
--- /dev/null
@@ -0,0 +1,14 @@
+#File clitkBinarizeImage.ggo
+Package "clitkBinarizeImage"
+version "1.0"
+purpose ""
+
+option "config"                -       "Config file"                     string        no
+option "verbose"       v       "Verbose"                         flag          off
+
+option "input"         i       "Input image filename"            string        yes
+option "output"        o       "Output image filename"           string        yes
+option "lower"         l       "Lower intensity (default=min)"   double        no
+option "upper"         u       "Upper intensity (default=max)"   double        no
+option "inside"        -       "Inside value"                    double        no      default="1"
+option "outside"       -       "Outside value"                   double        no      default="0"
diff --git a/filters/clitkBinarizeImageGenericFilter.cxx b/filters/clitkBinarizeImageGenericFilter.cxx
new file mode 100644 (file)
index 0000000..ca07df1
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef clitkBinarizeImageGenericFilter_cxx
+#define clitkBinarizeImageGenericFilter_cxx
+
+/* =================================================
+ * @file   clitkBinarizeImageGenericFilter.cxx
+ * @author Jef Vandemeulebroucke <jef@creatis.insa-lyon.fr>
+ * @date   29 june 2009
+ * 
+ * @brief 
+ * 
+ ===================================================*/
+
+#include "clitkBinarizeImageGenericFilter.h"
+
+#endif  //#define clitkBinarizeImageGenericFilter_cxx
diff --git a/filters/clitkBinarizeImageGenericFilter.h b/filters/clitkBinarizeImageGenericFilter.h
new file mode 100644 (file)
index 0000000..f35bc7a
--- /dev/null
@@ -0,0 +1,89 @@
+/*=========================================================================
+
+  Program:   clitk
+  Module:    $RCSfile: clitkBinarizeImageGenericFilter.h,v $
+  Language:  C++
+  Date:      $Date: 2010/01/29 07:28:33 $
+  Version:   $Revision: 1.1 $
+  Author :   Jef Vandemeulebroucke <jef@creatis.insa-lyon.fr>
+             David Sarrut (david.sarrut@creatis.insa-lyon.fr)
+
+  Copyright (C) 2008
+  Léon Bérard cancer center    http://oncora1.lyon.fnclcc.fr
+  CREATIS                      http://www.creatis.insa-lyon.fr
+
+  This program is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, version 3 of the License.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+  =========================================================================*/
+
+#ifndef CLITKBINARIZEIMAGEGENERICFILTER_H
+#define CLITKBINARIZEIMAGEGENERICFILTER_H
+
+// clitk include
+#include "clitkIO.h"
+#include "clitkCommon.h"
+#include "clitkImageToImageGenericFilter.h"
+
+// itk include
+#include "itkBinaryThresholdImageFilter.h"
+
+// std include
+#include <map>
+
+//--------------------------------------------------------------------
+namespace clitk 
+{
+  
+  template<class args_info_type>
+  class ITK_EXPORT BinarizeImageGenericFilter: 
+    public ImageToImageGenericFilter<BinarizeImageGenericFilter<args_info_type> >
+  {
+    
+  public:
+
+    //--------------------------------------------------------------------
+    BinarizeImageGenericFilter();
+
+    //--------------------------------------------------------------------
+    typedef BinarizeImageGenericFilter         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(BinarizeImageGenericFilter, 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 "clitkBinarizeImageGenericFilter.txx"
+#endif
+
+#endif // #define clitkBinarizeImageGenericFilter_h
diff --git a/filters/clitkBinarizeImageGenericFilter.txx b/filters/clitkBinarizeImageGenericFilter.txx
new file mode 100644 (file)
index 0000000..38f7725
--- /dev/null
@@ -0,0 +1,100 @@
+#ifndef clitkBinarizeImageGenericFilter_txx
+#define clitkBinarizeImageGenericFilter_txx
+
+/* =================================================
+ * @file   clitkBinarizeImageGenericFilter.txx
+ * @author Jef Vandemeulebroucke <jef@creatis.insa-lyon.fr>
+ * @date   29 june 2009
+ * 
+ * @brief 
+ * 
+ ===================================================*/
+
+namespace clitk
+{
+  
+  //--------------------------------------------------------------------
+  template<class args_info_type>
+  BinarizeImageGenericFilter<args_info_type>::BinarizeImageGenericFilter():
+    ImageToImageGenericFilter<Self>("Binarize") {
+    InitializeImageType<2>();
+    InitializeImageType<3>();
+  }
+  //--------------------------------------------------------------------
+
+
+  //--------------------------------------------------------------------
+  template<class args_info_type>
+  template<unsigned int Dim>
+  void BinarizeImageGenericFilter<args_info_type>::InitializeImageType() {      
+    ADD_IMAGE_TYPE(Dim, char);
+    ADD_IMAGE_TYPE(Dim, short);
+  }
+  //--------------------------------------------------------------------
+  
+
+  //--------------------------------------------------------------------
+  template<class args_info_type>
+  void BinarizeImageGenericFilter<args_info_type>::SetArgsInfo(const args_info_type & a) {
+    mArgsInfo=a;
+    SetIOVerbose(mArgsInfo.verbose_flag);
+
+    if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes();
+
+    if (mArgsInfo.input_given) {
+      SetInputFilename(mArgsInfo.input_arg);
+    }
+    if (mArgsInfo.output_given) {
+      SetOutputFilename(mArgsInfo.output_arg);
+    }
+  }
+  //--------------------------------------------------------------------
+
+  //--------------------------------------------------------------------
+  // Update with the number of dimensions and the pixeltype
+  //--------------------------------------------------------------------
+  template<class args_info_type>
+  template<class InputImageType>
+  void 
+  BinarizeImageGenericFilter<args_info_type>::UpdateWithInputImageType()
+  {
+
+    // Reading input
+    typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
+    
+    // Main filter
+    typedef typename InputImageType::PixelType PixelType;
+    typedef itk::Image<int, InputImageType::ImageDimension> OutputImageType;
+
+    // Filter
+    typedef itk::BinaryThresholdImageFilter<InputImageType, OutputImageType> BinaryThresholdImageFilterType;
+    typename BinaryThresholdImageFilterType::Pointer thresholdFilter=BinaryThresholdImageFilterType::New();
+    thresholdFilter->SetInput(input);
+    if(mArgsInfo.lower_given) thresholdFilter->SetLowerThreshold(static_cast<PixelType>(mArgsInfo.lower_arg));
+    if(mArgsInfo.upper_given) thresholdFilter->SetUpperThreshold(static_cast<PixelType>(mArgsInfo.upper_arg));
+
+    DD(mArgsInfo.lower_given);
+    DD(mArgsInfo.upper_given);
+    DD(mArgsInfo.lower_arg);
+    DD(mArgsInfo.upper_arg);
+
+    DD(mArgsInfo.inside_arg);
+    DD(mArgsInfo.outside_arg);
+    DD(mArgsInfo.inside_given);
+    DD(mArgsInfo.outside_given);
+
+    thresholdFilter->SetInsideValue(mArgsInfo.inside_arg);
+    thresholdFilter->SetOutsideValue(mArgsInfo.outside_arg);
+
+    thresholdFilter->Update();
+  
+    // Write/Save results
+    typename OutputImageType::Pointer outputImage = thresholdFilter->GetOutput();
+    this->template SetNextOutput<OutputImageType>(outputImage);
+  }
+  //--------------------------------------------------------------------
+
+
+}//end clitk
+#endif //#define clitkBinarizeImageGenericFilter_txx