From 312bd5e9ddcdbe15d16684c2a392f84121b67b4e Mon Sep 17 00:00:00 2001 From: Romulo Pinho Date: Tue, 21 Jun 2011 20:10:28 +0200 Subject: [PATCH] jacobian image filter - calculate the jacobian of a vector field --- tools/CMakeLists.txt | 4 +- tools/clitkJacobianImage.cxx | 16 +++ tools/clitkJacobianImage.ggo | 12 ++ tools/clitkJacobianImageGenericFilter.cxx | 23 ++++ tools/clitkJacobianImageGenericFilter.h | 115 ++++++++++++++++ tools/clitkJacobianImageGenericFilter.txx | 155 ++++++++++++++++++++++ 6 files changed, 323 insertions(+), 2 deletions(-) create mode 100644 tools/clitkJacobianImage.cxx create mode 100644 tools/clitkJacobianImage.ggo create mode 100644 tools/clitkJacobianImageGenericFilter.cxx create mode 100644 tools/clitkJacobianImageGenericFilter.h create mode 100644 tools/clitkJacobianImageGenericFilter.txx diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 837c4df..6576572 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -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 index 0000000..af36184 --- /dev/null +++ b/tools/clitkJacobianImage.cxx @@ -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 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 index 0000000..26a71ff --- /dev/null +++ b/tools/clitkJacobianImage.ggo @@ -0,0 +1,12 @@ +#File clitkJacobianImage.ggo +#Author: Rômulo Pinho +#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 index 0000000..b5f7cd4 --- /dev/null +++ b/tools/clitkJacobianImageGenericFilter.cxx @@ -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 index 0000000..f549719 --- /dev/null +++ b/tools/clitkJacobianImageGenericFilter.h @@ -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 ITK_EXPORT JacobianImageGenericFilter : public itk::LightObject + { + public: + //---------------------------------------- + // ITK + //---------------------------------------- + typedef JacobianImageGenericFilter Self; + typedef itk::LightObject Superclass; + typedef itk::SmartPointer Pointer; + typedef itk::SmartPointer 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 void UpdateWithDim(std::string PixelType); + template 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 index 0000000..2189411 --- /dev/null +++ b/tools/clitkJacobianImageGenericFilter.txx @@ -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 +JacobianImageGenericFilter::JacobianImageGenericFilter() +{ + m_Verbose=false; + m_InputFileName=""; +} + + +//----------------------------------------------------------- +// Update +//----------------------------------------------------------- +template +void JacobianImageGenericFilter::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!!!"< +template +void +JacobianImageGenericFilter::UpdateWithDim(std::string PixelType) +{ + if (m_Verbose) std::cout << "Image was detected to be "<(); + // } + // else if(PixelType == "unsigned_short"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + + // else if (PixelType == "unsigned_char"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + + // else if (PixelType == "char"){ + // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl; + // UpdateWithDimAndPixelType(); + // } + // else { + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl; + UpdateWithDimAndPixelType >(); + // } +} + + +//------------------------------------------------------------------- +// Update with the number of dimensions and the pixeltype +//------------------------------------------------------------------- +template +template +void +JacobianImageGenericFilter::UpdateWithDimAndPixelType() +{ + std::string vfield_file = m_ArgsInfo.input_arg; + + const unsigned int dim = Dimension; + typedef itk::Vector VectorType; + typedef itk::Image VectorFieldType; + typedef itk::ImageFileReader VectorFieldReaderType; + + typename VectorFieldReaderType::Pointer vfield_reader = VectorFieldReaderType::New(); + vfield_reader->SetFileName(vfield_file.c_str()); + + typedef double OutputPixelType; + typedef itk::Image ImageType; + //typedef itk::DeformationFieldJacobianDeterminantFilter JacobianFilterType; + typedef itk::DisplacementFieldJacobianDeterminantFilter JacobianFilterType; + + typename VectorFieldType::Pointer vfield = vfield_reader->GetOutput(); + typename JacobianFilterType::Pointer jac = JacobianFilterType::New(); + jac->SetInput(vfield); + jac->Update(); + + typedef itk::NormalizeImageFilter NormalizeFilterType; + typename NormalizeFilterType::Pointer normalize = NormalizeFilterType::New(); + normalize->SetInput(jac->GetOutput()); + normalize->Update(); + + typedef itk::ImageFileWriter 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 -- 2.45.1