]> Creatis software - clitk.git/commitdiff
Merge branch 'master' into vectorImage
authortbaudier <thomas.baudier@creatis.insa-lyon.fr>
Mon, 17 Oct 2016 07:17:17 +0000 (09:17 +0200)
committertbaudier <thomas.baudier@creatis.insa-lyon.fr>
Mon, 17 Oct 2016 07:17:17 +0000 (09:17 +0200)
common/vvImageReader.cxx
common/vvImageReader.h
common/vvImageReader.txx
tools/CMakeLists.txt
tools/clitk4DImageToNVectorImage.cxx [new file with mode: 0644]
tools/clitk4DImageToNVectorImage.ggo [new file with mode: 0644]
tools/clitk4DImageToNVectorImageGenericFilter.cxx [new file with mode: 0644]
tools/clitk4DImageToNVectorImageGenericFilter.h [new file with mode: 0644]
tools/clitk4DImageToNVectorImageGenericFilter.txx [new file with mode: 0644]
tools/clitkNVectorImageTo4DImageGenericFilter.txx

index 2c094a8c3eda3cfb67e85acddafb9cceb1bf562c..0e4c22ba05b468522dace0bf3b08ee2412652d08 100644 (file)
@@ -60,6 +60,8 @@ void vvImageReader::Update(LoadedImageType type)
     reader->ReadImageInformation();
     if (mInputFilenames.size() > 1)
       Update(reader->GetNumberOfDimensions()+1,reader->GetComponentTypeAsString(reader->GetComponentType()),type);
+    else if (reader->GetNumberOfComponents() > 1 && type != VECTORFIELD && type != VECTORFIELDWITHTIME)
+      Update(reader->GetNumberOfDimensions()+1,reader->GetComponentTypeAsString(reader->GetComponentType()),VECTORPIXELIMAGE);
     else
       Update(reader->GetNumberOfDimensions(),reader->GetComponentTypeAsString(reader->GetComponentType()),type);
   }
index 4348e0fac7e131f38aca7ab3d1ccb47d7851902b..4dc3f409d3d193520439e534e90e17309fdd8d98 100644 (file)
@@ -36,6 +36,8 @@ public:
   MERGEDWITHTIME,
   VECTORFIELD,
   VECTORFIELDWITHTIME,
+  VECTORPIXELIMAGE,
+  VECTORPIXELIMAGEWITHTIME,
   UNDEFINEDIMAGETYPE
   } LoadedImageType;
 
index 551e42626ba7313a84bb687f2fe8322c78d93962..d1fddfb58639143a45b4b616be5d034880e93265 100644 (file)
@@ -24,6 +24,7 @@
 #include <itkImageSeriesReader.h>
 #include <itkImageToVTKImageFilter.h>
 #include <itkFlexibleVectorCastImageFilter.h>
+#include "itkVectorImageToImageAdaptor.h"
 
 #include <vtkTransform.h>
 
@@ -130,6 +131,81 @@ void vvImageReader::UpdateWithDimAndInputPixelType()
                 << "(slice #" << mSlice << ") " << err << std::endl;
       return;
     }
+  } else if (mType == VECTORPIXELIMAGE) {
+    mImage=vvImage::New();
+    typedef itk::VectorImage< InputPixelType, VImageDimension-1 > InputImageType;
+    typedef itk::ImageFileReader<InputImageType> ReaderType;
+    typedef itk::Image<InputPixelType, VImageDimension> OutputImageType;
+    typename ReaderType::Pointer reader = ReaderType::New();
+    reader->SetFileName(mInputFilenames[0]);
+    reader->Update();
+    typename InputImageType::Pointer input= reader->GetOutput();
+
+    typedef itk::VectorImageToImageAdaptor<InputPixelType, VImageDimension-1> ImageAdaptorType;
+    typename ImageAdaptorType::Pointer adaptor = ImageAdaptorType::New();
+    typename OutputImageType::Pointer output = OutputImageType::New();
+
+    adaptor->SetExtractComponentIndex(0);
+    adaptor->SetImage(input);
+
+    //Create the output
+    typename OutputImageType::IndexType index;
+    index.Fill(0);
+    typename OutputImageType::SizeType size;
+    size.Fill(input->GetNumberOfComponentsPerPixel());
+    typename OutputImageType::SpacingType spacing;
+    spacing.Fill(1);
+    typename OutputImageType::PointType origin;
+    origin.Fill(0);
+    for (unsigned int pixelDim=0; pixelDim<VImageDimension-1; ++pixelDim)
+    {
+      size[pixelDim]=adaptor->GetLargestPossibleRegion().GetSize(pixelDim);
+      spacing[pixelDim]=input->GetSpacing()[pixelDim];
+      origin[pixelDim]=input->GetOrigin()[pixelDim];
+    }
+    typename OutputImageType::RegionType region;
+    region.SetSize(size);
+    region.SetIndex(index);
+    output->SetRegions(region);
+    output->SetOrigin(origin);
+    output->SetSpacing(spacing);
+    output->Allocate();
+
+    //Copy each channel
+    for (unsigned int pixelDim=0; pixelDim<input->GetNumberOfComponentsPerPixel(); ++pixelDim)
+    {
+      adaptor->SetExtractComponentIndex(pixelDim);
+
+      itk::ImageRegionIterator<InputImageType> imageIterator(input,input->GetLargestPossibleRegion());
+
+      while(!imageIterator.IsAtEnd())
+      {
+        typename OutputImageType::IndexType indexVector;
+        indexVector.Fill(0);
+        for (unsigned int indexDim=0; indexDim<VImageDimension-1; ++indexDim)
+        {
+          indexVector[indexDim]=imageIterator.GetIndex().GetElement(indexDim);
+        }
+        indexVector[VImageDimension-1]=pixelDim;
+
+        output->SetPixel(indexVector, adaptor->GetPixel(imageIterator.GetIndex()));
+        ++imageIterator;
+      }
+    }
+
+    if (VImageDimension == 4)
+      mType == VECTORPIXELIMAGEWITHTIME;
+    else
+      mType == VECTORPIXELIMAGE;
+
+    try {
+      mImage = vvImageFromITK<VImageDimension,InputPixelType>(output, mType == VECTORPIXELIMAGEWITHTIME);
+      mImage->ComputeScalarRangeBase<InputPixelType, VImageDimension>(output);
+    } catch ( itk::ExceptionObject & err ) {
+      std::cerr << "Error while slicing " << mInputFilenames[0].c_str()
+                << " " << err << std::endl;
+      return;
+    }
   } else {
     if (mInputFilenames.size() > 1) {
       typedef itk::Image< InputPixelType, VImageDimension > InputImageType;
index 7333fabd0a7b2fc28dcbf39a929f47d12802882f..422d8f9a89300fb2c7f9fd007d3384fd1ad4d3b3 100644 (file)
@@ -249,11 +249,16 @@ if(CLITK_BUILD_TOOLS)
   target_link_libraries(clitkVectorImageToImage  clitkCommon)
   set(TOOLS_INSTALL ${TOOLS_INSTALL} clitkVectorImageToImage)
   
-   WRAP_GGO(clitkNVectorImageTo4DImage_GGO_C clitkNVectorImageTo4DImage.ggo)
+  WRAP_GGO(clitkNVectorImageTo4DImage_GGO_C clitkNVectorImageTo4DImage.ggo)
   add_executable(clitkNVectorImageTo4DImage  clitkNVectorImageTo4DImage.cxx clitkNVectorImageTo4DImageGenericFilter.cxx ${clitkNVectorImageTo4DImage_GGO_C})
   target_link_libraries(clitkNVectorImageTo4DImage  clitkCommon)
   set(TOOLS_INSTALL ${TOOLS_INSTALL} clitkNVectorImageTo4DImage)
 
+  WRAP_GGO(clitk4DImageToNVectorImage_GGO_C clitk4DImageToNVectorImage.ggo)
+  add_executable(clitk4DImageToNVectorImage  clitk4DImageToNVectorImage.cxx clitk4DImageToNVectorImageGenericFilter.cxx ${clitk4DImageToNVectorImage_GGO_C})
+  target_link_libraries(clitk4DImageToNVectorImage  clitkCommon)
+  set(TOOLS_INSTALL ${TOOLS_INSTALL} clitk4DImageToNVectorImage)
+
   add_executable(clitkMIP clitkMIP.cxx clitkMIPGenericFilter.cxx)
   target_link_libraries(clitkMIP clitkMIPLib clitkCommon)
   set(TOOLS_INSTALL ${TOOLS_INSTALL} clitkMIP)
diff --git a/tools/clitk4DImageToNVectorImage.cxx b/tools/clitk4DImageToNVectorImage.cxx
new file mode 100644 (file)
index 0000000..62bd49d
--- /dev/null
@@ -0,0 +1,51 @@
+/*=========================================================================
+  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   clitk4DImageToNVectorImage.cxx
+ * @author 
+ * @date   
+ * 
+ * @brief 
+ * 
+ ===================================================*/
+
+
+// clitk
+#include "clitk4DImageToNVectorImage_ggo.h"
+#include "clitkIO.h"
+#include "clitk4DImageToNVectorImageGenericFilter.h"
+
+
+//--------------------------------------------------------------------
+int main(int argc, char * argv[]) {
+
+  // Init command line
+  GGO(clitk4DImageToNVectorImage, args_info);
+  CLITK_INIT;
+
+  // Filter
+  clitk::FourDImageToNVectorImageGenericFilter::Pointer genericFilter=clitk::FourDImageToNVectorImageGenericFilter::New();
+  
+  genericFilter->SetArgsInfo(args_info);
+  genericFilter->Update();
+
+  return EXIT_SUCCESS;
+}// end main
+
+//--------------------------------------------------------------------
diff --git a/tools/clitk4DImageToNVectorImage.ggo b/tools/clitk4DImageToNVectorImage.ggo
new file mode 100644 (file)
index 0000000..7f0d9dc
--- /dev/null
@@ -0,0 +1,11 @@
+#File clitk4DImageToNVectorImage.ggo
+package "clitk4DImageToNVectorImage"
+version "1.0"
+purpose "Convert the 4th dimension of a 4D Image into a VectorPixel 3D Image"
+
+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
+
diff --git a/tools/clitk4DImageToNVectorImageGenericFilter.cxx b/tools/clitk4DImageToNVectorImageGenericFilter.cxx
new file mode 100644 (file)
index 0000000..d70af20
--- /dev/null
@@ -0,0 +1,71 @@
+/*=========================================================================
+  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 clitk4DImageToNVectorImageGenericFilter_cxx
+#define clitk4DImageToNVectorImageGenericFilter_cxx
+
+/* =================================================
+ * @file   clitk4DImageToNVectorImageGenericFilter.cxx
+ * @author 
+ * @date   
+ * 
+ * @brief 
+ * 
+ ===================================================*/
+
+#include "clitk4DImageToNVectorImageGenericFilter.h"
+
+
+namespace clitk
+{
+
+
+  //-----------------------------------------------------------
+  // Constructor
+  //-----------------------------------------------------------
+  FourDImageToNVectorImageGenericFilter::FourDImageToNVectorImageGenericFilter()
+  {
+    m_Verbose=false;
+    m_InputFileName="";
+  }
+
+
+  //-----------------------------------------------------------
+  // Update
+  //-----------------------------------------------------------
+  void FourDImageToNVectorImageGenericFilter::Update()
+  {
+    // Read the Dimension and PixelType
+    int Dimension, Components;
+    std::string PixelType;
+    ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType, Components);
+
+    // Call UpdateWithDim
+    if(Dimension==2) UpdateWithDim<2>(PixelType, Components);
+    else if(Dimension==3) UpdateWithDim<3>(PixelType, Components);
+    else if (Dimension==4)UpdateWithDim<4>(PixelType, Components); 
+    else 
+      {
+       std::cout<<"Error, Only for 2, 3 or 4  Dimensions!!!"<<std::endl ;
+       return;
+      }
+  }
+
+
+} //end clitk
+
+#endif  //#define clitk4DImageToNVectorImageGenericFilter_cxx
diff --git a/tools/clitk4DImageToNVectorImageGenericFilter.h b/tools/clitk4DImageToNVectorImageGenericFilter.h
new file mode 100644 (file)
index 0000000..2823cb7
--- /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 clitk4DImageToNVectorImageGenericFilter_h
+#define clitk4DImageToNVectorImageGenericFilter_h
+
+/* =================================================
+ * @file   clitk4DImageToNVectorImageGenericFilter.h
+ * @author 
+ * @date   
+ * 
+ * @brief 
+ * 
+ ===================================================*/
+
+
+// clitk include
+#include "clitkIO.h"
+#include "clitkCommon.h"
+#include "clitkImageCommon.h"
+#include "clitk4DImageToNVectorImage_ggo.h"
+
+//itk include
+#include "itkLightObject.h"
+
+namespace clitk 
+{
+
+
+  class ITK_EXPORT FourDImageToNVectorImageGenericFilter : public itk::LightObject
+  {
+  public:
+    //----------------------------------------
+    // ITK
+    //----------------------------------------
+    typedef FourDImageToNVectorImageGenericFilter                   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( 4DImageToNVectorImageGenericFilter, LightObject );
+
+
+    //----------------------------------------
+    // Typedefs
+    //----------------------------------------
+
+
+    //----------------------------------------
+    // Set & Get
+    //----------------------------------------    
+    void SetArgsInfo(const args_info_clitk4DImageToNVectorImage & a)
+    {
+      m_ArgsInfo=a;
+      m_Verbose=m_ArgsInfo.verbose_flag;
+      m_InputFileName=m_ArgsInfo.input_arg;
+    }
+    
+    
+    //----------------------------------------  
+    // Update
+    //----------------------------------------  
+    void Update();
+
+  protected:
+
+    //----------------------------------------  
+    // Constructor & Destructor
+    //----------------------------------------  
+    FourDImageToNVectorImageGenericFilter();
+    ~FourDImageToNVectorImageGenericFilter() {};
+
+    
+    //----------------------------------------  
+    // Templated members
+    //----------------------------------------  
+    template <unsigned int Dimension>  void UpdateWithDim(std::string PixelType, unsigned int Components);
+    template <unsigned int Dimension, class PixelType>  void UpdateWithDimAndPixelType();
+
+
+    //----------------------------------------  
+    // Data members
+    //----------------------------------------
+    args_info_clitk4DImageToNVectorImage m_ArgsInfo;
+    bool m_Verbose;
+    std::string m_InputFileName;
+
+  };
+
+
+} // end namespace clitk
+
+#ifndef ITK_MANUAL_INSTANTIATION
+#include "clitk4DImageToNVectorImageGenericFilter.txx"
+#endif
+
+#endif // #define clitk4DImageToNVectorImageGenericFilter_h
diff --git a/tools/clitk4DImageToNVectorImageGenericFilter.txx b/tools/clitk4DImageToNVectorImageGenericFilter.txx
new file mode 100644 (file)
index 0000000..554cec7
--- /dev/null
@@ -0,0 +1,134 @@
+/*=========================================================================
+  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 clitk4DImageToNVectorImageGenericFilter_txx
+#define clitk4DImageToNVectorImageGenericFilter_txx
+
+/* =================================================
+ * @file   clitk4DImageToNVectorImageGenericFilter.txx
+ * @author 
+ * @date   
+ * 
+ * @brief 
+ * 
+ ===================================================*/
+
+#include "itkComposeImageFilter.h"
+#include "itkExtractImageFilter.h"
+
+namespace clitk
+{
+
+  //-------------------------------------------------------------------
+  // Update with the number of dimensions
+  //-------------------------------------------------------------------
+  template<unsigned int Dimension>
+  void 
+  FourDImageToNVectorImageGenericFilter::UpdateWithDim(std::string PixelType, unsigned int Components)
+  {
+    if (m_Verbose) std::cout << "Image was detected to be "<<Dimension<<"D and "<< PixelType<<"..."<<std::endl;
+
+    if (PixelType == "short") {
+      UpdateWithDimAndPixelType<Dimension, short>();
+    } else if (PixelType == "unsigned short") {
+      UpdateWithDimAndPixelType<Dimension, unsigned short>();
+    } else if (PixelType == "unsigned_short") {
+      UpdateWithDimAndPixelType<Dimension, unsigned short>();
+    } else if (PixelType == "char") {
+      UpdateWithDimAndPixelType<Dimension, char>();
+    } else if (PixelType == "unsigned_char") {
+      UpdateWithDimAndPixelType<Dimension, unsigned char>();
+    } else if (PixelType == "int") {
+      UpdateWithDimAndPixelType<Dimension, int>();
+    } else if (PixelType == "unsigned_int") {
+      UpdateWithDimAndPixelType<Dimension, unsigned int>();
+    } else if (PixelType == "double") {
+      UpdateWithDimAndPixelType<Dimension, double>();
+    } else if (PixelType == "float") {
+      UpdateWithDimAndPixelType<Dimension, float>();
+    } else {
+      std::cerr << "Error, pixel type : \"" << PixelType << "\" unknown !" << std::endl;
+    }
+  }
+
+
+  //-------------------------------------------------------------------
+  // Update with the number of dimensions and the pixeltype
+  //-------------------------------------------------------------------
+  template <unsigned int Dimension, class  PixelType> 
+  void 
+  FourDImageToNVectorImageGenericFilter::UpdateWithDimAndPixelType()
+  {
+    // ImageTypes
+    typedef itk::Image<PixelType, Dimension> InputImageType;
+    typedef itk::Image<PixelType, Dimension-1> MedianImageType;
+    typedef itk::VectorImage<PixelType, Dimension-1> OutputImageType;
+
+    // Read the input
+    typedef itk::ImageFileReader<InputImageType> InputReaderType;
+    typename InputReaderType::Pointer reader = InputReaderType::New();
+    reader->SetFileName(m_InputFileName);
+    reader->Update();
+    typename InputImageType::Pointer input= reader->GetOutput();
+    std::string fileName=m_ArgsInfo.output_arg;
+
+    //Filter
+    typedef itk::ComposeImageFilter<MedianImageType> ImageToVectorImageFilterType;
+    typename ImageToVectorImageFilterType::Pointer imageToVectorImageFilter = ImageToVectorImageFilterType::New();
+    typedef itk::ExtractImageFilter<InputImageType, MedianImageType> ExtractFilterType;
+    typename ExtractFilterType::Pointer extractFilter = ExtractFilterType::New();
+    extractFilter->SetDirectionCollapseToSubmatrix();
+    typedef itk::ImageFileWriter<OutputImageType> WriterType;
+    typename WriterType::Pointer writer = WriterType::New();
+
+    extractFilter->SetInput(input);
+    typename InputImageType::SizeType size;
+    for (unsigned int nbDimension=0; nbDimension<Dimension-1; ++nbDimension)
+    {
+        size[nbDimension] = input->GetLargestPossibleRegion().GetSize(nbDimension);
+    }
+    size[Dimension-1] = 0;
+    typename MedianImageType::Pointer tempImage = MedianImageType::New();
+    
+    //Extract All "time" slices
+    for (unsigned int nbSlice=0; nbSlice<input->GetLargestPossibleRegion().GetSize(Dimension-1); ++nbSlice)
+    {
+      typename InputImageType::RegionType desiredRegion;
+      typename InputImageType::IndexType index;
+      index.Fill(0);
+      index[Dimension-1]=nbSlice;
+      desiredRegion.SetSize(size);
+      extractFilter->SetInput(input);
+      desiredRegion.SetIndex(index);
+      extractFilter->SetExtractionRegion(desiredRegion);
+      extractFilter->Update();
+      tempImage = extractFilter->GetOutput();
+      tempImage->DisconnectPipeline();
+      extractFilter->Update();
+      imageToVectorImageFilter->SetInput(nbSlice, tempImage);
+    }
+
+    imageToVectorImageFilter->Update();
+
+    // Output
+    writer->SetInput(imageToVectorImageFilter->GetOutput());
+    writer->SetFileName(fileName);
+    writer->Update();
+  }
+}//end clitk
+#endif //#define clitk4DImageToNVectorImageGenericFilter_txx
index 932b9acba309a223107b3595f686ca9ab317760b..06d5792566198e8888c753461f254de72775c595 100644 (file)
@@ -28,7 +28,6 @@
  ===================================================*/
 
 #include "itkVectorImageToImageAdaptor.h"
-#include <sstream>
 
 namespace clitk
 {