]> Creatis software - clitk.git/commitdiff
Add padding in clitkExtractPatient
authorVivien Delmon <vivien.delmon@creatis.insa-lyon.fr>
Wed, 8 Jun 2011 15:31:33 +0000 (17:31 +0200)
committerVivien Delmon <vivien.delmon@creatis.insa-lyon.fr>
Wed, 8 Jun 2011 15:31:33 +0000 (17:31 +0200)
Add padding around the patient to form one big air area around the
patient. ExtractPatient relies on this assumption which was false for
dir-labs patients cropped around the ribcage.

segmentation/clitkExtractPatientFilter.txx

index a04232b9d3a72119f973fa784cc9f2011aee6a52..74cc2ccd0f7cc1909b7c70f3335583a2eb88d8d7 100644 (file)
@@ -35,6 +35,7 @@
 #include "itkBinaryMorphologicalOpeningImageFilter.h"
 #include "itkBinaryBallStructuringElement.h"
 #include "itkCastImageFilter.h"
+#include "itkConstantPadImageFilter.h"
 
 //--------------------------------------------------------------------
 template <class TInputImageType>
@@ -113,9 +114,22 @@ GenerateOutputInformation() {
   //--------------------------------------------------------------------
   // Step 1: 
   StartNewStep("Find low densities areas");
+
+  // Pad images with air to prevent patient touching the image border
+  typedef itk::ConstantPadImageFilter<InputImageType, InputImageType> PadFilterType;
+  typename PadFilterType::Pointer padFilter = PadFilterType::New();
+  padFilter->SetInput(input);
+  padFilter->SetConstant(GetUpperThreshold() - 1);
+  typename InputImageType::SizeType bounds;
+  for (unsigned i = 0; i < Dim - 1; ++i)
+    bounds[i] = 1;
+  bounds[Dim - 1] = 0;
+  padFilter->SetPadLowerBound(bounds);
+  padFilter->SetPadUpperBound(bounds);
+
   typedef itk::BinaryThresholdImageFilter<InputImageType, InternalImageType> BinarizeFilterType;  
   typename BinarizeFilterType::Pointer binarizeFilter=BinarizeFilterType::New();
-  binarizeFilter->SetInput(input);
+  binarizeFilter->SetInput(padFilter->GetOutput());
   if (m_UseLowerThreshold) binarizeFilter->SetLowerThreshold(GetLowerThreshold());
   binarizeFilter->SetUpperThreshold(GetUpperThreshold());
   binarizeFilter ->SetInsideValue(this->GetForegroundValue());
@@ -257,6 +271,17 @@ GenerateOutputInformation() {
     output = cropFilter->GetOutput();
     StopCurrentStep<MaskImageType>(output);
   }
+  else
+  {
+    // Remove Padding region
+    typedef itk::CropImageFilter<MaskImageType, MaskImageType> CropFilterType;
+    typename CropFilterType::Pointer cropFilter = CropFilterType::New();
+    cropFilter->SetInput(output);
+    cropFilter->SetLowerBoundaryCropSize(bounds);
+    cropFilter->SetUpperBoundaryCropSize(bounds);
+    cropFilter->Update();
+    output = cropFilter->GetOutput();
+  }
 }
 //--------------------------------------------------------------------