add_executable(clitkVectorImageToImage clitkVectorImageToImage.cxx clitkVectorImageToImageGenericFilter.cxx ${clitkVectorImageToImage_GGO_C})
target_link_libraries(clitkVectorImageToImage clitkCommon)
set(TOOLS_INSTALL ${TOOLS_INSTALL} clitkVectorImageToImage)
+
+ 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)
add_executable(clitkMIP clitkMIP.cxx clitkMIPGenericFilter.cxx)
target_link_libraries(clitkMIP clitkMIPLib clitkCommon)
--- /dev/null
+/*=========================================================================
+ 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 clitkNVectorImageTo4DImage.cxx
+ * @author
+ * @date
+ *
+ * @brief
+ *
+ ===================================================*/
+
+
+// clitk
+#include "clitkNVectorImageTo4DImage_ggo.h"
+#include "clitkIO.h"
+#include "clitkNVectorImageTo4DImageGenericFilter.h"
+
+
+//--------------------------------------------------------------------
+int main(int argc, char * argv[]) {
+
+ // Init command line
+ GGO(clitkNVectorImageTo4DImage, args_info);
+ CLITK_INIT;
+
+ // Filter
+ clitk::NVectorImageTo4DImageGenericFilter::Pointer genericFilter=clitk::NVectorImageTo4DImageGenericFilter::New();
+
+ genericFilter->SetArgsInfo(args_info);
+ genericFilter->Update();
+
+ return EXIT_SUCCESS;
+}// end main
+
+//--------------------------------------------------------------------
--- /dev/null
+#File clitkNVectorImageTo4DImage.ggo
+package "clitkNVectorImageTo4DImage"
+version "1.0"
+purpose "Convert all pixel channels of the image into a 4D 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
+
--- /dev/null
+/*=========================================================================
+ 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 clitkNVectorImageTo4DImageGenericFilter_cxx
+#define clitkNVectorImageTo4DImageGenericFilter_cxx
+
+/* =================================================
+ * @file clitkNVectorImageTo4DImageGenericFilter.cxx
+ * @author
+ * @date
+ *
+ * @brief
+ *
+ ===================================================*/
+
+#include "clitkNVectorImageTo4DImageGenericFilter.h"
+
+
+namespace clitk
+{
+
+
+ //-----------------------------------------------------------
+ // Constructor
+ //-----------------------------------------------------------
+ NVectorImageTo4DImageGenericFilter::NVectorImageTo4DImageGenericFilter()
+ {
+ m_Verbose=false;
+ m_InputFileName="";
+ }
+
+
+ //-----------------------------------------------------------
+ // Update
+ //-----------------------------------------------------------
+ void NVectorImageTo4DImageGenericFilter::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 clitkNVectorImageTo4DImageGenericFilter_cxx
--- /dev/null
+/*=========================================================================
+ 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 clitkNVectorImageTo4DImageGenericFilter_h
+#define clitkNVectorImageTo4DImageGenericFilter_h
+
+/* =================================================
+ * @file clitkNVectorImageTo4DImageGenericFilter.h
+ * @author
+ * @date
+ *
+ * @brief
+ *
+ ===================================================*/
+
+
+// clitk include
+#include "clitkIO.h"
+#include "clitkCommon.h"
+#include "clitkImageCommon.h"
+#include "clitkNVectorImageTo4DImage_ggo.h"
+
+//itk include
+#include "itkLightObject.h"
+
+namespace clitk
+{
+
+
+ class ITK_EXPORT NVectorImageTo4DImageGenericFilter : public itk::LightObject
+ {
+ public:
+ //----------------------------------------
+ // ITK
+ //----------------------------------------
+ typedef NVectorImageTo4DImageGenericFilter 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( NVectorImageTo4DImageGenericFilter, LightObject );
+
+
+ //----------------------------------------
+ // Typedefs
+ //----------------------------------------
+
+
+ //----------------------------------------
+ // Set & Get
+ //----------------------------------------
+ void SetArgsInfo(const args_info_clitkNVectorImageTo4DImage & a)
+ {
+ m_ArgsInfo=a;
+ m_Verbose=m_ArgsInfo.verbose_flag;
+ m_InputFileName=m_ArgsInfo.input_arg;
+ }
+
+
+ //----------------------------------------
+ // Update
+ //----------------------------------------
+ void Update();
+
+ protected:
+
+ //----------------------------------------
+ // Constructor & Destructor
+ //----------------------------------------
+ NVectorImageTo4DImageGenericFilter();
+ ~NVectorImageTo4DImageGenericFilter() {};
+
+
+ //----------------------------------------
+ // 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_clitkNVectorImageTo4DImage m_ArgsInfo;
+ bool m_Verbose;
+ std::string m_InputFileName;
+
+ };
+
+
+} // end namespace clitk
+
+#ifndef ITK_MANUAL_INSTANTIATION
+#include "clitkNVectorImageTo4DImageGenericFilter.txx"
+#endif
+
+#endif // #define clitkNVectorImageTo4DImageGenericFilter_h
--- /dev/null
+/*=========================================================================
+ 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 clitkNVectorImageTo4DImageGenericFilter_txx
+#define clitkNVectorImageTo4DImageGenericFilter_txx
+
+/* =================================================
+ * @file clitkNVectorImageTo4DImageGenericFilter.txx
+ * @author
+ * @date
+ *
+ * @brief
+ *
+ ===================================================*/
+
+#include "itkVectorImageToImageAdaptor.h"
+#include <sstream>
+
+namespace clitk
+{
+
+ //-------------------------------------------------------------------
+ // Update with the number of dimensions
+ //-------------------------------------------------------------------
+ template<unsigned int Dimension>
+ void
+ NVectorImageTo4DImageGenericFilter::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
+ NVectorImageTo4DImageGenericFilter::UpdateWithDimAndPixelType()
+ {
+ // ImageTypes
+ typedef itk::VectorImage<PixelType, Dimension> InputImageType;
+ typedef itk::Image<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();
+
+ //Filter
+ typedef itk::VectorImageToImageAdaptor<PixelType, Dimension> ImageAdaptorType;
+ typedef itk::ImageFileWriter<OutputImageType> WriterType;
+ typename ImageAdaptorType::Pointer adaptor = ImageAdaptorType::New();
+ typename OutputImageType::Pointer output = OutputImageType::New();
+ typename WriterType::Pointer writer = WriterType::New();
+
+ adaptor->SetExtractComponentIndex(0);
+ adaptor->SetImage(input);
+ std::string fileName=m_ArgsInfo.output_arg;
+
+ //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<Dimension; ++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();
+ writer->SetInput(output);
+
+ //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<Dimension; ++indexDim)
+ {
+ indexVector[indexDim]=imageIterator.GetIndex().GetElement(indexDim);
+ }
+ indexVector[Dimension]=pixelDim;
+
+ output->SetPixel(indexVector, adaptor->GetPixel(imageIterator.GetIndex()));
+ ++imageIterator;
+ }
+ }
+ // Output
+ writer->SetFileName(fileName);
+ writer->Update();
+ }
+}//end clitk
+
+#endif //#define clitkNVectorImageTo4DImageGenericFilter_txx