+ output = clitk::AutoCrop<MaskImageType>(output, this->GetBackgroundValue());
+ this->template StopCurrentStep<MaskImageType>(output);
+
+ //--------------------------------------------------------------------
+ // Step : LR limits from lung (need separate lung ?)
+ // Get separate lung images to get only the right and left lung
+ // (because RelativePositionPropImageFilter only consider fg=1);
+ // (label must be '1' because right is greater than left). (WE DO
+ // NOT NEED TO SEPARATE ? )
+ this->StartNewStep("[Mediastinum] Left/Right limits with lungs");
+
+ // The following cannot be "inplace" because mask is the same than input ...
+ MaskImagePointer right_lung =
+ clitk::SetBackground<MaskImageType, MaskImageType>(lung, lung, 2, 0, false);
+ MaskImagePointer left_lung =
+ clitk::SetBackground<MaskImageType, MaskImageType>(lung, lung, 1, 0, false);
+ left_lung = clitk::SetBackground<MaskImageType, MaskImageType>(left_lung, left_lung, 2, 1, false);
+ right_lung = clitk::ResizeImageLike<MaskImageType>(right_lung, output, this->GetBackgroundValue());
+ left_lung = clitk::ResizeImageLike<MaskImageType>(left_lung, output, this->GetBackgroundValue());
+ this->GetAFDB()->template SetImage<MaskImageType>("RightLung", "seg/RightLung.mha",
+ right_lung, true);
+ this->GetAFDB()->template SetImage<MaskImageType>("LeftLung", "seg/LeftLung.mha",
+ left_lung, true);
+ this->GetAFDB()->Write();
+ this->template StopCurrentStep<MaskImageType>(output);
+
+ //--------------------------------------------------------------------
+ // Step : AP limits from bones
+ // Separate the bones in the ant-post middle
+ MaskImagePointer bones_ant;
+ MaskImagePointer bones_post;
+ MaskImagePointType middle_AntPost_position;
+ middle_AntPost_position.Fill(NumericTraits<MaskImagePointType::ValueType>::Zero);
+ if (GetUseBones()) {
+ this->StartNewStep("[Mediastinum] Ant/Post limits with bones");
+
+ // To define ant and post part of the bones with a single horizontal line
+ MaskImageIndexType index_bones_middle;
+
+ // Method1: cut in the middle (not optimal)
+ /*
+ middle_AntPost_position[0] = middle_AntPost_position[2] = 0;
+ middle_AntPost_position[1] = bones->GetOrigin()[1]+
+ (bones->GetLargestPossibleRegion().GetSize()[1]*bones->GetSpacing()[1])/2.0;
+ DD(middle_AntPost_position);
+ bones->TransformPhysicalPointToIndex(middle_AntPost_position, index_bones_middle);
+ */
+
+ // Method2: Use VertebralBody, take most ant point
+ MaskImagePointer VertebralBody = this->GetAFDB()->template GetImage<MaskImageType>("VertebralBody");
+ FindExtremaPointInAGivenDirection<MaskImageType>(VertebralBody, this->GetBackgroundValue(),
+ 1, true, middle_AntPost_position);
+ bones->TransformPhysicalPointToIndex(middle_AntPost_position, index_bones_middle);
+
+ // Split bone image first into two parts (ant and post), and crop
+ // lateraly to get vertebral
+ typedef itk::RegionOfInterestImageFilter<MaskImageType, MaskImageType> ROIFilterType;
+ // typedef itk::ExtractImageFilter<MaskImageType, MaskImageType> ROIFilterType;
+ typename ROIFilterType::Pointer roiFilter = ROIFilterType::New();
+ MaskImageRegionType region = bones->GetLargestPossibleRegion();
+ MaskImageSizeType size = region.GetSize();
+ MaskImageIndexType index = region.GetIndex();
+ // ANT part
+ // crop LR to keep 1/4 center part
+ // index[0] = size[0]/4+size[0]/8;
+ //size[0] = size[0]/4;
+ // crop AP to keep first (ant) part
+ size[1] = index_bones_middle[1]; //size[1]/2.0;
+ region.SetSize(size);
+ region.SetIndex(index);
+ roiFilter->SetInput(bones);
+ roiFilter->SetRegionOfInterest(region);
+ roiFilter->ReleaseDataFlagOff();
+ roiFilter->Update();
+ bones_ant = roiFilter->GetOutput();
+ // writeImage<MaskImageType>(bones_ant, "b_ant.mhd");
+ // POST part
+ roiFilter = ROIFilterType::New();
+ index[1] = bones->GetLargestPossibleRegion().GetIndex()[1] + size[1]-1;
+ size[1] = bones->GetLargestPossibleRegion().GetSize()[1] - size[1];
+ region.SetIndex(index);
+ region.SetSize(size);
+ roiFilter->SetInput(bones);
+ roiFilter->SetRegionOfInterest(region);
+ roiFilter->ReleaseDataFlagOff();
+ roiFilter->Update();
+ bones_post = roiFilter->GetOutput();
+ // writeImage<MaskImageType>(bones_post, "b_post.mhd");
+
+ // Now, insert this image in the AFDB ==> (needed because used in the RelativePosition config file)
+ this->GetAFDB()->template SetImage<MaskImageType>("Bones_Post", "seg/Bones_Post.mha",
+ bones_post, true);
+ this->GetAFDB()->template SetImage<MaskImageType>("Bones_Ant", "seg/Bones_Ant.mha",
+ bones_ant, true);
+ this->GetAFDB()->Write();
+
+ this->template StopCurrentStep<MaskImageType>(output);
+ }
+
+ //--------------------------------------------------------------------
+ // Remove VertebralBody part
+ this->StartNewStep("[Mediastinum] Remove VertebralBody");
+ MaskImagePointer VertebralBody = this->GetAFDB()->template GetImage<MaskImageType>("VertebralBody");
+ clitk::AndNot<MaskImageType>(output, VertebralBody, this->GetBackgroundValue());
+ this->template StopCurrentStep<MaskImageType>(output);
+
+ //--------------------------------------------------------------------
+ // Generic RelativePosition processes
+ output = this->ApplyRelativePositionList("Mediastinum", output);
+
+
+ //--------------------------------------------------------------------
+ // FIXME --> do not put this limits here !
+ /*
+ // Step : SI limits It is better to do this limit *AFTER* the
+ // RelativePosition to avoid some issue due to superior boundaries.
+ this->StartNewStep("[Mediastinum] Keep inferior to CricoidCartilag");
+ // load Cricoid, get centroid, cut above (or below), lower bound
+ MaskImagePointType p;
+ try {
+ MaskImagePointer CricoidCartilag = this->GetAFDB()->template GetImage <MaskImageType>("CricoidCartilag");
+ p[0] = p[1] = p[2] = 0.0; // to avoid warning
+ clitk::FindExtremaPointInAGivenDirection<MaskImageType>(CricoidCartilag,
+ this->GetBackgroundValue(), 2, true, p);
+ } catch (clitk::ExceptionObject e) {
+ //DD("CricoidCartilag image not found, try CricoidCartilagZ");
+ this->GetAFDB()->GetPoint3D("CricoidCartilagPoint", p);
+ }
+ output = clitk::CropImageRemoveGreaterThan<MaskImageType>(output, 2, p[2], true, this->GetBackgroundValue());
+ this->template StopCurrentStep<MaskImageType>(output);