1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://www.centreleonberard.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
19 -------------------------------------------------------------------
20 * @file clitkSplitImageGenericFilter.cxx
21 * @author Joël Schaerer
25 -------------------------------------------------------------------*/
27 #include "clitkSplitImageGenericFilter.h"
28 #include <itkIntensityWindowingImageFilter.h>
29 //--------------------------------------------------------------------
30 clitk::SplitImageGenericFilter::SplitImageGenericFilter():
31 clitk::ImageToImageGenericFilter<Self>("SplitImage")
34 InitializeImageType<3>();
35 InitializeImageType<4>();
37 //--------------------------------------------------------------------
39 //--------------------------------------------------------------------
40 template<unsigned int Dim>
41 void clitk::SplitImageGenericFilter::InitializeImageType()
43 ADD_DEFAULT_IMAGE_TYPES(Dim);
44 ADD_VEC_IMAGE_TYPE(Dim, 3,float);
46 //--------------------------------------------------------------------
48 //--------------------------------------------------------------------
49 template <class ImageType>
50 typename clitk::SplitImageGenericFilter::PngConversion<ImageType>::OutputPngImagePointer
51 clitk::SplitImageGenericFilter::PngConversion<ImageType>::Do(double window,
55 static const unsigned int PixelDimension = itk::PixelTraits<typename ImageType::PixelType>::Dimension;
56 return this->Do(window, level, input, static_cast< PixelDimType<PixelDimension> *>(NULL) );
58 //--------------------------------------------------------------------
60 //--------------------------------------------------------------------
61 template <class ImageType>
62 template<unsigned int Dim>
63 typename clitk::SplitImageGenericFilter::PngConversion<ImageType>::OutputPngImagePointer
64 clitk::SplitImageGenericFilter::PngConversion<ImageType>::Do(double window,
69 clitkExceptionMacro("Png conversion is not implemented for vector fields");
72 //--------------------------------------------------------------------
74 //--------------------------------------------------------------------
75 template <class ImageType>
76 typename clitk::SplitImageGenericFilter::PngConversion<ImageType>::OutputPngImagePointer
77 clitk::SplitImageGenericFilter::PngConversion<ImageType>::Do(double window,
82 typedef itk::IntensityWindowingImageFilter< ImageType, OutputPngImageType > CastFilterType;
83 typename CastFilterType::Pointer cast = CastFilterType::New();
84 cast->SetWindowLevel(window, level);
85 cast->SetInput(input);
86 return cast->GetOutput();
88 //--------------------------------------------------------------------
90 //--------------------------------------------------------------------
91 template<class ImageType>
92 void clitk::SplitImageGenericFilter::UpdateWithInputImageType()
96 typedef typename ImageType::PixelType PixelType;
97 typedef itk::Image<PixelType,ImageType::ImageDimension-1> OutputImageType;
98 typename ImageType::Pointer input = this->GetInput<ImageType>(0);
99 typedef itk::ExtractImageFilter<ImageType,OutputImageType> FilterType;
100 typename FilterType::Pointer filter= FilterType::New();
102 filter->SetInput(input);
103 typename ImageType::SizeType size=input->GetLargestPossibleRegion().GetSize();
104 size[mSplitDimension]=0;
105 typename ImageType::RegionType extracted_region;
106 extracted_region.SetSize(size);
107 #if ITK_VERSION_MAJOR >= 4
108 filter->SetDirectionCollapseToSubmatrix();
110 filter->SetExtractionRegion(extracted_region);
113 typename ImageType::IndexType index=input->GetLargestPossibleRegion().GetIndex();
114 std::string base_filename=GetOutputFilename();
115 unsigned int number_of_output_images=input->GetLargestPossibleRegion().GetSize()[mSplitDimension];
116 for (unsigned int i=0; i<number_of_output_images; i++) {
117 std::ostringstream ss;
118 ss << std::setfill('0') << std::setw((int)(log10(double(number_of_output_images))+1)) << i;
119 index[mSplitDimension]=i;
120 extracted_region.SetIndex(index);
121 filter->SetExtractionRegion(extracted_region);
124 PngConversion<OutputImageType> png;
125 SetOutputFilename(base_filename+"_"+ss.str()+".png");
126 typename PngConversion<OutputImageType>::OutputPngImagePointer output;
127 output = png.Do(this->m_Window, this->m_Level, filter->GetOutput());
128 this->template SetNextOutput<typename PngConversion<OutputImageType>::OutputPngImageType>(output);
131 SetOutputFilename(base_filename+"_"+ss.str()+".mhd");
132 SetNextOutput<OutputImageType>(filter->GetOutput());
136 //--------------------------------------------------------------------