]> Creatis software - clitk.git/commitdiff
jacobian image filter
authorRomulo Pinho <pinho@lyon.fnclcc.fr>
Tue, 21 Jun 2011 18:10:28 +0000 (20:10 +0200)
committerRomulo Pinho <pinho@lyon.fnclcc.fr>
Tue, 21 Jun 2011 18:10:28 +0000 (20:10 +0200)
- calculate the jacobian of a vector field

tools/CMakeLists.txt
tools/clitkJacobianImage.cxx [new file with mode: 0644]
tools/clitkJacobianImage.ggo [new file with mode: 0644]
tools/clitkJacobianImageGenericFilter.cxx [new file with mode: 0644]
tools/clitkJacobianImageGenericFilter.h [new file with mode: 0644]
tools/clitkJacobianImageGenericFilter.txx [new file with mode: 0644]

index 837c4df15bb19f67d895191c8cceb8b7f7819361..65765721c138e8b4d39562974aaa2a744bea7030 100644 (file)
@@ -259,8 +259,8 @@ IF (CLITK_BUILD_TOOLS)
   ADD_EXECUTABLE(clitkMakeSphereImage clitkMakeSphereImage.cxx) # clitkLineProfileGenericFilter.cxx ${clitkLineProfile_GGO_C})
   TARGET_LINK_LIBRARIES(clitkMakeSphereImage clitkCommon ${ITK_LIBRARIES})
 
-  #WRAP_GGO(clitkLineProfile_GGO_C clitkLineProfile.ggo)
-  ADD_EXECUTABLE(clitkJacobianImage clitkJacobianImage.cxx) # clitkLineProfileGenericFilter.cxx ${clitkLineProfile_GGO_C})
+  WRAP_GGO(clitkJacobianImage_GGO_C clitkJacobianImage.ggo)
+  ADD_EXECUTABLE(clitkJacobianImage clitkJacobianImage.cxx clitkJacobianImageGenericFilter.cxx ${clitkJacobianImage_GGO_C})
   TARGET_LINK_LIBRARIES(clitkJacobianImage clitkCommon ${ITK_LIBRARIES})
   
   IF(CLITK_EXPERIMENTAL)
diff --git a/tools/clitkJacobianImage.cxx b/tools/clitkJacobianImage.cxx
new file mode 100644 (file)
index 0000000..af36184
--- /dev/null
@@ -0,0 +1,16 @@
+#include "clitkJacobianImage_ggo.h"
+#include "clitkJacobianImageGenericFilter.h"
+
+int main(int argc, char** argv) {
+  // Init command line
+  GGO(clitkJacobianImage, args_info);
+
+  // Filter
+  typedef clitk::JacobianImageGenericFilter<args_info_clitkJacobianImage> FilterType;
+  FilterType::Pointer genericFilter = FilterType::New();
+
+  genericFilter->SetArgsInfo(args_info);
+  genericFilter->Update();
+
+  return EXIT_SUCCESS;
+}
\ No newline at end of file
diff --git a/tools/clitkJacobianImage.ggo b/tools/clitkJacobianImage.ggo
new file mode 100644 (file)
index 0000000..26a71ff
--- /dev/null
@@ -0,0 +1,12 @@
+#File clitkJacobianImage.ggo
+#Author: Rômulo Pinho <pinho@lyon.fnclcc.fr>
+#Date : Tue 21 June 16.10 
+
+package "clitk"
+version "Read a DVF and calculate the corresponding jacobian image."
+
+option "config"       - "Config file"               string    no
+option "verbose"      v     "Verbose"               flag    off
+
+option "input"        i     "Input VF filename"             string    yes
+option "output"       o     "Output VF filename"              string    yes
diff --git a/tools/clitkJacobianImageGenericFilter.cxx b/tools/clitkJacobianImageGenericFilter.cxx
new file mode 100644 (file)
index 0000000..b5f7cd4
--- /dev/null
@@ -0,0 +1,23 @@
+/*=========================================================================
+  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
+===========================================================================*/
+#include "clitkJacobianImageGenericFilter.h"
+
+namespace clitk
+{
+
+}
\ No newline at end of file
diff --git a/tools/clitkJacobianImageGenericFilter.h b/tools/clitkJacobianImageGenericFilter.h
new file mode 100644 (file)
index 0000000..f549719
--- /dev/null
@@ -0,0 +1,115 @@
+/*=========================================================================
+  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 clitkJacobianImageGenericFilter_h
+#define clitkJacobianImageGenericFilter_h
+
+/* =================================================
+ * @file   clitkJacobianImageGenericFilter.h
+ * @author 
+ * @date   
+ * 
+ * @brief 
+ * 
+ ===================================================*/
+
+
+// clitk include
+#include "clitkIO.h"
+#include "clitkCommon.h"
+#include "clitkJacobianImage_ggo.h"
+
+//itk include
+#include "itkLightObject.h"
+#include "itkInverseDeformationFieldImageFilter.h"
+
+namespace clitk 
+{
+
+  template<class args_info_type>
+  class ITK_EXPORT JacobianImageGenericFilter : public itk::LightObject
+  {
+  public:
+    //----------------------------------------
+    // ITK
+    //----------------------------------------
+    typedef JacobianImageGenericFilter                   Self;
+    typedef itk::LightObject                   Superclass;
+    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( JacobianImageGenericFilter, LightObject );
+
+
+    //----------------------------------------
+    // Typedefs
+    //----------------------------------------
+
+
+    //----------------------------------------
+    // Set & Get
+    //----------------------------------------    
+    void SetArgsInfo(const args_info_type & a)
+    {
+      m_ArgsInfo=a;
+      m_Verbose=m_ArgsInfo.verbose_flag;
+      m_InputFileName=m_ArgsInfo.input_arg;
+    }
+    
+    
+    //----------------------------------------  
+    // Update
+    //----------------------------------------  
+    void Update();
+
+  protected:
+
+    //----------------------------------------  
+    // Constructor & Destructor
+    //----------------------------------------  
+    JacobianImageGenericFilter();
+    ~JacobianImageGenericFilter() {};
+
+    
+    //----------------------------------------  
+    // Templated members
+    //----------------------------------------  
+    template <unsigned int Dimension>  void UpdateWithDim(std::string PixelType);
+    template <unsigned int Dimension, class PixelType>  void UpdateWithDimAndPixelType();
+
+
+    //----------------------------------------  
+    // Data members
+    //----------------------------------------
+    args_info_type m_ArgsInfo;
+    bool m_Verbose;
+    std::string m_InputFileName;
+
+  };
+
+
+} // end namespace clitk
+
+#ifndef ITK_MANUAL_INSTANTIATION
+#include "clitkJacobianImageGenericFilter.txx"
+#endif
+
+#endif // #define clitkJacobianImageGenericFilter_h
diff --git a/tools/clitkJacobianImageGenericFilter.txx b/tools/clitkJacobianImageGenericFilter.txx
new file mode 100644 (file)
index 0000000..2189411
--- /dev/null
@@ -0,0 +1,155 @@
+/*=========================================================================
+  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 clitkJacobianImageGenericFilter_txx
+#define clitkJacobianImageGenericFilter_txx
+
+/* =================================================
+ * @file   clitkJacobianImageGenericFilter.txx
+ * @author
+ * @date
+ *
+ * @brief
+ *
+ ===================================================*/
+
+#include "clitkImageCommon.h"
+#include "itkDeformationFieldJacobianDeterminantFilter.h"
+#include "itkImage.h"
+#include "itkImageFileReader.h"
+#include "itkImageFileWriter.h"
+#include "itkVector.h"
+#include "itkNormalizeImageFilter.h"
+
+namespace clitk
+{
+
+//-----------------------------------------------------------
+// Constructor
+//-----------------------------------------------------------
+template<class args_info_type>
+JacobianImageGenericFilter<args_info_type>::JacobianImageGenericFilter()
+{
+  m_Verbose=false;
+  m_InputFileName="";
+}
+
+
+//-----------------------------------------------------------
+// Update
+//-----------------------------------------------------------
+template<class args_info_type>
+void JacobianImageGenericFilter<args_info_type>::Update()
+{
+  // Read the Dimension and PixelType
+  int Dimension;
+  std::string PixelType;
+  ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType);
+
+
+  // Call UpdateWithDim
+  if(Dimension==2) UpdateWithDim<2>(PixelType);
+  else if(Dimension==3) UpdateWithDim<3>(PixelType);
+  // else if (Dimension==4)UpdateWithDim<4>(PixelType);
+  else {
+    std::cout<<"Error, Only for 2 or 3  Dimensions!!!"<<std::endl ;
+    return;
+  }
+}
+
+//-------------------------------------------------------------------
+// Update with the number of dimensions
+//-------------------------------------------------------------------
+template<class args_info_type>
+template<unsigned int Dimension>
+void
+JacobianImageGenericFilter<args_info_type>::UpdateWithDim(std::string PixelType)
+{
+  if (m_Verbose) std::cout << "Image was detected to be "<<Dimension<<"D and "<< PixelType<<"..."<<std::endl;
+
+  //    if(PixelType == "short"){
+  //       if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed short..." << std::endl;
+  //       UpdateWithDimAndPixelType<Dimension, signed short>();
+  //     }
+  //    else if(PixelType == "unsigned_short"){
+  //       if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl;
+  //       UpdateWithDimAndPixelType<Dimension, unsigned short>();
+  //     }
+
+  //     else if (PixelType == "unsigned_char"){
+  //       if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl;
+  //       UpdateWithDimAndPixelType<Dimension, unsigned char>();
+  //     }
+
+  //     else if (PixelType == "char"){
+  //       if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl;
+  //       UpdateWithDimAndPixelType<Dimension, signed char>();
+  //     }
+  //  else {
+  if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and float..." << std::endl;
+  UpdateWithDimAndPixelType<Dimension, itk::Vector<float, Dimension> >();
+  // }
+}
+
+
+//-------------------------------------------------------------------
+// Update with the number of dimensions and the pixeltype
+//-------------------------------------------------------------------
+template<class args_info_type>
+template <unsigned int Dimension, class  PixelType>
+void
+JacobianImageGenericFilter<args_info_type>::UpdateWithDimAndPixelType()
+{
+  std::string vfield_file = m_ArgsInfo.input_arg;
+  
+  const unsigned int dim = Dimension;
+  typedef itk::Vector<double, dim> VectorType;
+  typedef itk::Image<VectorType, dim> VectorFieldType;
+  typedef itk::ImageFileReader<VectorFieldType> VectorFieldReaderType;
+  
+  typename VectorFieldReaderType::Pointer vfield_reader = VectorFieldReaderType::New();
+  vfield_reader->SetFileName(vfield_file.c_str());
+  
+  typedef double OutputPixelType;
+  typedef itk::Image<OutputPixelType, dim> ImageType;
+  //typedef itk::DeformationFieldJacobianDeterminantFilter<VectorFieldType, PixelType, ImageType> JacobianFilterType;
+  typedef itk::DisplacementFieldJacobianDeterminantFilter<VectorFieldType, OutputPixelType, ImageType> JacobianFilterType;
+
+  typename VectorFieldType::Pointer vfield = vfield_reader->GetOutput();
+  typename JacobianFilterType::Pointer jac = JacobianFilterType::New();
+  jac->SetInput(vfield);
+  jac->Update();
+  
+  typedef itk::NormalizeImageFilter<ImageType, ImageType> NormalizeFilterType;
+  typename NormalizeFilterType::Pointer normalize = NormalizeFilterType::New();
+  normalize->SetInput(jac->GetOutput());
+  normalize->Update();
+
+  typedef itk::ImageFileWriter<ImageType> ImageFileWriterType;
+  typename ImageFileWriterType::Pointer image_writer = ImageFileWriterType::New();
+  
+  std::string image_file = m_ArgsInfo.output_arg;
+  image_writer->SetFileName(image_file.c_str());
+  image_writer->SetInput(jac->GetOutput());
+  image_writer->Update();
+  
+}
+
+
+}//end clitk
+
+#endif //#define clitkJacobianImageGenericFilter_txx