]> Creatis software - clitk.git/commitdiff
Merge branch 'master' of /home/dsarrut/clitk3.server
authordsarrut <david.sarrut@gmail.com>
Thu, 9 Jun 2011 05:23:05 +0000 (07:23 +0200)
committerdsarrut <david.sarrut@gmail.com>
Thu, 9 Jun 2011 05:23:05 +0000 (07:23 +0200)
segmentation/clitkExtractPatientFilter.txx
tools/clitkCropImage.cxx
tools/clitkCropImage.ggo
tools/clitkCropImageGenericFilter.cxx
vv/vvImageContour.cxx
vv/vvToolCropImage.cxx

index a04232b9d3a72119f973fa784cc9f2011aee6a52..00e31653afce00e5ea32c5a91a1218fbe39251fa 100644 (file)
@@ -1,7 +1,7 @@
 /*=========================================================================
   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
 
-  Authors belong to: 
+  Authors belong to:
   - University of LYON              http://www.universite-lyon.fr/
   - Léon Bérard cancer center       http://www.centreleonberard.fr
   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
@@ -35,6 +35,7 @@
 #include "itkBinaryMorphologicalOpeningImageFilter.h"
 #include "itkBinaryBallStructuringElement.h"
 #include "itkCastImageFilter.h"
+#include "itkConstantPadImageFilter.h"
 
 //--------------------------------------------------------------------
 template <class TInputImageType>
@@ -68,11 +69,11 @@ ExtractPatientFilter():
   SetRadius2(r);
   SetMaximumNumberOfLabels2(2);
   SetNumberOfNewLabels2(1);
-  
+
   // Step 5: Only keep label corresponding (Keep patient's labels)
   SetFirstKeep(1);
   SetLastKeep(1);
-  
+
   // Step 4: OpenClose (option)
   FinalOpenCloseOff();
   AutoCropOn();
@@ -82,9 +83,9 @@ ExtractPatientFilter():
 
 //--------------------------------------------------------------------
 template <class TInputImageType>
-void 
+void
 clitk::ExtractPatientFilter<TInputImageType>::
-SetInput(const TInputImageType * image) 
+SetInput(const TInputImageType * image)
 {
   this->SetNthInput(0, const_cast<TInputImageType *>(image));
 }
@@ -93,9 +94,9 @@ SetInput(const TInputImageType * image)
 
 //--------------------------------------------------------------------
 template <class TInputImageType>
-void 
+void
 clitk::ExtractPatientFilter<TInputImageType>::
-GenerateOutputInformation() { 
+GenerateOutputInformation() {
 
   clitk::PrintMemory(GetVerboseMemoryFlag(), "Initial memory"); // OK
 
@@ -108,14 +109,27 @@ GenerateOutputInformation() {
   // Get input pointers
   static const unsigned int Dim = InputImageType::ImageDimension;
   //input = dynamic_cast<const TInputImageType*>(itk::ProcessObject::GetInput(0));
-    
+
   //--------------------------------------------------------------------
   //--------------------------------------------------------------------
-  // Step 1: 
+  // Step 1:
   StartNewStep("Find low densities areas");
-  typedef itk::BinaryThresholdImageFilter<InputImageType, InternalImageType> BinarizeFilterType;  
+
+  // 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());
@@ -127,7 +141,7 @@ GenerateOutputInformation() {
   connectFilter->SetInput(binarizeFilter->GetOutput());
   connectFilter->SetBackgroundValue(this->GetBackgroundValue());
   connectFilter->SetFullyConnected(false);
-  
+
   // Sort labels according to size
   typedef itk::RelabelComponentImageFilter<InternalImageType, InternalImageType> RelabelFilterType;
   typename RelabelFilterType::Pointer relabelFilter=RelabelFilterType::New();
@@ -135,13 +149,13 @@ GenerateOutputInformation() {
   relabelFilter->SetInput(connectFilter->GetOutput());
   relabelFilter->Update();
   working_image = relabelFilter->GetOutput();
-  
+
   // End
   StopCurrentStep<InternalImageType>(working_image);
 
   //--------------------------------------------------------------------
   //--------------------------------------------------------------------
-  // [Optional] 
+  // [Optional]
   if (GetDecomposeAndReconstructDuringFirstStep()) {
     StartNewStep("First Decompose & Reconstruct step");
     typedef clitk::DecomposeAndReconstructImageFilter<InternalImageType,InternalImageType> FilterType;
@@ -158,11 +172,11 @@ GenerateOutputInformation() {
     working_image = f->GetOutput();
     StopCurrentStep<InternalImageType>(working_image);
   }
-  
+
   //--------------------------------------------------------------------
   //--------------------------------------------------------------------
   StartNewStep("Remove the air (largest area)");
-  typedef itk::BinaryThresholdImageFilter<InternalImageType, InternalImageType> iBinarizeFilterType;  
+  typedef itk::BinaryThresholdImageFilter<InternalImageType, InternalImageType> iBinarizeFilterType;
   typename iBinarizeFilterType::Pointer binarizeFilter2 = iBinarizeFilterType::New();
   binarizeFilter2->SetInput(working_image);
   binarizeFilter2->SetLowerThreshold(GetFirstKeep());
@@ -180,15 +194,15 @@ GenerateOutputInformation() {
   relabelFilter2->SetInput(connectFilter2->GetOutput());
   relabelFilter2->Update();
   working_image = relabelFilter2->GetOutput();
-  
+
   // Keep main label
   working_image = KeepLabels<InternalImageType>
-    (working_image, GetBackgroundValue(), GetForegroundValue(), 1, 1, true);  
+    (working_image, GetBackgroundValue(), GetForegroundValue(), 1, 1, true);
   StopCurrentStep<InternalImageType>(working_image);
 
   //--------------------------------------------------------------------
   //--------------------------------------------------------------------
-  // [Optional] 
+  // [Optional]
   if (GetDecomposeAndReconstructDuringSecondStep()) {
     StartNewStep("Second Decompose & Reconstruct step");
     typedef clitk::DecomposeAndReconstructImageFilter<InternalImageType,InternalImageType> FilterType;
@@ -221,7 +235,7 @@ GenerateOutputInformation() {
     openFilter->SetInput(working_image);
     openFilter->SetBackgroundValue(this->GetBackgroundValue());
     openFilter->SetForegroundValue(this->GetForegroundValue());
-    openFilter->SetKernel(structuringElement);  
+    openFilter->SetKernel(structuringElement);
     // Close
     typedef itk::BinaryMorphologicalClosingImageFilter<InternalImageType, InternalImageType , KernelType> CloseFilterType;
     typename CloseFilterType::Pointer closeFilter = CloseFilterType::New();
@@ -230,14 +244,14 @@ GenerateOutputInformation() {
     closeFilter->SetForegroundValue(this->GetForegroundValue());
     //  closeFilter->SetBackgroundValue(SetBackgroundValue());
     closeFilter->SetKernel(structuringElement);
-    closeFilter->Update();  
+    closeFilter->Update();
     working_image = closeFilter->GetOutput();
     StopCurrentStep<InternalImageType>(working_image);
   }
 
   //--------------------------------------------------------------------
   //--------------------------------------------------------------------
-  // Final Cast 
+  // Final Cast
   typedef itk::CastImageFilter<InternalImageType, MaskImageType> CastImageFilterType;
   typename CastImageFilterType::Pointer caster= CastImageFilterType::New();
   caster->SetInput(working_image);
@@ -253,26 +267,37 @@ GenerateOutputInformation() {
     typename CropFilterType::Pointer cropFilter = CropFilterType::New();
     cropFilter->SetInput(output);
     cropFilter->SetBackgroundValue(GetBackgroundValue());
-    cropFilter->Update();   
+    cropFilter->Update();
     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();
+  }
 }
 //--------------------------------------------------------------------
 
 
 //--------------------------------------------------------------------
 template <class TInputImageType>
-void 
+void
 clitk::ExtractPatientFilter<TInputImageType>::
 GenerateData() {
   // Final Graft
   this->GraftOutput(output);
   // Store image filename into AFDB
-  GetAFDB()->SetImageFilename("Patient", this->GetOutputPatientFilename());  
+  GetAFDB()->SetImageFilename("Patient", this->GetOutputPatientFilename());
   WriteAFDB();
 }
 //--------------------------------------------------------------------
-  
+
 
 #endif //#define CLITKBOOLEANOPERATORLABELIMAGEFILTER_TXX
index 8e557139501b3ba72393231faecfd1221a1881ff..3c6725cdccd056c1c501f373e1d2d84716db0634 100644 (file)
@@ -34,7 +34,7 @@ int main(int argc, char * argv[])
 
   filter->SetArgsInfo(args_info);
 
-  try {
+  try { 
     filter->Update();
   } catch(std::runtime_error e) {
     std::cout << e.what() << std::endl;
index e8650de42447336cd1b09755ac4cabdc99313f33..a674f8bbef5b5450493a3c0eae14ccde4acb0579 100644 (file)
@@ -15,7 +15,7 @@ option "input"                i       "Input image filename"            string        yes
 option "output"        o       "Output image filename"           string        yes
 
 section "Used determined crop"
-option "boundingBox"           b       "Bounding box of the crop region (in 2D: =x1,y2, x2,y2)"  int   no  multiple
+option "boundingBox"           b       "Bounding box of the crop region (in 3D: =x1,x2,y1,y2,z1,z2)"  int      no  multiple
 option "lower"         l       "Size of the lower crop region (multiple values)"         int   no  multiple
 option "upper"         u       "Size of the upper crop region (multiple values)"         int   no  multiple
 option "origin"        -       "Set new origin to zero"          flag  off  
index b062976b678b4dac3abe72804dd6dbda572c81aa..5c78d4ea436355e1d8e459ba8a69e9eac3f5d36d 100644 (file)
@@ -79,6 +79,7 @@ namespace clitk
   { 
     // Reading input
     typename ImageType::Pointer input = this->template GetInput<ImageType>(0);
+    typename ImageType::RegionType input_region = input->GetLargestPossibleRegion();
 
     // Check options
     if (mArgsInfo.BG_given && mArgsInfo.like_given)
@@ -123,10 +124,11 @@ namespace clitk
         // ------------------------------------------------
         typename ImageType::SizeType lSize;
         typename ImageType::SizeType uSize;
+        if (mArgsInfo.verbose_flag) std::cout << "input region " << input_region << std::endl;
         if (mArgsInfo.boundingBox_given) {
           for(unsigned int i=0; i<ImageType::ImageDimension; i++) {
             lSize[i] = mArgsInfo.boundingBox_arg[2*i];
-            uSize[i] = input->GetLargestPossibleRegion().GetSize()[i]-mArgsInfo.boundingBox_arg[2*i+1]-1;
+            uSize[i] = input_region.GetSize()[i]-mArgsInfo.boundingBox_arg[2*i+1]-1;
           }
         }
         else {
@@ -141,6 +143,11 @@ namespace clitk
           }
           else uSize.Fill(0);
         }
+        
+        if (mArgsInfo.verbose_flag) {
+          std::cout << "lower " << lSize << " upper " << uSize << std::endl;
+        }
+        
         typedef  itk::CropImageFilter<ImageType, ImageType> CropImageFilterType;
         typename CropImageFilterType::Pointer filter=CropImageFilterType::New();
         filter->SetInput(input);
@@ -157,6 +164,14 @@ namespace clitk
       origin.Fill(itk::NumericTraits<double>::Zero);
       output->SetOrigin(origin);
     }
+    
+    // force index to zero
+    typename ImageType::RegionType region;
+    region = output->GetLargestPossibleRegion();
+    typename ImageType::IndexType index;
+    index.Fill(itk::NumericTraits<double>::Zero);
+    region.SetIndex(index);
+    output->SetRegions(region);
 
     // Write/Save results
     this->template SetNextOutput<ImageType>(output); 
index 27703963c345be05e09715957a59423295319d38..94129031759648c7808a40f6216b12b95ef74d1d 100644 (file)
@@ -267,6 +267,7 @@ void vvImageContour::CreateNewActor(int numImage) {
     clipper->SetInput(mHiddenImage->GetVTKImages()[0]);
   else
     clipper->SetInput(mSlicer->GetImage()->GetVTKImages()[numImage]);
+  
   squares->SetInput(clipper->GetOutput());
   squaresMapper->SetInput(squares->GetOutput());
   squaresMapper->ScalarVisibilityOff();
@@ -333,8 +334,6 @@ void vvImageContour::UpdateActor(vtkActor * actor,
   clipper->SetOutputWholeExtent(extent2[0],extent2[1],extent2[2],
                                 extent2[3],extent2[4],extent2[5]);
 
-  //std::cout << mTSlice << " " << mSlice << " " << extent2[0] << " " << extent2[1] << " " << extent2[2] << " " << extent2[3] << " " << extent2[4] << " " << extent2[5] << std::endl;
-
   if (mHiddenImageIsUsed) delete extent2;
 
   // Move the actor to be visible
@@ -342,47 +341,7 @@ void vvImageContour::UpdateActor(vtkActor * actor,
   position[orientation] = -1;
   actor->SetPosition(position);
   
-//   switch (orientation)  {
-//   case 0:
-//     actor->SetPosition(-1,0,0);
-//     /*
-//     // DD(mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[0]);
-//     if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[0] > slice) {
-//     actor->SetPosition(1,0,0);
-//     } else {
-//       actor->SetPosition(-1,0,0);
-//       }*/
-//     break;
-//   case 1:
-//     actor->SetPosition(0,-1,0);
-//     /*
-//     // DD(mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[1]);
-//     if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[1] > slice) {
-//       actor->SetPosition(0,1,0);
-//     } else {
-//       actor->SetPosition(0,-1,0);
-//     }
-//     */
-//     break;
-//   case 2:
-//     actor->SetPosition(0,0,-1);
-//     /*
-//     DD(mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[2]);
-//     if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[2] > slice) {
-//       DD("1");
-//       actor->SetPosition(0,0,1);
-//     } else {
-//      DD("-1");
-//       actor->SetPosition(0,0,-1);
-//     }
-//     */
-//     break;
-//   }
-
   mapper->Update();
-  
-  
 }
 //------------------------------------------------------------------------------
 
index 9d6d891bbadd2bafe01892278c72ffc2f1d09738..c3b55709722033a6445b9b3d0fb0c239ec1d5628 100644 (file)
@@ -274,15 +274,19 @@ void vvToolCropImage::apply()
   catch(clitk::ExceptionObject & e) {
     DD(e.what());
     QApplication::restoreOverrideCursor();
+    delete [] mArgsInfo.boundingBox_arg;
     close();
   }
   std::ostringstream croppedImageName;
   croppedImageName << "Cropped_" << mCurrentSlicerManager->GetSlicer(0)->GetFileName() << ".mhd";
   // Retrieve result and display it
   vvImage::Pointer output = filter->GetOutputVVImage();
+  
   AddImage(output,croppedImageName.str());
+  
   // End
   QApplication::restoreOverrideCursor();
+  delete [] mArgsInfo.boundingBox_arg;
   close();
 }
 //------------------------------------------------------------------------------