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 ======================================================================-====*/
19 #ifndef CLITKEXTRACTPATIENTFILTER_H
20 #define CLITKEXTRACTPATIENTFILTER_H
22 #include "clitkFilterBase.h"
23 #include "clitkFilterWithAnatomicalFeatureDatabaseManagement.h"
24 #include "clitkSegmentationUtils.h"
28 //--------------------------------------------------------------------
30 Try to extract the Patient part of a thorax CT.
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
45 //--------------------------------------------------------------------
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> >
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;
62 /** Method for creation through the object factory. */
65 /** Run-time type information (and related methods). */
66 itkTypeMacro(ExtractPatientFilter, ImageToImageFilter);
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;
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;
85 itkStaticConstMacro(ImageDimension, unsigned int, InputImageType::ImageDimension);
86 typedef int InternalPixelType;
87 typedef itk::Image<InternalPixelType, ImageDimension> InternalImageType;
88 typedef typename InternalImageType::SizeType InternalImageSizeType;
91 void SetInput(const TInputImageType * image);
92 itkSetMacro(OutputPatientFilename, std::string);
93 itkGetMacro(OutputPatientFilename, std::string);
96 itkSetMacro(UpperThreshold, InputImagePixelType);
97 itkGetMacro(UpperThreshold, InputImagePixelType);
99 itkSetMacro(LowerThreshold, InputImagePixelType);
100 itkGetMacro(LowerThreshold, InputImagePixelType);
101 itkSetMacro(UseLowerThreshold, bool);
102 itkGetConstMacro(UseLowerThreshold, bool);
103 itkBooleanMacro(UseLowerThreshold);
106 itkSetMacro(DecomposeAndReconstructDuringFirstStep, bool);
107 itkGetConstMacro(DecomposeAndReconstructDuringFirstStep, bool);
108 itkBooleanMacro(DecomposeAndReconstructDuringFirstStep);
110 itkSetMacro(Radius1, InternalImageSizeType);
111 itkGetConstMacro(Radius1, InternalImageSizeType);
113 itkSetMacro(MaximumNumberOfLabels1, int);
114 itkGetConstMacro(MaximumNumberOfLabels1, int);
116 itkSetMacro(NumberOfNewLabels1, int);
117 itkGetConstMacro(NumberOfNewLabels1, int);
120 itkSetMacro(DecomposeAndReconstructDuringSecondStep, bool);
121 itkGetConstMacro(DecomposeAndReconstructDuringSecondStep, bool);
122 itkBooleanMacro(DecomposeAndReconstructDuringSecondStep);
124 itkSetMacro(Radius2, InternalImageSizeType);
125 itkGetConstMacro(Radius2, InternalImageSizeType);
127 itkSetMacro(MaximumNumberOfLabels2, int);
128 itkGetConstMacro(MaximumNumberOfLabels2, int);
130 itkSetMacro(NumberOfNewLabels2, int);
131 itkGetConstMacro(NumberOfNewLabels2, int);
134 itkSetMacro(FirstKeep, int);
135 itkGetConstMacro(FirstKeep, int);
137 itkSetMacro(LastKeep, int);
138 itkGetConstMacro(LastKeep, int);
141 itkSetMacro(FinalOpenClose, bool);
142 itkGetConstMacro(FinalOpenClose, bool);
143 itkBooleanMacro(FinalOpenClose);
146 itkSetMacro(AutoCrop, bool);
147 itkGetConstMacro(AutoCrop, bool);
148 itkBooleanMacro(AutoCrop);
151 ExtractPatientFilter();
152 virtual ~ExtractPatientFilter() {}
154 itkSetMacro(BackgroundValue, MaskImagePixelType);
155 itkSetMacro(ForegroundValue, MaskImagePixelType);
156 itkGetConstMacro(BackgroundValue, MaskImagePixelType);
157 itkGetConstMacro(ForegroundValue, MaskImagePixelType);
158 MaskImagePixelType m_BackgroundValue;
159 MaskImagePixelType m_ForegroundValue;
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;
178 virtual void GenerateOutputInformation();
179 virtual void GenerateData();
181 InputImageConstPointer input;
182 MaskImagePointer output;
183 typename InternalImageType::Pointer working_image;
186 ExtractPatientFilter(const Self&); //purposely not implemented
187 void operator=(const Self&); //purposely not implemented
190 //--------------------------------------------------------------------
192 } // end namespace clitk
193 //--------------------------------------------------------------------
195 #ifndef ITK_MANUAL_INSTANTIATION
196 #include "clitkExtractPatientFilter.txx"