2 //--------------------------------------------------------------------
3 template <class TImageType>
5 clitk::ExtractLymphStationsFilter<TImageType>::
6 ExtractStation_7_SetDefaultValues()
8 SetFuzzyThreshold("7", "Bronchi", 0.1);
9 SetFuzzyThreshold("7", "LeftSuperiorPulmonaryVein", 0.3);
10 SetFuzzyThreshold("7", "RightSuperiorPulmonaryVein", 0.2);
11 SetFuzzyThreshold("7", "RightPulmonaryArtery", 0.3);
12 SetFuzzyThreshold("7", "LeftPulmonaryArtery", 0.5);
13 SetFuzzyThreshold("7", "SVC", 0.2);
15 //--------------------------------------------------------------------
18 //--------------------------------------------------------------------
19 template <class TImageType>
21 clitk::ExtractLymphStationsFilter<TImageType>::
22 ExtractStation_7_SI_Limits()
24 StartNewStep("[Station7] Inf/Sup mediastinum limits with carina/LLLBronchus");
26 MaskImagePointer Trachea = GetAFDB()->template GetImage <MaskImageType>("Trachea");
28 // We suppoe that CarinaZ was already computed (S8)
29 double m_CarinaZ = GetAFDB()->GetDouble("CarinaZ");
31 // double m_OriginOfRightMiddleLobeBronchusZ = GetAFDB()->GetPoint3D("OriginOfRightMiddleLobeBronchus", 2);
32 // DD(m_OriginOfRightMiddleLobeBronchusZ);
33 MaskImagePointer UpperBorderOfLLLBronchus = GetAFDB()->template GetImage<MaskImageType>("UpperBorderOfLLLBronchus");
35 // Search most inf point (WHY ? IS IT THE RIGHT STRUCTURE ??)
36 MaskImagePointType ps = UpperBorderOfLLLBronchus->GetOrigin(); // initialise to avoid warning
37 clitk::FindExtremaPointInAGivenDirection<MaskImageType>(UpperBorderOfLLLBronchus, GetBackgroundValue(), 2, true, ps);
38 double m_UpperBorderOfLLLBronchusZ = ps[2];
41 std::vector<MaskImagePointType> centroids;
42 clitk::ComputeCentroids<MaskImageType>(UpperBorderOfLLLBronchus, GetBackgroundValue(), centroids);
43 double m_UpperBorderOfLLLBronchusZ = centroids[1][2];
44 DD(m_UpperBorderOfLLLBronchusZ)
49 clitk::CropImageAlongOneAxis<MaskImageType>(m_Working_Support, 2,
50 m_UpperBorderOfLLLBronchusZ,
52 GetBackgroundValue());
55 clitk::CropImageAlongOneAxis<MaskImageType>(Trachea, 2,
56 m_UpperBorderOfLLLBronchusZ,
58 GetBackgroundValue());
60 StopCurrentStep<MaskImageType>(m_Working_Support);
61 m_ListOfStations["7"] = m_Working_Support;
63 //--------------------------------------------------------------------
66 //--------------------------------------------------------------------
67 template <class TImageType>
69 clitk::ExtractLymphStationsFilter<TImageType>::
70 ExtractStation_7_RL_Limits()
72 // ----------------------------------------------------------------
73 StartNewStep("[Station7] Limits with bronchus : RightTo the left bronchus");
75 // First consider bronchus and keep the main CCL by slice
76 m_RightBronchus = GetAFDB()->template GetImage <MaskImageType>("RightBronchus");
77 m_LeftBronchus = GetAFDB()->template GetImage <MaskImageType>("LeftBronchus");
79 // Extract slices, Label, compute centroid, keep most central connected component
80 std::vector<MaskSlicePointer> slices_leftbronchus;
81 std::vector<MaskSlicePointer> slices_rightbronchus;
82 clitk::ExtractSlices<MaskImageType>(m_LeftBronchus, 2, slices_leftbronchus);
83 clitk::ExtractSlices<MaskImageType>(m_RightBronchus, 2, slices_rightbronchus);
86 for(uint i=0; i<slices_leftbronchus.size(); i++) {
87 slices_leftbronchus[i] = Labelize<MaskSliceType>(slices_leftbronchus[i], 0, false, 10);
88 std::vector<typename MaskSliceType::PointType> c;
89 clitk::ComputeCentroids<MaskSliceType>(slices_leftbronchus[i], GetBackgroundValue(), c);
91 double most_at_left = c[1][0];
92 int most_at_left_index=1;
93 for(uint j=1; j<c.size(); j++) {
94 if (c[j][0] < most_at_left) {
95 most_at_left = c[j][0];
96 most_at_left_index = j;
99 // Put all other CCL to Background
100 slices_leftbronchus[i] =
101 clitk::Binarize<MaskSliceType>(slices_leftbronchus[i], most_at_left_index,
102 most_at_left_index, GetBackgroundValue(), GetForegroundValue());
106 for(uint i=0; i<slices_rightbronchus.size(); i++) {
107 slices_rightbronchus[i] = Labelize<MaskSliceType>(slices_rightbronchus[i], 0, false, 10);
108 std::vector<typename MaskSliceType::PointType> c;
109 clitk::ComputeCentroids<MaskSliceType>(slices_rightbronchus[i], GetBackgroundValue(), c);
111 double most_at_right = c[1][0];
112 int most_at_right_index=1;
113 for(uint j=1; j<c.size(); j++) {
114 if (c[j][0] > most_at_right) {
115 most_at_right = c[j][0];
116 most_at_right_index = j;
119 // Put all other CCL to Background
120 slices_rightbronchus[i] =
121 clitk::Binarize<MaskSliceType>(slices_rightbronchus[i], most_at_right_index,
122 most_at_right_index, GetBackgroundValue(), GetForegroundValue());
127 m_LeftBronchus = clitk::JoinSlices<MaskImageType>(slices_leftbronchus, m_LeftBronchus, 2);
128 m_RightBronchus = clitk::JoinSlices<MaskImageType>(slices_rightbronchus, m_RightBronchus, 2);
130 writeImage<MaskImageType>(m_LeftBronchus, "step-left.mhd");
131 writeImage<MaskImageType>(m_RightBronchus, "step-right.mhd");
134 clitk::SliceBySliceRelativePosition<MaskImageType>(m_Working_Support, m_LeftBronchus, 2,
135 GetFuzzyThreshold("7", "Bronchi"), "RightTo",
137 StopCurrentStep<MaskImageType>(m_Working_Support);
140 // ----------------------------------------------------------------
141 StartNewStep("[Station7] Limits with bronchus : LeftTo the right bronchus");
143 clitk::SliceBySliceRelativePosition<MaskImageType>(m_Working_Support, m_RightBronchus, 2,
144 GetFuzzyThreshold("7", "Bronchi"), "LeftTo",
146 StopCurrentStep<MaskImageType>(m_Working_Support);
149 // ----------------------------------------------------------------
150 StartNewStep("[Station7] Limits with LeftSuperiorPulmonaryVein");
152 MaskImagePointer LeftSuperiorPulmonaryVein = GetAFDB()->template GetImage<MaskImageType>("LeftSuperiorPulmonaryVein");
153 typedef SliceBySliceRelativePositionFilter<MaskImageType> SliceRelPosFilterType;
154 typename SliceRelPosFilterType::Pointer sliceRelPosFilter = SliceRelPosFilterType::New();
155 sliceRelPosFilter->SetInput(m_Working_Support);
156 sliceRelPosFilter->SetInputObject(LeftSuperiorPulmonaryVein);
157 sliceRelPosFilter->SetDirection(2);
158 sliceRelPosFilter->SetFuzzyThreshold(GetFuzzyThreshold("7", "LeftSuperiorPulmonaryVein"));
159 sliceRelPosFilter->AddOrientationTypeString("NotLeftTo");
160 sliceRelPosFilter->AddOrientationTypeString("NotAntTo");
161 sliceRelPosFilter->SetIntermediateSpacingFlag(true);
162 sliceRelPosFilter->SetIntermediateSpacing(3);
163 sliceRelPosFilter->SetUniqueConnectedComponentBySlice(false);
164 sliceRelPosFilter->SetAutoCropFlag(false);
165 sliceRelPosFilter->IgnoreEmptySliceObjectFlagOn();
166 sliceRelPosFilter->Update();
167 m_Working_Support = sliceRelPosFilter->GetOutput();
168 StopCurrentStep<MaskImageType>(m_Working_Support);
170 catch (clitk::ExceptionObject e) {
171 std::cout << "Not LeftSuperiorPulmonaryVein, skip" << std::endl;
174 // ----------------------------------------------------------------
175 StartNewStep("[Station7] Limits with RightSuperiorPulmonaryVein");
177 MaskImagePointer RightSuperiorPulmonaryVein = GetAFDB()->template GetImage<MaskImageType>("RightSuperiorPulmonaryVein");
178 typedef SliceBySliceRelativePositionFilter<MaskImageType> SliceRelPosFilterType;
179 typename SliceRelPosFilterType::Pointer sliceRelPosFilter = SliceRelPosFilterType::New();
180 sliceRelPosFilter->SetInput(m_Working_Support);
181 sliceRelPosFilter->SetInputObject(RightSuperiorPulmonaryVein);
182 sliceRelPosFilter->SetDirection(2);
183 sliceRelPosFilter->SetFuzzyThreshold(GetFuzzyThreshold("7", "RightSuperiorPulmonaryVein"));
184 sliceRelPosFilter->AddOrientationTypeString("NotRightTo");
185 sliceRelPosFilter->AddOrientationTypeString("NotAntTo");
186 sliceRelPosFilter->AddOrientationTypeString("NotPostTo");
187 sliceRelPosFilter->SetIntermediateSpacingFlag(true);
188 sliceRelPosFilter->SetIntermediateSpacing(3);
189 sliceRelPosFilter->SetUniqueConnectedComponentBySlice(false);
190 sliceRelPosFilter->SetAutoCropFlag(false);
191 sliceRelPosFilter->IgnoreEmptySliceObjectFlagOn();
192 sliceRelPosFilter->Update();
193 m_Working_Support = sliceRelPosFilter->GetOutput();
194 StopCurrentStep<MaskImageType>(m_Working_Support);
196 catch (clitk::ExceptionObject e) {
197 std::cout << "Not RightSuperiorPulmonaryVein, skip" << std::endl;
200 // ----------------------------------------------------------------
201 StartNewStep("[Station7] Limits with RightPulmonaryArtery");
202 MaskImagePointer RightPulmonaryArtery = GetAFDB()->template GetImage<MaskImageType>("RightPulmonaryArtery");
203 typedef SliceBySliceRelativePositionFilter<MaskImageType> SliceRelPosFilterType;
204 typename SliceRelPosFilterType::Pointer sliceRelPosFilter = SliceRelPosFilterType::New();
205 sliceRelPosFilter->SetInput(m_Working_Support);
206 sliceRelPosFilter->SetInputObject(RightPulmonaryArtery);
207 sliceRelPosFilter->SetDirection(2);
208 sliceRelPosFilter->SetFuzzyThreshold(GetFuzzyThreshold("7", "RightPulmonaryArtery"));
209 sliceRelPosFilter->AddOrientationTypeString("NotAntTo");
210 sliceRelPosFilter->SetIntermediateSpacingFlag(true);
211 sliceRelPosFilter->SetIntermediateSpacing(3);
212 sliceRelPosFilter->SetUniqueConnectedComponentBySlice(false);
213 sliceRelPosFilter->SetAutoCropFlag(false);
214 sliceRelPosFilter->IgnoreEmptySliceObjectFlagOn();
215 sliceRelPosFilter->Update();
216 m_Working_Support = sliceRelPosFilter->GetOutput();
217 StopCurrentStep<MaskImageType>(m_Working_Support);
219 // ----------------------------------------------------------------
220 StartNewStep("[Station7] Limits with LeftPulmonaryArtery");
221 MaskImagePointer LeftPulmonaryArtery = GetAFDB()->template GetImage<MaskImageType>("LeftPulmonaryArtery");
222 sliceRelPosFilter = SliceRelPosFilterType::New();
223 sliceRelPosFilter->SetInput(m_Working_Support);
224 sliceRelPosFilter->SetInputObject(LeftPulmonaryArtery);
225 sliceRelPosFilter->SetDirection(2);
226 sliceRelPosFilter->SetFuzzyThreshold(GetFuzzyThreshold("7", "LeftPulmonaryArtery"));
227 sliceRelPosFilter->AddOrientationTypeString("NotAntTo");
228 sliceRelPosFilter->SetIntermediateSpacingFlag(true);
229 sliceRelPosFilter->SetIntermediateSpacing(3);
230 sliceRelPosFilter->SetUniqueConnectedComponentBySlice(false);
231 sliceRelPosFilter->SetAutoCropFlag(false);
232 sliceRelPosFilter->IgnoreEmptySliceObjectFlagOn();
233 sliceRelPosFilter->Update();
234 m_Working_Support = sliceRelPosFilter->GetOutput();
235 StopCurrentStep<MaskImageType>(m_Working_Support);
237 StartNewStep("[Station7] Limits with SVC");
238 MaskImagePointer SVC = GetAFDB()->template GetImage<MaskImageType>("SVC");
239 sliceRelPosFilter = SliceRelPosFilterType::New();
240 sliceRelPosFilter->SetInput(m_Working_Support);
241 sliceRelPosFilter->SetInputObject(SVC);
242 sliceRelPosFilter->SetDirection(2);
243 sliceRelPosFilter->SetFuzzyThreshold(GetFuzzyThreshold("7", "SVC"));
244 sliceRelPosFilter->AddOrientationTypeString("NotRightTo");
245 sliceRelPosFilter->AddOrientationTypeString("NotAntTo");
246 sliceRelPosFilter->SetIntermediateSpacingFlag(true);
247 sliceRelPosFilter->SetIntermediateSpacing(3);
248 sliceRelPosFilter->SetUniqueConnectedComponentBySlice(false);
249 sliceRelPosFilter->SetAutoCropFlag(true);
250 sliceRelPosFilter->IgnoreEmptySliceObjectFlagOn();
251 sliceRelPosFilter->Update();
252 m_Working_Support = sliceRelPosFilter->GetOutput();
253 StopCurrentStep<MaskImageType>(m_Working_Support);
256 m_ListOfStations["7"] = m_Working_Support;
258 //--------------------------------------------------------------------
261 //--------------------------------------------------------------------
262 template <class TImageType>
264 clitk::ExtractLymphStationsFilter<TImageType>::
265 ExtractStation_7_Posterior_Limits()
267 StartNewStep("[Station7] Posterior limits -> must be AntTo post wall of the bronchi (OLD CLASSIF)");
269 // Search for points that are the most left/post/ant and most
270 // right/post/ant of the left and right bronchus
272 // extract, loop slices, label/keep, find extrema x 3
273 /* FindExtremaPointsInBronchus(m_LeftBronchus, 0, 15, m_RightMostInLeftBronchus,
274 m_AntMostInLeftBronchus, m_PostMostInLeftBronchus);
275 FindExtremaPointsInBronchus(m_RightBronchus, 1, 15, m_LeftMostInRightBronchus,
276 m_AntMostInRightBronchus, m_PostMostInRightBronchus);
279 // First cut bronchus to the correct sup/inf support
280 MaskImagePointer RightBronchus = clitk::ResizeImageLike<MaskImageType>(m_RightBronchus, m_Working_Support, GetBackgroundValue());
281 MaskImagePointer LeftBronchus = clitk::ResizeImageLike<MaskImageType>(m_LeftBronchus, m_Working_Support, GetBackgroundValue());
283 // Find extrema points
284 FindExtremaPointsInBronchus(RightBronchus, 0, 10, m_LeftMostInRightBronchus,
285 m_AntMostInRightBronchus, m_PostMostInRightBronchus);
287 FindExtremaPointsInBronchus(LeftBronchus, 1, 10, m_RightMostInLeftBronchus,
288 m_AntMostInLeftBronchus, m_PostMostInLeftBronchus);
293 std::ofstream osrl; openFileForWriting(osrl, "osrl.txt"); osrl << "LANDMARKS1" << std::endl;
294 std::ofstream osal; openFileForWriting(osal, "osal.txt"); osal << "LANDMARKS1" << std::endl;
295 std::ofstream ospl; openFileForWriting(ospl, "ospl.txt"); ospl << "LANDMARKS1" << std::endl;
296 std::ofstream osrr; openFileForWriting(osrr, "osrr.txt"); osrr << "LANDMARKS1" << std::endl;
297 std::ofstream osar; openFileForWriting(osar, "osar.txt"); osar << "LANDMARKS1" << std::endl;
298 std::ofstream ospr; openFileForWriting(ospr, "ospr.txt"); ospr << "LANDMARKS1" << std::endl;
300 for(uint i=0; i<m_RightMostInLeftBronchus.size(); i++) {
301 osrl << i << " " << m_RightMostInLeftBronchus[i][0] << " " << m_RightMostInLeftBronchus[i][1]
302 << " " << m_RightMostInLeftBronchus[i][2] << " 0 0 " << std::endl;
303 osal << i << " " << m_AntMostInLeftBronchus[i][0] << " " << m_AntMostInLeftBronchus[i][1]
304 << " " << m_AntMostInLeftBronchus[i][2] << " 0 0 " << std::endl;
305 ospl << i << " " << m_PostMostInLeftBronchus[i][0] << " " << m_PostMostInLeftBronchus[i][1]
306 << " " << m_PostMostInLeftBronchus[i][2] << " 0 0 " << std::endl;
309 for(uint i=0; i<m_LeftMostInRightBronchus.size(); i++) {
310 osrr << i << " " << m_LeftMostInRightBronchus[i][0] << " " << m_LeftMostInRightBronchus[i][1]
311 << " " << m_LeftMostInRightBronchus[i][2] << " 0 0 " << std::endl;
312 osar << i << " " << m_AntMostInRightBronchus[i][0] << " " << m_AntMostInRightBronchus[i][1]
313 << " " << m_AntMostInRightBronchus[i][2] << " 0 0 " << std::endl;
314 ospr << i << " " << m_PostMostInRightBronchus[i][0] << " " << m_PostMostInRightBronchus[i][1]
315 << " " << m_PostMostInRightBronchus[i][2] << " 0 0 " << std::endl;
324 clitk::SliceBySliceSetBackgroundFromLineSeparation<MaskImageType>(m_Working_Support,
325 m_PostMostInRightBronchus,
326 m_PostMostInLeftBronchus,
327 GetBackgroundValue(), 1, -10);
328 // If needed -> can do the same with AntMost.
331 StopCurrentStep<MaskImageType>(m_Working_Support);
332 m_ListOfStations["7"] = m_Working_Support;
334 //--------------------------------------------------------------------
336 //--------------------------------------------------------------------
337 template <class ImageType>
339 clitk::ExtractLymphStationsFilter<ImageType>::
340 ExtractStation_7_Remove_Structures()
343 //--------------------------------------------------------------------
344 StartNewStep("[Station7] remove some structures");
346 Remove_Structures("7", "AzygousVein");
347 Remove_Structures("7", "Aorta");
348 Remove_Structures("7", "Esophagus");
349 Remove_Structures("7", "RightPulmonaryArtery");
350 Remove_Structures("7", "LeftPulmonaryArtery");
351 Remove_Structures("7", "LeftSuperiorPulmonaryVein");
352 Remove_Structures("7", "PulmonaryTrunk");
353 Remove_Structures("7", "VertebralBody");
356 StopCurrentStep<MaskImageType>(m_Working_Support);
357 m_ListOfStations["7"] = m_Working_Support;
360 //--------------------------------------------------------------------