]> Creatis software - clitk.git/blob - segmentation/clitkExtractLymphStation_7.txx
motion masks with and without bands
[clitk.git] / segmentation / clitkExtractLymphStation_7.txx
1
2 //--------------------------------------------------------------------
3 template <class TImageType>
4 void 
5 clitk::ExtractLymphStationsFilter<TImageType>::
6 ExtractStation_7_SetDefaultValues()
7 {
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);
14   SetS7_UseMostInferiorPartOnlyFlag(false);
15 }
16 //--------------------------------------------------------------------
17
18
19 //--------------------------------------------------------------------
20 template <class TImageType>
21 void 
22 clitk::ExtractLymphStationsFilter<TImageType>::
23 ExtractStation_7() {
24   if (CheckForStation("7")) {
25   ExtractStation_7_SI_Limits();
26   ExtractStation_7_RL_Interior_Limits();
27
28   //  ExtractStation_7_Posterior_Limits();
29   ExtractStation_8_Single_CCL_Limits();  
30   ExtractStation_7_Remove_Structures();
31   // Store image filenames into AFDB 
32   writeImage<MaskImageType>(m_ListOfStations["7"], "seg/Station7.mhd");
33   GetAFDB()->SetImageFilename("Station7", "seg/Station7.mhd");  
34   WriteAFDB();
35   }
36 }
37 //--------------------------------------------------------------------
38
39
40 //--------------------------------------------------------------------
41 template <class TImageType>
42 void 
43 clitk::ExtractLymphStationsFilter<TImageType>::
44 ExtractStation_7_SI_Limits() 
45 {
46   StartNewStep("[Station7] Inf/Sup mediastinum limits with carina/LLL-RMLBronchus");
47   // Get Inputs
48   MaskImagePointer Trachea = GetAFDB()->template GetImage <MaskImageType>("Trachea");  
49  
50   // Create line from A to B with
51   // A = upper border of LLL at left
52   // B = lower border of bronchus intermedius (BI) or RightMiddleLobeBronchus
53   ImagePointType A;
54   ImagePointType B;
55   FindLineForS7S8Separation(A, B);    
56
57   // // if option -> replace A[0] with B[0]
58   // if (GetS7_UseMostInferiorPartOnlyFlag()) {
59   //   A[0] = B[0];
60   // }
61
62   // Use line to remove the inferior part
63   m_Working_Support =
64     SliceBySliceSetBackgroundFromSingleLine<MaskImageType>(m_Working_Support, GetBackgroundValue(), 
65                                                            A, B, 2, 0, false);
66
67   // Get the CarinaZ position
68   double m_CarinaZ = FindCarina();
69   
70   // Crop support
71   m_Working_Support = 
72     clitk::CropImageAlongOneAxis<MaskImageType>(m_Working_Support, 2, 
73                                                 A[2], m_CarinaZ, true,
74                                                 GetBackgroundValue());
75   // Crop trachea 
76   m_Working_Trachea = 
77     clitk::CropImageAlongOneAxis<MaskImageType>(Trachea, 2, 
78                                                 A[2], m_CarinaZ, true,
79                                                 GetBackgroundValue()); 
80   
81   StopCurrentStep<MaskImageType>(m_Working_Support);
82   m_ListOfStations["7"] = m_Working_Support;
83 }
84 //--------------------------------------------------------------------
85
86
87 //--------------------------------------------------------------------
88 template <class TImageType>
89 void 
90 clitk::ExtractLymphStationsFilter<TImageType>::
91 ExtractStation_7_RL_Interior_Limits() 
92 {
93   // ----------------------------------------------------------------
94   StartNewStep("[Station7] RL limits with bronchi");  
95   
96   /*
97     Slice by Slice, consider most Left point of the Right
98     bronchus. Remove the Ant/Right corner
99   */
100
101   // First consider bronchi
102   FindLeftAndRightBronchi();
103   m_RightBronchus = GetAFDB()->template GetImage <MaskImageType>("RightBronchus");
104   m_LeftBronchus = GetAFDB()->template GetImage <MaskImageType>("LeftBronchus");
105
106   // Resize like m_Working_Support
107   m_LeftBronchus = 
108     clitk::ResizeImageLike<MaskImageType>(m_LeftBronchus, m_Working_Support, GetBackgroundValue());
109   m_RightBronchus = 
110     clitk::ResizeImageLike<MaskImageType>(m_RightBronchus, m_Working_Support, GetBackgroundValue());
111
112   // Extract slices, Label, compute centroid, keep most central connected component
113   std::vector<MaskSlicePointer> slices_leftbronchus;
114   std::vector<MaskSlicePointer> slices_rightbronchus;
115   std::vector<MaskSlicePointer> slices_support;
116   clitk::ExtractSlices<MaskImageType>(m_LeftBronchus, 2, slices_leftbronchus);
117   clitk::ExtractSlices<MaskImageType>(m_RightBronchus, 2, slices_rightbronchus);
118   clitk::ExtractSlices<MaskImageType>(m_Working_Support, 2, slices_support);
119
120   // Keep only the CCL of the bronchus with the closest to the center
121   // Loop on slices for left bronchus
122   for(uint i=0; i<slices_leftbronchus.size(); i++) {
123     slices_leftbronchus[i] = Labelize<MaskSliceType>(slices_leftbronchus[i], 0, false, 10);
124     std::vector<typename MaskSliceType::PointType> c;
125     clitk::ComputeCentroids<MaskSliceType>(slices_leftbronchus[i], GetBackgroundValue(), c);
126     if (c.size() > 1) {
127       double most_at_left = c[1][0];
128       int most_at_left_index=1;
129       for(uint j=1; j<c.size(); j++) {
130         if (c[j][0] < most_at_left) {
131           most_at_left = c[j][0];
132           most_at_left_index = j;
133         }
134       }
135       // Put all other CCL to Background
136       slices_leftbronchus[i] = 
137         clitk::Binarize<MaskSliceType>(slices_leftbronchus[i], most_at_left_index, 
138                                        most_at_left_index, GetBackgroundValue(), GetForegroundValue());
139     } // end c.size
140   }
141   
142   // Loop on slices for right bronchus
143   for(uint i=0; i<slices_rightbronchus.size(); i++) {
144     slices_rightbronchus[i] = Labelize<MaskSliceType>(slices_rightbronchus[i], 0, false, 10);
145     std::vector<typename MaskSliceType::PointType> c;
146     clitk::ComputeCentroids<MaskSliceType>(slices_rightbronchus[i], GetBackgroundValue(), c);
147     if (c.size() > 1) {
148       double most_at_right = c[1][0];
149       int most_at_right_index=1;
150       for(uint j=1; j<c.size(); j++) {
151         if (c[j][0] > most_at_right) {
152           most_at_right = c[j][0];
153           most_at_right_index = j;
154         }
155       }
156       // Put all other CCL to Background
157       slices_rightbronchus[i] = 
158         clitk::Binarize<MaskSliceType>(slices_rightbronchus[i], most_at_right_index, 
159                                        most_at_right_index, GetBackgroundValue(), GetForegroundValue());
160     } // end c.size
161   }
162   
163   // Joint slices
164   m_LeftBronchus = clitk::JoinSlices<MaskImageType>(slices_leftbronchus, m_LeftBronchus, 2);
165   m_RightBronchus = clitk::JoinSlices<MaskImageType>(slices_rightbronchus, m_RightBronchus, 2);
166
167   // For Right bronchus, Find most Left point. Remove corner Ant/Right corner
168   for(uint i=0; i<slices_rightbronchus.size(); i++) {
169     // Find most point most at left
170     MaskSlicePointType p_left;
171     MaskSlicePointType p_post;
172     bool b = clitk::FindExtremaPointInAGivenDirection<MaskSliceType>(slices_rightbronchus[i], GetBackgroundValue(), 0, false, p_left);
173     if (b) {
174       b = clitk::FindExtremaPointInAGivenDirection<MaskSliceType>(slices_rightbronchus[i], GetBackgroundValue(), 1, false, p_post);
175     }
176     if (b) {
177       MaskSlicePointType p = p_left;
178       p[1] = p_post[1];
179       MaskSliceIndexType pi;
180       slices_rightbronchus[i]->TransformPhysicalPointToIndex(p, pi);
181       
182       // Build region to remove
183       MaskSliceRegionType region = slices_rightbronchus[i]->GetLargestPossibleRegion();
184       MaskSliceIndexType index = region.GetIndex();
185       MaskSliceSizeType size = region.GetSize();
186       size[0] = pi[0] - index[0];
187       size[1] = pi[1] - index[1];
188       region.SetSize(size);
189       
190       // Fill region with Background value
191       clitk::FillRegionWithValue<MaskSliceType>(slices_support[i], GetBackgroundValue(), region);
192     }
193   }
194
195   // For Left bronchus, Find most Right point. Remove corner Ant/Left corner
196   for(uint i=0; i<slices_leftbronchus.size(); i++) {
197     // Find most point most at right
198     MaskSlicePointType p_right;
199     MaskSlicePointType p_post;
200     bool b = clitk::FindExtremaPointInAGivenDirection<MaskSliceType>(slices_leftbronchus[i], GetBackgroundValue(), 0, true, p_right);
201     if (b) {
202       b = clitk::FindExtremaPointInAGivenDirection<MaskSliceType>(slices_rightbronchus[i], GetBackgroundValue(), 1, false, p_post);
203     }
204     if (b) {
205       MaskSlicePointType p = p_right;
206       p[1] = p_post[1];
207       MaskSliceIndexType pi;
208       slices_leftbronchus[i]->TransformPhysicalPointToIndex(p, pi);
209       
210       /*      typedef itk::ImageRegionIterator<ImageType> IteratorType;
211       IteratorType iter(input, region);
212       iter.GoToBegin();
213       while (!iter.IsAtEnd()) {
214         MaskSliceIndexType index = iter.GetIndex();
215         if (index[0] > pi[0]) && (index[1] > pi[1]) iter.Set(GetBackgroundValue());
216
217         ++iter;
218       } 
219       */  
220       
221
222       // Build region to remove
223       MaskSliceRegionType region = slices_leftbronchus[i]->GetLargestPossibleRegion();
224       MaskSliceIndexType index = region.GetIndex();
225       MaskSliceSizeType size = region.GetSize();
226       index[0] = pi[0];
227       size[0] = slices_leftbronchus[i]->GetLargestPossibleRegion().GetSize()[0] - pi[0];
228       size[1] = pi[1] - index[1];
229       region.SetSize(size);
230       region.SetIndex(index);
231       
232       // Fill region with Background value
233       clitk::FillRegionWithValue<MaskSliceType>(slices_support[i], GetBackgroundValue(), region);
234     }
235   }
236
237   m_Working_Support = clitk::JoinSlices<MaskImageType>(slices_support, m_Working_Support, 2);
238
239   // Also remove what is at right of the Right bronchus (left respectively)
240   m_Working_Support = 
241     clitk::SliceBySliceRelativePosition<MaskImageType>(m_Working_Support, m_LeftBronchus, 2, 
242                                                        GetFuzzyThreshold("7", "Bronchi"), "NotLeftTo", 
243                                                        false, 3, false);
244   m_Working_Support = 
245     clitk::SliceBySliceRelativePosition<MaskImageType>(m_Working_Support, m_RightBronchus, 2, 
246                                                        GetFuzzyThreshold("7", "Bronchi"), "NotRightTo", 
247                                                        false, 3, false);
248
249   // SECOND PART 
250
251   StopCurrentStep<MaskImageType>(m_Working_Support);
252 }
253 //--------------------------------------------------------------------
254
255
256 //--------------------------------------------------------------------
257 template <class TImageType>
258 void 
259 clitk::ExtractLymphStationsFilter<TImageType>::
260 ExtractStation_7_RL_Limits_OLD() 
261 {
262   // ----------------------------------------------------------------
263   StartNewStep("[Station7] Limits with bronchus : RightTo the left bronchus");  
264
265   // First consider bronchus and keep the main CCL by slice
266   m_RightBronchus = GetAFDB()->template GetImage <MaskImageType>("RightBronchus");
267   m_LeftBronchus = GetAFDB()->template GetImage <MaskImageType>("LeftBronchus");
268
269   // Extract slices, Label, compute centroid, keep most central connected component
270   std::vector<MaskSlicePointer> slices_leftbronchus;
271   std::vector<MaskSlicePointer> slices_rightbronchus;
272   clitk::ExtractSlices<MaskImageType>(m_LeftBronchus, 2, slices_leftbronchus);
273   clitk::ExtractSlices<MaskImageType>(m_RightBronchus, 2, slices_rightbronchus);
274   
275   // Version #1 with limit = centroid of the bronchus (OUTDATED)
276   // Step1 = keep only the CCL of the bronchus with the closest to the center
277   // Step2 = SliceBySlice Rel pos to both bronchi
278
279   // Loop on slices
280   for(uint i=0; i<slices_leftbronchus.size(); i++) {
281     slices_leftbronchus[i] = Labelize<MaskSliceType>(slices_leftbronchus[i], 0, false, 10);
282     std::vector<typename MaskSliceType::PointType> c;
283     clitk::ComputeCentroids<MaskSliceType>(slices_leftbronchus[i], GetBackgroundValue(), c);
284     if (c.size() > 1) {
285       double most_at_left = c[1][0];
286       int most_at_left_index=1;
287       for(uint j=1; j<c.size(); j++) {
288         if (c[j][0] < most_at_left) {
289           most_at_left = c[j][0];
290           most_at_left_index = j;
291         }
292       }
293       // Put all other CCL to Background
294       slices_leftbronchus[i] = 
295         clitk::Binarize<MaskSliceType>(slices_leftbronchus[i], most_at_left_index, 
296                                        most_at_left_index, GetBackgroundValue(), GetForegroundValue());
297     } // end c.size
298   }
299   
300   for(uint i=0; i<slices_rightbronchus.size(); i++) {
301     slices_rightbronchus[i] = Labelize<MaskSliceType>(slices_rightbronchus[i], 0, false, 10);
302     std::vector<typename MaskSliceType::PointType> c;
303     clitk::ComputeCentroids<MaskSliceType>(slices_rightbronchus[i], GetBackgroundValue(), c);
304     if (c.size() > 1) {
305       double most_at_right = c[1][0];
306       int most_at_right_index=1;
307       for(uint j=1; j<c.size(); j++) {
308         if (c[j][0] > most_at_right) {
309           most_at_right = c[j][0];
310           most_at_right_index = j;
311         }
312       }
313       // Put all other CCL to Background
314       slices_rightbronchus[i] = 
315         clitk::Binarize<MaskSliceType>(slices_rightbronchus[i], most_at_right_index, 
316                                        most_at_right_index, GetBackgroundValue(), GetForegroundValue());
317     } // end c.size
318   }
319   
320   // Joint slices
321   m_LeftBronchus = clitk::JoinSlices<MaskImageType>(slices_leftbronchus, m_LeftBronchus, 2);
322   m_RightBronchus = clitk::JoinSlices<MaskImageType>(slices_rightbronchus, m_RightBronchus, 2);
323
324   writeImage<MaskImageType>(m_LeftBronchus, "step-left.mhd");
325   writeImage<MaskImageType>(m_RightBronchus, "step-right.mhd");
326
327   m_Working_Support = 
328     clitk::SliceBySliceRelativePosition<MaskImageType>(m_Working_Support, m_LeftBronchus, 2, 
329                                                        GetFuzzyThreshold("7", "Bronchi"), "RightTo", 
330                                                        false, 3, false);
331   StopCurrentStep<MaskImageType>(m_Working_Support);
332
333
334   // ----------------------------------------------------------------
335   StartNewStep("[Station7] Limits with bronchus : LeftTo the right bronchus");
336   m_Working_Support = 
337     clitk::SliceBySliceRelativePosition<MaskImageType>(m_Working_Support, m_RightBronchus, 2, 
338                                                        GetFuzzyThreshold("7", "Bronchi"), "LeftTo", 
339                                                        false, 3, false); 
340   StopCurrentStep<MaskImageType>(m_Working_Support);
341
342
343   // ----------------------------------------------------------------
344   StartNewStep("[Station7] Limits with LeftSuperiorPulmonaryVein");
345   try {
346     MaskImagePointer LeftSuperiorPulmonaryVein = GetAFDB()->template GetImage<MaskImageType>("LeftSuperiorPulmonaryVein");
347     typedef SliceBySliceRelativePositionFilter<MaskImageType> SliceRelPosFilterType;
348     typename SliceRelPosFilterType::Pointer sliceRelPosFilter = SliceRelPosFilterType::New();
349     sliceRelPosFilter->SetInput(m_Working_Support);
350     sliceRelPosFilter->SetInputObject(LeftSuperiorPulmonaryVein);
351     sliceRelPosFilter->SetDirection(2);
352     sliceRelPosFilter->SetFuzzyThreshold(GetFuzzyThreshold("7", "LeftSuperiorPulmonaryVein"));
353     sliceRelPosFilter->AddOrientationTypeString("NotLeftTo");
354     sliceRelPosFilter->AddOrientationTypeString("NotAntTo");
355     sliceRelPosFilter->SetIntermediateSpacingFlag(true);
356     sliceRelPosFilter->SetIntermediateSpacing(3);
357     sliceRelPosFilter->SetUniqueConnectedComponentBySliceFlag(false);
358     sliceRelPosFilter->SetAutoCropFlag(false); 
359     sliceRelPosFilter->IgnoreEmptySliceObjectFlagOn();
360     sliceRelPosFilter->Update();
361     m_Working_Support = sliceRelPosFilter->GetOutput();
362     StopCurrentStep<MaskImageType>(m_Working_Support);
363   }
364   catch (clitk::ExceptionObject e) {
365     std::cout << "Not LeftSuperiorPulmonaryVein, skip" << std::endl;
366   }
367
368   // ----------------------------------------------------------------
369   StartNewStep("[Station7] Limits with RightSuperiorPulmonaryVein");
370   try {
371     MaskImagePointer RightSuperiorPulmonaryVein = GetAFDB()->template GetImage<MaskImageType>("RightSuperiorPulmonaryVein");
372     typedef SliceBySliceRelativePositionFilter<MaskImageType> SliceRelPosFilterType;
373     typename SliceRelPosFilterType::Pointer sliceRelPosFilter = SliceRelPosFilterType::New();
374     sliceRelPosFilter->SetInput(m_Working_Support);
375     sliceRelPosFilter->SetInputObject(RightSuperiorPulmonaryVein);
376     sliceRelPosFilter->SetDirection(2);
377     sliceRelPosFilter->SetFuzzyThreshold(GetFuzzyThreshold("7", "RightSuperiorPulmonaryVein"));
378     sliceRelPosFilter->AddOrientationTypeString("NotRightTo");
379     sliceRelPosFilter->AddOrientationTypeString("NotAntTo");
380     sliceRelPosFilter->AddOrientationTypeString("NotPostTo");
381     sliceRelPosFilter->SetIntermediateSpacingFlag(true);
382     sliceRelPosFilter->SetIntermediateSpacing(3);
383     sliceRelPosFilter->SetUniqueConnectedComponentBySliceFlag(false);
384     sliceRelPosFilter->SetAutoCropFlag(false); 
385     sliceRelPosFilter->IgnoreEmptySliceObjectFlagOn();
386     sliceRelPosFilter->Update();
387     m_Working_Support = sliceRelPosFilter->GetOutput();
388     StopCurrentStep<MaskImageType>(m_Working_Support);
389   }
390   catch (clitk::ExceptionObject e) {
391     std::cout << "Not RightSuperiorPulmonaryVein, skip" << std::endl;
392   }
393
394   // ----------------------------------------------------------------
395   StartNewStep("[Station7] Limits with RightPulmonaryArtery");
396   MaskImagePointer RightPulmonaryArtery = GetAFDB()->template GetImage<MaskImageType>("RightPulmonaryArtery");
397   typedef SliceBySliceRelativePositionFilter<MaskImageType> SliceRelPosFilterType;
398   typename SliceRelPosFilterType::Pointer sliceRelPosFilter = SliceRelPosFilterType::New();
399   sliceRelPosFilter->SetInput(m_Working_Support);
400   sliceRelPosFilter->SetInputObject(RightPulmonaryArtery);
401   sliceRelPosFilter->SetDirection(2);
402   sliceRelPosFilter->SetFuzzyThreshold(GetFuzzyThreshold("7", "RightPulmonaryArtery"));
403   sliceRelPosFilter->AddOrientationTypeString("NotAntTo");
404   sliceRelPosFilter->SetIntermediateSpacingFlag(true);
405   sliceRelPosFilter->SetIntermediateSpacing(3);
406   sliceRelPosFilter->SetUniqueConnectedComponentBySliceFlag(false);
407   sliceRelPosFilter->SetAutoCropFlag(false); 
408   sliceRelPosFilter->IgnoreEmptySliceObjectFlagOn();
409   sliceRelPosFilter->Update();
410   m_Working_Support = sliceRelPosFilter->GetOutput();
411   StopCurrentStep<MaskImageType>(m_Working_Support);
412
413   // ----------------------------------------------------------------
414   StartNewStep("[Station7] Limits with LeftPulmonaryArtery");
415   MaskImagePointer LeftPulmonaryArtery = GetAFDB()->template GetImage<MaskImageType>("LeftPulmonaryArtery");
416   sliceRelPosFilter = SliceRelPosFilterType::New();
417   sliceRelPosFilter->SetInput(m_Working_Support);
418   sliceRelPosFilter->SetInputObject(LeftPulmonaryArtery);
419   sliceRelPosFilter->SetDirection(2);
420   sliceRelPosFilter->SetFuzzyThreshold(GetFuzzyThreshold("7", "LeftPulmonaryArtery"));
421   sliceRelPosFilter->AddOrientationTypeString("NotAntTo");
422   sliceRelPosFilter->SetIntermediateSpacingFlag(true);
423   sliceRelPosFilter->SetIntermediateSpacing(3);
424   sliceRelPosFilter->SetUniqueConnectedComponentBySliceFlag(false);
425   sliceRelPosFilter->SetAutoCropFlag(false); 
426   sliceRelPosFilter->IgnoreEmptySliceObjectFlagOn();
427   sliceRelPosFilter->Update();
428   m_Working_Support = sliceRelPosFilter->GetOutput();
429   StopCurrentStep<MaskImageType>(m_Working_Support);
430
431   StartNewStep("[Station7] Limits with SVC");
432   MaskImagePointer SVC = GetAFDB()->template GetImage<MaskImageType>("SVC");
433   sliceRelPosFilter = SliceRelPosFilterType::New();
434   sliceRelPosFilter->SetInput(m_Working_Support);
435   sliceRelPosFilter->SetInputObject(SVC);
436   sliceRelPosFilter->SetDirection(2);
437   sliceRelPosFilter->SetFuzzyThreshold(GetFuzzyThreshold("7", "SVC"));
438   sliceRelPosFilter->AddOrientationTypeString("NotRightTo");
439   sliceRelPosFilter->AddOrientationTypeString("NotAntTo");
440   sliceRelPosFilter->SetIntermediateSpacingFlag(true);
441   sliceRelPosFilter->SetIntermediateSpacing(3);
442   sliceRelPosFilter->SetUniqueConnectedComponentBySliceFlag(false);
443   sliceRelPosFilter->SetAutoCropFlag(true); 
444   sliceRelPosFilter->IgnoreEmptySliceObjectFlagOn();
445   sliceRelPosFilter->Update();
446   m_Working_Support = sliceRelPosFilter->GetOutput();
447   StopCurrentStep<MaskImageType>(m_Working_Support);
448   
449   // End
450   m_ListOfStations["7"] = m_Working_Support;
451 }
452 //--------------------------------------------------------------------
453
454
455 //--------------------------------------------------------------------
456 template <class TImageType>
457 void 
458 clitk::ExtractLymphStationsFilter<TImageType>::
459 ExtractStation_7_Posterior_Limits() 
460 {
461   StartNewStep("[Station7] Posterior limits -> must be AntTo post wall of the bronchi (OLD CLASSIF)");  
462
463   // Search for points that are the most left/post/ant and most
464   // right/post/ant of the left and right bronchus
465
466   // extract, loop slices, label/keep, find extrema x 3
467   /*  FindExtremaPointsInBronchus(m_LeftBronchus, 0, 15, m_RightMostInLeftBronchus, 
468                               m_AntMostInLeftBronchus, m_PostMostInLeftBronchus);
469   FindExtremaPointsInBronchus(m_RightBronchus, 1, 15, m_LeftMostInRightBronchus, 
470                               m_AntMostInRightBronchus, m_PostMostInRightBronchus);
471   */
472   
473   // First cut bronchus to the correct sup/inf support 
474   MaskImagePointer RightBronchus = clitk::ResizeImageLike<MaskImageType>(m_RightBronchus, m_Working_Support, GetBackgroundValue());
475   MaskImagePointer LeftBronchus = clitk::ResizeImageLike<MaskImageType>(m_LeftBronchus, m_Working_Support, GetBackgroundValue());
476
477   // Find extrema points
478   FindExtremaPointsInBronchus(RightBronchus, 0, 10, m_LeftMostInRightBronchus, 
479                               m_AntMostInRightBronchus, m_PostMostInRightBronchus);
480
481   FindExtremaPointsInBronchus(LeftBronchus, 1, 10, m_RightMostInLeftBronchus, 
482                               m_AntMostInLeftBronchus, m_PostMostInLeftBronchus);
483
484
485
486   // DEBUG
487   std::ofstream osrl; openFileForWriting(osrl, "osrl.txt"); osrl << "LANDMARKS1" << std::endl;
488   std::ofstream osal; openFileForWriting(osal, "osal.txt"); osal << "LANDMARKS1" << std::endl;
489   std::ofstream ospl; openFileForWriting(ospl, "ospl.txt"); ospl << "LANDMARKS1" << std::endl;
490   std::ofstream osrr; openFileForWriting(osrr, "osrr.txt"); osrr << "LANDMARKS1" << std::endl;
491   std::ofstream osar; openFileForWriting(osar, "osar.txt"); osar << "LANDMARKS1" << std::endl;
492   std::ofstream ospr; openFileForWriting(ospr, "ospr.txt"); ospr << "LANDMARKS1" << std::endl;
493
494   for(uint i=0; i<m_RightMostInLeftBronchus.size(); i++) {
495     osrl << i << " " << m_RightMostInLeftBronchus[i][0] << " " << m_RightMostInLeftBronchus[i][1] 
496          << " " << m_RightMostInLeftBronchus[i][2] << " 0 0 " << std::endl;
497     osal << i << " " << m_AntMostInLeftBronchus[i][0] << " " << m_AntMostInLeftBronchus[i][1] 
498          << " " << m_AntMostInLeftBronchus[i][2] << " 0 0 " << std::endl;
499     ospl << i << " " << m_PostMostInLeftBronchus[i][0] << " " << m_PostMostInLeftBronchus[i][1] 
500          << " " << m_PostMostInLeftBronchus[i][2] << " 0 0 " << std::endl;
501   }
502
503   for(uint i=0; i<m_LeftMostInRightBronchus.size(); i++) {
504     osrr << i << " " << m_LeftMostInRightBronchus[i][0] << " " << m_LeftMostInRightBronchus[i][1] 
505          << " " << m_LeftMostInRightBronchus[i][2] << " 0 0 " << std::endl;
506     osar << i << " " << m_AntMostInRightBronchus[i][0] << " " << m_AntMostInRightBronchus[i][1] 
507          << " " << m_AntMostInRightBronchus[i][2] << " 0 0 " << std::endl;
508     ospr << i << " " << m_PostMostInRightBronchus[i][0] << " " << m_PostMostInRightBronchus[i][1] 
509          << " " << m_PostMostInRightBronchus[i][2] << " 0 0 " << std::endl;
510   }
511   osrl.close();
512   osal.close();
513   ospl.close();
514   osrr.close();
515   osar.close();
516   ospr.close();
517
518   clitk::SliceBySliceSetBackgroundFromLineSeparation<MaskImageType>(m_Working_Support, 
519                                                                     m_PostMostInRightBronchus,
520                                                                     m_PostMostInLeftBronchus,
521                                                                     GetBackgroundValue(), 1, -10);
522   // If needed -> can do the same with AntMost.
523
524   // End
525   StopCurrentStep<MaskImageType>(m_Working_Support);
526   m_ListOfStations["7"] = m_Working_Support;
527 }
528 //--------------------------------------------------------------------
529
530 //--------------------------------------------------------------------
531 template <class ImageType>
532 void 
533 clitk::ExtractLymphStationsFilter<ImageType>::
534 ExtractStation_7_Remove_Structures()
535 {
536
537   //--------------------------------------------------------------------
538   StartNewStep("[Station7] remove some structures");
539
540   Remove_Structures("7", "AzygousVein");
541   Remove_Structures("7", "Aorta");
542   Remove_Structures("7", "RightPulmonaryArtery");
543   Remove_Structures("7", "LeftPulmonaryArtery");
544   Remove_Structures("7", "LeftSuperiorPulmonaryVein");
545   Remove_Structures("7", "PulmonaryTrunk");
546   Remove_Structures("7", "VertebralBody");
547
548   // Keep only one CCL by slice (before removing Esophagus)
549   //  DD("SliceBySliceKeepMainCCL");
550
551   // TODO -> replace by keep the one that contains point at the middle of the line between the bronchus
552   //      -> new function "keep/select" the ccl that contains this point (2D)
553
554   //m_Working_Support = clitk::SliceBySliceKeepMainCCL<MaskImageType>(m_Working_Support, GetBackgroundValue(), GetForegroundValue());
555
556   Remove_Structures("7", "Esophagus");
557
558   // END
559   StopCurrentStep<MaskImageType>(m_Working_Support);
560   m_ListOfStations["7"] = m_Working_Support;
561   return;
562 }
563 //--------------------------------------------------------------------
564
565
566