1 #ifndef clitkBinarizeImageGenericFilter_txx
2 #define clitkBinarizeImageGenericFilter_txx
4 /* =================================================
5 * @file clitkBinarizeImageGenericFilter.txx
6 * @author Jef Vandemeulebroucke <jef@creatis.insa-lyon.fr>
11 ===================================================*/
16 //--------------------------------------------------------------------
17 template<class args_info_type>
18 BinarizeImageGenericFilter<args_info_type>::BinarizeImageGenericFilter():
19 ImageToImageGenericFilter<Self>("Binarize") {
20 InitializeImageType<2>();
21 InitializeImageType<3>();
22 InitializeImageType<4>();
24 //--------------------------------------------------------------------
27 //--------------------------------------------------------------------
28 template<class args_info_type>
29 template<unsigned int Dim>
30 void BinarizeImageGenericFilter<args_info_type>::InitializeImageType() {
31 ADD_IMAGE_TYPE(Dim, char);
32 ADD_IMAGE_TYPE(Dim, short);
33 ADD_IMAGE_TYPE(Dim, int);
34 ADD_IMAGE_TYPE(Dim, float);
36 //--------------------------------------------------------------------
39 //--------------------------------------------------------------------
40 template<class args_info_type>
41 void BinarizeImageGenericFilter<args_info_type>::SetArgsInfo(const args_info_type & a) {
43 SetIOVerbose(mArgsInfo.verbose_flag);
45 if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes();
47 if (mArgsInfo.input_given) {
48 SetInputFilename(mArgsInfo.input_arg);
50 if (mArgsInfo.output_given) {
51 SetOutputFilename(mArgsInfo.output_arg);
54 //--------------------------------------------------------------------
56 //--------------------------------------------------------------------
57 // Update with the number of dimensions and the pixeltype
58 //--------------------------------------------------------------------
59 template<class args_info_type>
60 template<class InputImageType>
62 BinarizeImageGenericFilter<args_info_type>::UpdateWithInputImageType()
66 typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
69 typedef typename InputImageType::PixelType PixelType;
70 typedef itk::Image<int, InputImageType::ImageDimension> OutputImageType;
73 typedef itk::BinaryThresholdImageFilter<InputImageType, OutputImageType> BinaryThresholdImageFilterType;
74 typename BinaryThresholdImageFilterType::Pointer thresholdFilter=BinaryThresholdImageFilterType::New();
75 thresholdFilter->SetInput(input);
76 if(mArgsInfo.lower_given) thresholdFilter->SetLowerThreshold(static_cast<PixelType>(mArgsInfo.lower_arg));
77 if(mArgsInfo.upper_given) thresholdFilter->SetUpperThreshold(static_cast<PixelType>(mArgsInfo.upper_arg));
79 DD(mArgsInfo.lower_given);
80 DD(mArgsInfo.upper_given);
81 DD(mArgsInfo.lower_arg);
82 DD(mArgsInfo.upper_arg);
84 DD(mArgsInfo.inside_arg);
85 DD(mArgsInfo.outside_arg);
86 DD(mArgsInfo.inside_given);
87 DD(mArgsInfo.outside_given);
89 thresholdFilter->SetInsideValue(mArgsInfo.inside_arg);
90 thresholdFilter->SetOutsideValue(mArgsInfo.outside_arg);
92 thresholdFilter->Update();
95 typename OutputImageType::Pointer outputImage = thresholdFilter->GetOutput();
96 this->template SetNextOutput<OutputImageType>(outputImage);
98 //--------------------------------------------------------------------
103 #endif //#define clitkBinarizeImageGenericFilter_txx