]> Creatis software - clitk.git/blob - segmentation/clitkExtractPatientFilter.h
some segmentation tools (most from jef)
[clitk.git] / segmentation / clitkExtractPatientFilter.h
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to: 
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
8
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.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17   ======================================================================-====*/
18
19 #ifndef CLITKEXTRACTPATIENTFILTER_H
20 #define CLITKEXTRACTPATIENTFILTER_H
21
22 #include "clitkFilterBase.h"
23
24 namespace clitk {
25   
26   //--------------------------------------------------------------------
27   /*
28     Try to extract the Patient part of a thorax CT.  
29
30     Prefer high resolution input and resample (NN) output at the end
31     (like). Input is binarized using initial thresholds, connected
32     components are labeled (firstLabel). The air label (1) is
33     removed. The remaining is binarized and relabeled, patient should
34     now be the principal label (secondLabel). Two mechanismes are
35     provided to influence the label images. Crop to reduce
36     connectivity (image is restored to original size), eg for
37     SBF. Decomposition through ersion and reconstruction through
38     dilation (slow), eg for Pulmo bellows. Choose which labels to keep
39     from second Label image. Final mask is cleaned by opening and
40     closing.
41
42   */
43   //--------------------------------------------------------------------
44   
45   template <class TInputImageType, class TOutputImageType>
46   class ITK_EXPORT ExtractPatientFilter: 
47     public clitk::FilterBase, 
48     public itk::ImageToImageFilter<TInputImageType, TOutputImageType> 
49   {
50   public:
51     /** Standard class typedefs. */
52     typedef ExtractPatientFilter            Self;
53     typedef itk::ImageToImageFilter<TInputImageType, TOutputImageType> Superclass;
54     typedef itk::SmartPointer<Self>         Pointer;
55     typedef itk::SmartPointer<const Self>   ConstPointer;
56     
57     /** Method for creation through the object factory. */
58     itkNewMacro(Self);
59     
60     /** Run-time type information (and related methods). */
61     itkTypeMacro(ExtractPatientFilter, ImageToImageFilter);
62     FILTERBASE_INIT;
63
64     /** Some convenient typedefs. */
65     typedef TInputImageType                       InputImageType;
66     typedef typename InputImageType::ConstPointer InputImageConstPointer;
67     typedef typename InputImageType::Pointer      InputImagePointer;
68     typedef typename InputImageType::RegionType   InputImageRegionType; 
69     typedef typename InputImageType::PixelType    InputImagePixelType; 
70     typedef typename InputImageType::SizeType     InputImageSizeType; 
71     typedef typename InputImageType::IndexType    InputImageIndexType; 
72         
73     typedef TOutputImageType                       OutputImageType;
74     typedef typename OutputImageType::ConstPointer OutputImageConstPointer;
75     typedef typename OutputImageType::Pointer      OutputImagePointer;
76     typedef typename OutputImageType::RegionType   OutputImageRegionType; 
77     typedef typename OutputImageType::PixelType    OutputImagePixelType; 
78     typedef typename OutputImageType::SizeType     OutputImageSizeType; 
79     typedef typename OutputImageType::IndexType    OutputImageIndexType; 
80
81     itkStaticConstMacro(ImageDimension, unsigned int, InputImageType::ImageDimension);
82     typedef int InternalPixelType;
83     typedef itk::Image<InternalPixelType, ImageDimension> InternalImageType;
84     typedef typename InternalImageType::SizeType          InternalImageSizeType;
85     
86     /** Connect inputs */
87     void SetInput(const TInputImageType * image);
88
89     // Set all options at a time
90     template<class ArgsInfoType>
91       void SetArgsInfo(ArgsInfoType arg);
92
93     // Step 1
94     itkSetMacro(UpperThreshold, InputImagePixelType);
95     itkGetMacro(UpperThreshold, InputImagePixelType);
96     GGO_DefineOption(upper, SetUpperThreshold, InputImagePixelType);
97
98     itkSetMacro(LowerThreshold, InputImagePixelType);
99     itkGetMacro(LowerThreshold, InputImagePixelType);
100     itkSetMacro(UseLowerThreshold, bool);    
101     itkGetConstMacro(UseLowerThreshold, bool);    
102     itkBooleanMacro(UseLowerThreshold);
103     GGO_DefineOption_WithTest(lower, SetLowerThreshold, InputImagePixelType, UseLowerThreshold);
104
105     // Step 2
106     itkSetMacro(DecomposeAndReconstructDuringFirstStep, bool);
107     itkGetConstMacro(DecomposeAndReconstructDuringFirstStep, bool);
108     itkBooleanMacro(DecomposeAndReconstructDuringFirstStep);
109     GGO_DefineOption_Flag(erode1, SetDecomposeAndReconstructDuringFirstStep);
110
111     itkSetMacro(Radius1, InternalImageSizeType);
112     itkGetConstMacro(Radius1, InternalImageSizeType);
113     GGO_DefineOption_Vector(radius1, SetRadius1, InternalImageSizeType, ImageDimension, true);
114
115     itkSetMacro(MaximumNumberOfLabels1, int);
116     itkGetConstMacro(MaximumNumberOfLabels1, int);
117     GGO_DefineOption(max1, SetMaximumNumberOfLabels1, int);
118
119     itkSetMacro(NumberOfNewLabels1, int);
120     itkGetConstMacro(NumberOfNewLabels1, int);
121     GGO_DefineOption(new1, SetNumberOfNewLabels1, int);
122
123     // Step 2
124     itkSetMacro(DecomposeAndReconstructDuringSecondStep, bool);
125     itkGetConstMacro(DecomposeAndReconstructDuringSecondStep, bool);
126     itkBooleanMacro(DecomposeAndReconstructDuringSecondStep);
127     GGO_DefineOption_Flag(erode2, SetDecomposeAndReconstructDuringSecondStep);
128
129     itkSetMacro(Radius2, InternalImageSizeType);
130     itkGetConstMacro(Radius2, InternalImageSizeType);
131     GGO_DefineOption_Vector(radius2, SetRadius2, InternalImageSizeType, ImageDimension, true)
132
133     itkSetMacro(MaximumNumberOfLabels2, int);
134     itkGetConstMacro(MaximumNumberOfLabels2, int);
135     GGO_DefineOption(max2, SetMaximumNumberOfLabels2, int);
136
137     itkSetMacro(NumberOfNewLabels2, int);
138     itkGetConstMacro(NumberOfNewLabels2, int);
139     GGO_DefineOption(new2, SetNumberOfNewLabels2, int);
140
141     // Step 3
142     itkSetMacro(FirstKeep, int);
143     itkGetConstMacro(FirstKeep, int);
144     GGO_DefineOption(firstKeep, SetFirstKeep, int);
145
146     itkSetMacro(LastKeep, int);
147     itkGetConstMacro(LastKeep, int);
148     GGO_DefineOption(lastKeep, SetLastKeep, int);
149
150     // Step 4
151     itkSetMacro(FinalOpenClose, bool);
152     itkGetConstMacro(FinalOpenClose, bool);
153     itkBooleanMacro(FinalOpenClose);
154     GGO_DefineOption_Flag(openClose, SetFinalOpenClose);
155
156     // Step 4
157     itkSetMacro(AutoCrop, bool);
158     itkGetConstMacro(AutoCrop, bool);
159     itkBooleanMacro(AutoCrop);
160     GGO_DefineOption_Flag(autoCrop, SetAutoCrop);
161
162   protected:
163     ExtractPatientFilter();
164     virtual ~ExtractPatientFilter() {}
165     
166     itkSetMacro(BackgroundValue, OutputImagePixelType);
167     itkSetMacro(ForegroundValue, OutputImagePixelType);
168     itkGetConstMacro(BackgroundValue, OutputImagePixelType);
169     itkGetConstMacro(ForegroundValue, OutputImagePixelType);
170     OutputImagePixelType m_BackgroundValue;
171     OutputImagePixelType m_ForegroundValue;
172
173     InputImagePixelType m_UpperThreshold;
174     InputImagePixelType m_LowerThreshold;
175     bool m_UseLowerThreshold;
176     bool m_DecomposeAndReconstructDuringFirstStep;
177     bool m_DecomposeAndReconstructDuringSecondStep;
178     bool m_FinalOpenClose;
179     InternalImageSizeType m_Radius1;
180     InternalImageSizeType m_Radius2;
181     int m_MaximumNumberOfLabels1;
182     int m_MaximumNumberOfLabels2;
183     int m_NumberOfNewLabels1;
184     int m_NumberOfNewLabels2;
185     int m_FirstKeep;
186     int m_LastKeep;
187     bool m_AutoCrop;
188
189     virtual void GenerateOutputInformation();
190     virtual void GenerateData();
191     
192     InputImageConstPointer input;
193     OutputImagePointer output;
194     typename InternalImageType::Pointer working_image;
195         
196   private:
197     ExtractPatientFilter(const Self&); //purposely not implemented
198     void operator=(const Self&); //purposely not implemented
199     
200   }; // end class
201   //--------------------------------------------------------------------
202
203 } // end namespace clitk
204 //--------------------------------------------------------------------
205
206 #ifndef ITK_MANUAL_INSTANTIATION
207 #include "clitkExtractPatientFilter.txx"
208 #endif
209
210 #endif