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