]> Creatis software - clitk.git/blobdiff - itk/clitkSegmentationUtils.txx
Romulo:
[clitk.git] / itk / clitkSegmentationUtils.txx
index 42ddc4759867b1231016ca847ade9c65d403068b..00f3392f17a91477f3c4bc5790da0c97f05f95a0 100644 (file)
@@ -297,7 +297,8 @@ namespace clitk {
   {
     typename ImageType::Pointer working_image;
     working_image = Labelize<ImageType>(input, BG, isFullyConnected, minimalComponentSize);
-    working_image = RemoveLabels<ImageType>(working_image, BG, param->GetLabelsToRemove());
+    if (param->GetLabelsToRemove().size() != 0)
+      working_image = RemoveLabels<ImageType>(working_image, BG, param->GetLabelsToRemove());
     working_image = KeepLabels<ImageType>(working_image, 
                                           BG, FG, 
                                           param->GetFirstKeep(), 
@@ -336,7 +337,8 @@ namespace clitk {
                                std::string orientation, 
                                bool uniqueConnectedComponent, 
                                double spacing, 
-                               bool inverseflag) 
+                               bool autocropFlag, 
+                               bool singleObjectCCL) 
   {
     typedef SliceBySliceRelativePositionFilter<MaskImageType> SliceRelPosFilterType;
     typename SliceRelPosFilterType::Pointer sliceRelPosFilter = SliceRelPosFilterType::New();
@@ -350,8 +352,10 @@ namespace clitk {
     sliceRelPosFilter->SetIntermediateSpacingFlag((spacing != -1));
     sliceRelPosFilter->SetIntermediateSpacing(spacing);
     sliceRelPosFilter->SetUniqueConnectedComponentBySlice(uniqueConnectedComponent);
-    sliceRelPosFilter->SetInverseOrientationFlag(inverseflag);
-    //  sliceRelPosFilter->SetAutoCropFlag(true); ??
+    sliceRelPosFilter->SetUseASingleObjectConnectedComponentBySliceFlag(singleObjectCCL);
+    //    sliceRelPosFilter->SetInverseOrientationFlag(inverseflag); 
+    sliceRelPosFilter->SetAutoCropFlag(autocropFlag); 
+    sliceRelPosFilter->IgnoreEmptySliceObjectFlagOn();
     sliceRelPosFilter->Update();
     return sliceRelPosFilter->GetOutput();
   }
@@ -384,7 +388,7 @@ namespace clitk {
     /*
       loop over input pixels, store the index in the fg that is max
       according to the given direction. 
-    */
+    */    
     typedef itk::ImageRegionConstIteratorWithIndex<ImageType> IteratorType;
     IteratorType iter(input, input->GetLargestPossibleRegion());
     iter.GoToBegin();
@@ -531,27 +535,6 @@ namespace clitk {
   //--------------------------------------------------------------------
 
 
-  //--------------------------------------------------------------------
-  template<class ImageType>
-  typename ImageType::Pointer
-  JoinSlices(std::vector<typename itk::Image<typename ImageType::PixelType, 
-                                             ImageType::ImageDimension-1>::Pointer > & slices, 
-             const ImageType * input, 
-             int direction) {
-    typedef typename itk::Image<typename ImageType::PixelType, ImageType::ImageDimension-1> SliceType;
-    typedef itk::JoinSeriesImageFilter<SliceType, ImageType> JoinSeriesFilterType;
-    typename JoinSeriesFilterType::Pointer joinFilter = JoinSeriesFilterType::New();
-    joinFilter->SetOrigin(input->GetOrigin()[direction]);
-    joinFilter->SetSpacing(input->GetSpacing()[direction]);
-    for(unsigned int i=0; i<slices.size(); i++) {
-      joinFilter->PushBackInput(slices[i]);
-    }
-    joinFilter->Update();
-    return joinFilter->GetOutput();
-  }
-  //--------------------------------------------------------------------
-
-
   //--------------------------------------------------------------------
   template<class ImageType>
   void
@@ -919,5 +902,60 @@ namespace clitk {
   //--------------------------------------------------------------------
 
 
+  //--------------------------------------------------------------------
+  /* Consider an input object, for each slice, find the extrema
+     position according to a given direction and build a line segment
+     passing throught this point in a given direction.  Output is a
+     vector of line (from point A to B), for each slice;
+   */
+  template<class ImageType>
+  void 
+  SliceBySliceBuildLineSegmentAccordingToExtremaPosition(const ImageType * input, 
+                                                         typename ImageType::PixelType BG, 
+                                                         int sliceDimension, 
+                                                         int extremaDirection, 
+                                                         bool extremaOppositeFlag, 
+                                                         int lineDirection,
+                                                         double margin,
+                                                         std::vector<typename ImageType::PointType> & A, 
+                                                         std::vector<typename ImageType::PointType> & B)
+  {
+    // Type of a slice
+    typedef typename itk::Image<typename ImageType::PixelType, ImageType::ImageDimension-1> SliceType;
+    
+    // Build the list of slices
+    std::vector<typename SliceType::Pointer> slices;
+    clitk::ExtractSlices<ImageType>(input, sliceDimension, slices);
+
+    // Build the list of 2D points
+    std::map<int, typename SliceType::PointType> position2D;
+    for(uint i=0; i<slices.size(); i++) {
+      typename SliceType::PointType p;
+      bool found = 
+        clitk::FindExtremaPointInAGivenDirection<SliceType>(slices[i], BG, 
+                                                            extremaDirection, extremaOppositeFlag, p);
+      if (found) {
+        position2D[i] = p;
+      }    
+    }
+    
+    // Convert 2D points in slice into 3D points
+    clitk::PointsUtils<ImageType>::Convert2DTo3DList(position2D, input, A);
+    
+    // Create additional point just right to the previous ones, on the
+    // given lineDirection, in order to create a horizontal/vertical line.
+    for(uint i=0; i<A.size(); i++) {
+      typename ImageType::PointType p = A[i];
+      p[lineDirection] += 10;
+      B.push_back(p);
+      // Margins ?
+      A[i][1] += margin;
+      B[i][1] += margin;
+    }
+
+  }
+  //--------------------------------------------------------------------
+
+
 } // end of namespace