1 /*-------------------------------------------------------------------------
3 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
4 l'Image). All rights reserved. See Doc/License.txt or
5 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
7 This software is distributed WITHOUT ANY WARRANTY; without even
8 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9 PURPOSE. See the above copyright notices for more information.
11 -------------------------------------------------------------------------*/
13 #ifndef clitkSplitImageGenericFilter_TXX
14 #define clitkSplitImageGenericFilter_TXX
16 //This is where you put the actual implementation
19 #include <itkExtractImageFilter.h>
22 //--------------------------------------------------------------------
23 template<unsigned int Dimension>
24 void clitk::SplitImageGenericFilter::UpdateWithDim(std::string PixelType, int Components) {
26 if (m_Verbose) std::cout << "Image was detected to be "<<Dimension<<"D and "<<Components<<" component(s) of "<< PixelType<<"..."<<std::endl;
30 if(PixelType == "short"){
31 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed short..." << std::endl;
32 UpdateWithDimAndPixelType<Dimension, signed short>();
34 else if(PixelType == "unsigned_short"){
35 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl;
36 UpdateWithDimAndPixelType<Dimension, unsigned short>();
39 else if (PixelType == "unsigned_char"){
40 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl;
41 UpdateWithDimAndPixelType<Dimension, unsigned char>();
44 else if (PixelType == "char"){
45 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl;
46 UpdateWithDimAndPixelType<Dimension, signed char>();
49 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl;
50 UpdateWithDimAndPixelType<Dimension, float>();
54 else if (Components==3)
56 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and 3D float (DVF)" << std::endl;
57 UpdateWithDimAndPixelType<Dimension, itk::Vector<float, Dimension> >();
59 else std::cerr<<"Number of components is "<<Components<<", not supported!"<<std::endl;
62 //--------------------------------------------------------------------
64 //--------------------------------------------------------------------
65 template<unsigned int Dimension, class PixelType>
66 void clitk::SplitImageGenericFilter::UpdateWithDimAndPixelType() {
69 typedef itk::Image<PixelType,Dimension> ImageType;
70 typedef itk::Image<PixelType,Dimension-1> OutputImageType;
71 typename ImageType::Pointer input = clitk::readImage<ImageType>(mInputFilenames[0], mIOVerbose);
72 typedef itk::ExtractImageFilter<ImageType,OutputImageType> FilterType;
73 typename FilterType::Pointer filter= FilterType::New();
75 filter->SetInput(input);
76 typename ImageType::SizeType size=input->GetLargestPossibleRegion().GetSize();
77 size[mSplitDimension]=0;
78 typename ImageType::RegionType extracted_region;
79 extracted_region.SetSize(size);
80 filter->SetExtractionRegion(extracted_region);
83 typename ImageType::IndexType index=input->GetLargestPossibleRegion().GetIndex();
84 std::string base_filename=GetOutputFilename();
85 unsigned int number_of_output_images=input->GetLargestPossibleRegion().GetSize()[mSplitDimension];
86 for (unsigned int i=0;i<number_of_output_images;i++)
88 std::ostringstream ss;
90 index[mSplitDimension]=i;
91 extracted_region.SetIndex(index);
92 filter->SetExtractionRegion(extracted_region);
94 SetOutputFilename(base_filename+"_"+ss.str()+".mhd");
95 typename OutputImageType::Pointer output=filter->GetOutput();
96 SetNextOutput<OutputImageType>(output);
99 //--------------------------------------------------------------------
101 #endif //#define clitkSplitImageGenericFilter_TXX