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