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);
87 return cast->GetOutput();
89 //--------------------------------------------------------------------
91 //--------------------------------------------------------------------
92 template<class ImageType>
93 void clitk::SplitImageGenericFilter::UpdateWithInputImageType()
97 typedef typename ImageType::PixelType PixelType;
98 typedef itk::Image<PixelType,ImageType::ImageDimension-1> OutputImageType;
99 typename ImageType::Pointer input = this->GetInput<ImageType>(0);
100 typedef itk::ExtractImageFilter<ImageType,OutputImageType> FilterType;
101 typename FilterType::Pointer filter= FilterType::New();
103 filter->SetInput(input);
104 typename ImageType::SizeType size=input->GetLargestPossibleRegion().GetSize();
105 size[mSplitDimension]=0;
106 typename ImageType::RegionType extracted_region;
107 extracted_region.SetSize(size);
108 #if ITK_VERSION_MAJOR >= 4
109 filter->SetDirectionCollapseToSubmatrix();
111 filter->SetExtractionRegion(extracted_region);
114 typename ImageType::IndexType index=input->GetLargestPossibleRegion().GetIndex();
115 std::string base_filename=GetOutputFilename();
116 unsigned int number_of_output_images=input->GetLargestPossibleRegion().GetSize()[mSplitDimension];
117 for (unsigned int i=0; i<number_of_output_images; i++) {
118 std::ostringstream ss;
119 ss << std::setfill('0') << std::setw((int)(log10(double(number_of_output_images))+1)) << i;
120 index[mSplitDimension]=i;
121 extracted_region.SetIndex(index);
122 filter->SetExtractionRegion(extracted_region);
125 PngConversion<OutputImageType> png;
126 SetOutputFilename(base_filename+"_"+ss.str()+".png");
127 typename PngConversion<OutputImageType>::OutputPngImagePointer output;
128 output = png.Do(this->m_Window, this->m_Level, filter->GetOutput());
129 this->template SetNextOutput<typename PngConversion<OutputImageType>::OutputPngImageType>(output);
132 SetOutputFilename(base_filename+"_"+ss.str()+".mhd");
133 SetNextOutput<OutputImageType>(filter->GetOutput());
137 //--------------------------------------------------------------------