]> Creatis software - clitk.git/blobdiff - itk/clitkSegmentationUtils.h
Add SliceBySliceRelativePosition with angles
[clitk.git] / itk / clitkSegmentationUtils.h
index 6fa67aa4ebed30d25a02b5f7faf3156948eb7eac..6972d154ab8f4436a672247090da66efff9eb331 100644 (file)
 #include "clitkCommon.h"
 #include "clitkAutoCropFilter.h"
 #include "clitkLabelizeParameters.h"
+#include "clitkExtractSliceFilter.h"
 
 // itk
 #include <itkBoundingBox.h>
+#include <itkJoinSeriesImageFilter.h>
 
 /*
   According to 
 namespace clitk {
 
   //--------------------------------------------------------------------
-  template<class ImageType>
-  void ComputeBBFromImageRegion(const ImageType * image, 
-                                typename ImageType::RegionType region,
-                                typename itk::BoundingBox<unsigned long, 
-                                                          ImageType::ImageDimension>::Pointer bb);
-  
-  //--------------------------------------------------------------------
-  template<int Dimension>
-  void ComputeBBIntersection(typename itk::BoundingBox<unsigned long, Dimension>::Pointer bbo, 
-                             typename itk::BoundingBox<unsigned long, Dimension>::Pointer bbi1, 
-                             typename itk::BoundingBox<unsigned long, Dimension>::Pointer bbi2);
-
-  //--------------------------------------------------------------------
-  template<class ImageType>
-  void ComputeRegionFromBB(const ImageType * image, 
-                           const typename itk::BoundingBox<unsigned long, 
-                                                           ImageType::ImageDimension>::Pointer bb, 
-                           typename ImageType::RegionType & region);
-  //--------------------------------------------------------------------
   template<class TInternalImageType, class TMaskInternalImageType>
   typename TInternalImageType::Pointer
   SetBackground(const TInternalImageType * input,
@@ -134,13 +117,6 @@ namespace clitk {
                           int minimalComponentSize,
                           LabelizeParameters<typename TImageType::PixelType> * param);
 
-  //--------------------------------------------------------------------
-  template<class ImageType>
-  typename ImageType::Pointer
-  ResizeImageLike(const ImageType * input,
-                  const itk::ImageBase<ImageType::ImageDimension> * like, 
-                  typename ImageType::PixelType BG);
-
 
   //--------------------------------------------------------------------
   template<class MaskImageType>
@@ -152,7 +128,20 @@ namespace clitk {
                               std::string orientation, 
                                bool uniqueConnectedComponent=false, 
                                double spacing=-1, 
-                              bool notflag=false);
+                               bool autocropflag=true, 
+                               bool singleObjectCCL=true);
+  template<class MaskImageType>
+  typename MaskImageType::Pointer
+  SliceBySliceRelativePosition(const MaskImageType * input,
+                              const MaskImageType * object,
+                              int direction, 
+                              double threshold, 
+                              double angle, 
+                               bool inverseflag,
+                               bool uniqueConnectedComponent=false, 
+                               double spacing=-1, 
+                               bool autocropflag=true, 
+                               bool singleObjectCCL=true);
 
   //--------------------------------------------------------------------
   // In a binary image, search for the point belonging to the FG that
@@ -190,32 +179,52 @@ namespace clitk {
                         typename ImageType::PixelType BG=0);
   template<class ImageType>
   typename ImageType::Pointer
-  CropImageAbove(const ImageType * image, 
-                 int dim, double min, bool autoCrop = false,
-                 typename ImageType::PixelType BG=0);
+  CropImageRemoveGreaterThan(const ImageType * image, 
+                             int dim, double min, bool autoCrop = false,
+                             typename ImageType::PixelType BG=0);
   template<class ImageType>
   typename ImageType::Pointer
-  CropImageBelow(const ImageType * image, 
-                 int dim, double max,bool autoCrop = false,
-                 typename ImageType::PixelType BG=0);
+  CropImageRemoveLowerThan(const ImageType * image, 
+                           int dim, double max,bool autoCrop = false,
+                           typename ImageType::PixelType BG=0);
   //--------------------------------------------------------------------
 
 
   //--------------------------------------------------------------------
+  template<class ImageType, class LabelType>
+  typename itk::LabelMap< itk::ShapeLabelObject<LabelType, ImageType::ImageDimension> >::Pointer
+  ComputeLabelMap(const ImageType * image, 
+                  typename ImageType::PixelType BG,                   
+                  bool computePerimeterFlag=false);
   template<class ImageType>
   void
   ComputeCentroids(const ImageType * image, 
                    typename ImageType::PixelType BG, 
                    std::vector<typename ImageType::PointType> & centroids);
+  template<class ImageType>
+  void
+  ComputeCentroids2(const ImageType * image, 
+                   typename ImageType::PixelType BG, 
+                   std::vector<typename ImageType::PointType> & centroids);
   //--------------------------------------------------------------------
 
 
   //--------------------------------------------------------------------
   template<class ImageType>
   void
-  ExtractSlices(const ImageType * image, int dim, 
-               std::vector< typename itk::Image<typename ImageType::PixelType, 
-                                                 ImageType::ImageDimension-1>::Pointer > & slices);
+  ExtractSlices(const ImageType * image, int direction,
+                std::vector<typename itk::Image<typename ImageType::PixelType,
+                                                ImageType::ImageDimension-1>::Pointer > & slices)
+  {
+    typedef ExtractSliceFilter<ImageType> ExtractSliceFilterType;
+    typedef typename ExtractSliceFilterType::SliceType SliceType;
+    typename ExtractSliceFilterType::Pointer
+      extractSliceFilter = ExtractSliceFilterType::New();
+    extractSliceFilter->SetInput(image);
+    extractSliceFilter->SetDirection(direction);
+    extractSliceFilter->Update();
+    extractSliceFilter->GetOutputSlices(slices);
+  }
   //--------------------------------------------------------------------
 
 
@@ -224,7 +233,19 @@ namespace clitk {
   typename ImageType::Pointer
   JoinSlices(std::vector<typename itk::Image<typename ImageType::PixelType, 
                                              ImageType::ImageDimension-1>::Pointer > & slices, 
-            const ImageType * input, int dim);
+             const itk::ImageBase<ImageType::ImageDimension> * input, //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();
+  }
   //--------------------------------------------------------------------
 
 
@@ -244,14 +265,20 @@ namespace clitk {
     
     typedef std::map<int, PointType2D> MapPoint2DType;
     typedef std::vector<PointType3D> VectorPoint3DType;
+    typedef std::vector<PointType2D> VectorPoint2DType;
+
   public:
     static void Convert2DTo3D(const PointType2D & p2D, 
                               const ImageType * image, 
                               const int slice, 
                               PointType3D & p3D);
-    static void Convert2DTo3DList(const MapPoint2DType & map, 
+    static void Convert2DMapTo3DList(const MapPoint2DType & map, 
                                   const ImageType * image, 
                                   VectorPoint3DType & list);
+    static void Convert2DListTo3DList(const VectorPoint2DType & p, 
+                                      int slice,
+                                      const ImageType * image, 
+                                      VectorPoint3DType & list);
   };
 
   //--------------------------------------------------------------------
@@ -283,6 +310,15 @@ namespace clitk {
          bool extendSupport);
   //--------------------------------------------------------------------
 
+
+  //--------------------------------------------------------------------
+  template<class ImageType>
+  typename ImageType::Pointer 
+  Opening(const ImageType * image, typename ImageType::SizeType radius,
+          typename ImageType::PixelType BG, typename ImageType::PixelType FG);
+  //--------------------------------------------------------------------
+
+
   //--------------------------------------------------------------------
   template<class ValueType, class VectorType>
   void ConvertOption(std::string optionName, uint given, 
@@ -309,6 +345,14 @@ namespace clitk {
   void AndNot(ImageType * input, 
               const ImageType * object, 
               typename ImageType::PixelType BG=0);
+  template<class ImageType>
+  void And(ImageType * input, 
+           const ImageType * object, 
+           typename ImageType::PixelType BG=0);
+  template<class ImageType>
+  void Or(ImageType * input, 
+          const ImageType * object, 
+          typename ImageType::PixelType BG=0);
   //--------------------------------------------------------------------
  
 
@@ -348,7 +392,103 @@ namespace clitk {
   IsOnTheSameLineSide(PointType C, PointType A, PointType B, PointType like);
   //--------------------------------------------------------------------
 
-}
+
+  //--------------------------------------------------------------------
+  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);  
+  template<class ImageType>
+  void 
+  SliceBySliceBuildLineSegmentAccordingToMinimalDistanceBetweenStructures(const ImageType * S1, 
+                                                                          const ImageType * S2, 
+                                                                          typename ImageType::PixelType BG, 
+                                                                          int sliceDimension, 
+                                                                          std::vector<typename ImageType::PointType> & A, 
+                                                                          std::vector<typename ImageType::PointType> & B);  
+  //--------------------------------------------------------------------
+
+
+  //--------------------------------------------------------------------
+  template<class ImageType>
+  typename ImageType::Pointer
+  SliceBySliceKeepMainCCL(const ImageType * input, 
+                          typename ImageType::PixelType BG,
+                          typename ImageType::PixelType FG);
+  //--------------------------------------------------------------------
+  
+
+  //--------------------------------------------------------------------
+  template<class ImageType>
+  typename ImageType::Pointer
+  Clone(const ImageType * input);
+  //--------------------------------------------------------------------
+  
+
+  //--------------------------------------------------------------------
+  template<class ImageType>
+  typename ImageType::Pointer
+  SliceBySliceSetBackgroundFromSingleLine(const ImageType * input, 
+                                          typename ImageType::PixelType BG, 
+                                          typename ImageType::PointType & A, 
+                                          typename ImageType::PointType & B, 
+                                          int dim1, int dim2, bool removeLowerPartFlag);
+  //--------------------------------------------------------------------
+  
+
+  //--------------------------------------------------------------------
+  template<class ImageType>
+  typename ImageType::Pointer
+  SliceBySliceSetBackgroundFromPoints(const ImageType * input, 
+                                      typename ImageType::PixelType BG, 
+                                      int sliceDim,
+                                      std::vector<typename ImageType::PointType> & A, 
+                                      bool removeGreaterThanXFlag,
+                                      bool removeGreaterThanYFlag);
+  //--------------------------------------------------------------------
+
+
+  //--------------------------------------------------------------------
+  template<class ImageType>
+  void
+  FillRegionWithValue(ImageType * input, typename ImageType::PixelType value, 
+                      typename ImageType::RegionType & region);
+  //--------------------------------------------------------------------
+
+
+  //--------------------------------------------------------------------
+  template<class ImageType>
+  void
+  GetMinMaxBoundary(ImageType * input, typename ImageType::PointType & min, 
+                    typename ImageType::PointType & max);
+  //--------------------------------------------------------------------
+
+
+  //--------------------------------------------------------------------
+  template<class ImageType>
+  typename itk::Image<float, ImageType::ImageDimension>::Pointer//void
+  DistanceMap(const ImageType * input, typename ImageType::PixelType BG);//, 
+  //--------------------------------------------------------------------
+
+
+  //--------------------------------------------------------------------
+  template<class ImageType>
+  typename ImageType::PointType
+  ComputeClosestPoint(const ImageType * input, 
+                      const itk::Image<float, ImageType::ImageDimension> * dmap, 
+                      typename ImageType::PixelType & BG);
+  //--------------------------------------------------------------------
+  
+
+
+} // end clitk namespace
 
 #include "clitkSegmentationUtils.txx"