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://oncora1.lyon.fnclcc.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 ======================================================================-====*/
18 #ifndef clitkFooImageGenericFilter_txx
19 #define clitkFooImageGenericFilter_txx
21 /* =================================================
22 * @file clitkFooImageGenericFilter.txx
23 * @author Jef Vandemeulebroucke <jef@creatis.insa-lyon.fr>
28 ===================================================*/
31 #include "itkBinaryThresholdImageFilter.h"
32 #include "itkMaskImageFilter.h"
33 #include "itkMaskNegatedImageFilter.h"
34 #include <clitkCommon.h>
40 //--------------------------------------------------------------------
41 template<class args_info_type>
42 FooImageGenericFilter<args_info_type>::FooImageGenericFilter():
43 ImageToImageGenericFilter<Self>("FooImage") {
44 InitializeImageType<2>();
45 InitializeImageType<3>();
46 InitializeImageType<4>();
48 //--------------------------------------------------------------------
51 //--------------------------------------------------------------------
52 template<class args_info_type>
53 template<unsigned int Dim>
54 void FooImageGenericFilter<args_info_type>::InitializeImageType() {
55 ADD_IMAGE_TYPE(Dim, char);
56 ADD_IMAGE_TYPE(Dim, uchar);
57 ADD_IMAGE_TYPE(Dim, short);
58 ADD_IMAGE_TYPE(Dim, ushort);
59 ADD_IMAGE_TYPE(Dim, int);
60 ADD_IMAGE_TYPE(Dim, uint16);
61 ADD_IMAGE_TYPE(Dim, float);
62 ADD_IMAGE_TYPE(Dim, double);
64 //--------------------------------------------------------------------
67 //--------------------------------------------------------------------
68 template<class args_info_type>
69 void FooImageGenericFilter<args_info_type>::SetArgsInfo(const args_info_type & a) {
71 SetIOVerbose(mArgsInfo.verbose_flag);
72 if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes();
74 if (mArgsInfo.input_given) {
75 SetInputFilename(mArgsInfo.input_arg);
77 if (mArgsInfo.output_given) {
78 SetOutputFilename(mArgsInfo.output_arg);
81 //--------------------------------------------------------------------
83 //--------------------------------------------------------------------
84 // Update with the number of dimensions and the pixeltype
85 //--------------------------------------------------------------------
86 template<class args_info_type>
87 template<class InputImageType>
89 FooImageGenericFilter<args_info_type>::UpdateWithInputImageType()
93 typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
96 typedef typename InputImageType::PixelType PixelType;
97 typedef itk::Image<char, InputImageType::ImageDimension> OutputImageType;
100 typedef itk::BinaryThresholdImageFilter<InputImageType, OutputImageType> BinaryThresholdImageFilterType;
101 typename BinaryThresholdImageFilterType::Pointer thresholdFilter=BinaryThresholdImageFilterType::New();
102 thresholdFilter->SetInput(input);
103 thresholdFilter->SetInsideValue(mArgsInfo.fg_arg);
105 if (mArgsInfo.lower_given) thresholdFilter->SetLowerThreshold(static_cast<PixelType>(mArgsInfo.lower_arg));
106 if (mArgsInfo.upper_given) thresholdFilter->SetUpperThreshold(static_cast<PixelType>(mArgsInfo.upper_arg));
108 if (mArgsInfo.mode_arg == std::string("both")) {
109 thresholdFilter->SetOutsideValue(mArgsInfo.bg_arg);
110 thresholdFilter->Update();
112 typename OutputImageType::Pointer outputImage = thresholdFilter->GetOutput();
113 this->template SetNextOutput<OutputImageType>(outputImage);
116 typename InputImageType::Pointer outputImage;
117 thresholdFilter->SetOutsideValue(0);
118 if (mArgsInfo.mode_arg == std::string("BG")) {
119 typedef itk::MaskImageFilter<InputImageType,OutputImageType> maskFilterType;
120 typename maskFilterType::Pointer maskFilter = maskFilterType::New();
121 maskFilter->SetInput1(input);
122 maskFilter->SetInput2(thresholdFilter->GetOutput());
123 maskFilter->SetOutsideValue(mArgsInfo.bg_arg);
124 maskFilter->Update();
125 outputImage = maskFilter->GetOutput();
128 typedef itk::MaskNegatedImageFilter<InputImageType,OutputImageType> maskFilterType;
129 typename maskFilterType::Pointer maskFilter = maskFilterType::New();
130 maskFilter->SetInput1(input);
131 maskFilter->SetInput2(thresholdFilter->GetOutput());
132 maskFilter->SetOutsideValue(mArgsInfo.fg_arg);
133 maskFilter->Update();
134 outputImage = maskFilter->GetOutput();
136 // Write/Save results
137 this->template SetNextOutput<InputImageType>(outputImage);
140 //--------------------------------------------------------------------
145 #endif //#define clitkFooImageGenericFilter_txx