]> Creatis software - clitk.git/blob - segmentation/clitkExtractPatientFilter.h
Merge branch 'master' of git.creatis.insa-lyon.fr:clitk
[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     itkGetMacro(PrimaryOpeningRadius, unsigned int);
103     itkSetMacro(PrimaryOpeningRadius, unsigned int);
104     itkGetConstMacro(UseLowerThreshold, bool);    
105     itkBooleanMacro(UseLowerThreshold);
106
107     // Step 2
108     itkSetMacro(DecomposeAndReconstructDuringFirstStep, bool);
109     itkGetConstMacro(DecomposeAndReconstructDuringFirstStep, bool);
110     itkBooleanMacro(DecomposeAndReconstructDuringFirstStep);
111
112     itkSetMacro(Radius1, InternalImageSizeType);
113     itkGetConstMacro(Radius1, InternalImageSizeType);
114
115     itkSetMacro(MaximumNumberOfLabels1, int);
116     itkGetConstMacro(MaximumNumberOfLabels1, int);
117
118     itkSetMacro(NumberOfNewLabels1, int);
119     itkGetConstMacro(NumberOfNewLabels1, int);
120
121     // Step 2
122     itkSetMacro(DecomposeAndReconstructDuringSecondStep, bool);
123     itkGetConstMacro(DecomposeAndReconstructDuringSecondStep, bool);
124     itkBooleanMacro(DecomposeAndReconstructDuringSecondStep);
125
126     itkSetMacro(Radius2, InternalImageSizeType);
127     itkGetConstMacro(Radius2, InternalImageSizeType);
128
129     itkSetMacro(MaximumNumberOfLabels2, int);
130     itkGetConstMacro(MaximumNumberOfLabels2, int);
131
132     itkSetMacro(NumberOfNewLabels2, int);
133     itkGetConstMacro(NumberOfNewLabels2, int);
134
135     // Step 3
136     itkSetMacro(FirstKeep, int);
137     itkGetConstMacro(FirstKeep, int);
138
139     itkSetMacro(LastKeep, int);
140     itkGetConstMacro(LastKeep, int);
141
142     // Step 4
143     itkSetMacro(FinalOpenClose, bool);
144     itkGetConstMacro(FinalOpenClose, bool);
145     itkBooleanMacro(FinalOpenClose);
146
147     // Step 4
148     itkSetMacro(AutoCrop, bool);
149     itkGetConstMacro(AutoCrop, bool);
150     itkBooleanMacro(AutoCrop);
151
152   protected:
153     ExtractPatientFilter();
154     virtual ~ExtractPatientFilter() {}
155     
156     itkSetMacro(BackgroundValue, MaskImagePixelType);
157     itkSetMacro(ForegroundValue, MaskImagePixelType);
158     itkGetConstMacro(BackgroundValue, MaskImagePixelType);
159     itkGetConstMacro(ForegroundValue, MaskImagePixelType);
160     MaskImagePixelType m_BackgroundValue;
161     MaskImagePixelType m_ForegroundValue;
162
163     std::string m_OutputPatientFilename;
164     InputImagePixelType m_UpperThreshold;
165     InputImagePixelType m_LowerThreshold;
166     bool m_UseLowerThreshold;
167     bool m_DecomposeAndReconstructDuringFirstStep;
168     bool m_DecomposeAndReconstructDuringSecondStep;
169     bool m_FinalOpenClose;
170     unsigned  m_PrimaryOpeningRadius;
171     InternalImageSizeType m_Radius1;
172     InternalImageSizeType m_Radius2;
173     int m_MaximumNumberOfLabels1;
174     int m_MaximumNumberOfLabels2;
175     int m_NumberOfNewLabels1;
176     int m_NumberOfNewLabels2;
177     int m_FirstKeep;
178     int m_LastKeep;
179     bool m_AutoCrop;
180
181     virtual void GenerateOutputInformation();
182     virtual void GenerateData();
183     
184     InputImageConstPointer input;
185     MaskImagePointer output;
186     typename InternalImageType::Pointer working_image;
187         
188   private:
189     ExtractPatientFilter(const Self&); //purposely not implemented
190     void operator=(const Self&); //purposely not implemented
191     
192   }; // end class
193   //--------------------------------------------------------------------
194
195 } // end namespace clitk
196 //--------------------------------------------------------------------
197
198 #ifndef ITK_MANUAL_INSTANTIATION
199 #include "clitkExtractPatientFilter.txx"
200 #endif
201
202 #endif