浏览代码

implementation for 'classify' in SemanticSegmentation

Sven Sickert 11 年之前
父节点
当前提交
e4cf835fa6

+ 1 - 3
progs/testSemanticSegmentation3D.cpp

@@ -209,10 +209,8 @@ int main ( int argc, char **argv )
       if ( depthCount < depthBoundary ) continue;
       if ( depthCount < depthBoundary ) continue;
 
 
       NICE::MultiChannelImage3DT<double> probabilities;
       NICE::MultiChannelImage3DT<double> probabilities;
-      NICE::MultiChannelImage3DT<double> imgData;
 
 
-      semseg->make3DImage ( filelist, imgData );
-      semseg->classify ( imgData, segresult, probabilities, filelist );
+      semseg->classify ( filelist, segresult, probabilities );
 
 
       // save to file
       // save to file
       for ( int z = 0; z < segresult.channels(); z++ )
       for ( int z = 0; z < segresult.channels(); z++ )

+ 0 - 6
semseg/SemSegContextTree.h

@@ -176,12 +176,6 @@ class SemSegContextTree : public SemanticSegmentation
      */
      */
     void train ( const MultiDataset *md );
     void train ( const MultiDataset *md );
 
 
-    void classify ( NICE::MultiChannelImage3DT<double> & imgData,
-                    NICE::MultiChannelImageT<double> & segresult,
-                    NICE::MultiChannelImage3DT<double> & probabilities,
-                    const std::vector<std::string> & filelist )
-    {}
-
     /**
     /**
      * @brief computes integral image of given feats
      * @brief computes integral image of given feats
      *
      *

+ 8 - 3
semseg/SemSegContextTree3D.cpp

@@ -1646,11 +1646,16 @@ void SemSegContextTree3D::addFeatureMaps (
 }
 }
 
 
 void SemSegContextTree3D::classify (
 void SemSegContextTree3D::classify (
-    NICE::MultiChannelImage3DT<double> & imgData,
+    const std::vector<std::string> & filelist,
     NICE::MultiChannelImageT<double> & segresult,
     NICE::MultiChannelImageT<double> & segresult,
-    NICE::MultiChannelImage3DT<double> & probabilities,
-    const std::vector<std::string> & filelist )
+    NICE::MultiChannelImage3DT<double> & probabilities )
 {
 {
+  ///////////////////////// build MCI3DT from files ///////////////////////////
+  /////////////////////////////////////////////////////////////////////////////
+
+  NICE::MultiChannelImage3DT<double> imgData;
+  this->make3DImage( filelist, imgData );
+
   int xsize = imgData.width();
   int xsize = imgData.width();
   int ysize = imgData.height();
   int ysize = imgData.height();
   int zsize = imgData.depth();
   int zsize = imgData.depth();

+ 6 - 7
semseg/SemSegContextTree3D.h

@@ -226,15 +226,14 @@ public:
   virtual ~SemSegContextTree3D();
   virtual ~SemSegContextTree3D();
 
 
   /**
   /**
-   * classify each pixel of a single 3d image
-   * @param imgData input data
-   * @param segresult segmentation results
-   * @param probabilities probabilities for each pixel
+   * classify each voxel of a 3D image (image stack)
+   * @param filelist filename list of images that represent slices of a stack
+   * @param segresult segmentation results (output)
+   * @param probabilities probabilities for each pixel (output)
    */
    */
-  void classify ( NICE::MultiChannelImage3DT<double> &imgData,
+  void classify ( const std::vector<std::string> & filelist,
                   NICE::MultiChannelImageT<double> & segresult,
                   NICE::MultiChannelImageT<double> & segresult,
-                  NICE::MultiChannelImage3DT<double> & probabilities,
-                  const std::vector<std::string> & filelist );
+                  NICE::MultiChannelImage3DT<double> & probabilities );
 
 
   /**
   /**
    * the training method with checking for already existing trained classifier from file
    * the training method with checking for already existing trained classifier from file

+ 0 - 6
semseg/SemSegCsurka.h

@@ -233,12 +233,6 @@ class SemSegCsurka : public SemanticSegmentation
                        NICE::Image & segresult,
                        NICE::Image & segresult,
                        NICE::MultiChannelImageT<double> & probabilities );
                        NICE::MultiChannelImageT<double> & probabilities );
 
 
-    void classify ( NICE::MultiChannelImage3DT<double> & imgData,
-                    NICE::MultiChannelImageT<double> & segresult,
-                    NICE::MultiChannelImage3DT<double> & probabilities,
-                    const std::vector<std::string> & filelist )
-    {}
-
     /** this procedure is equal semanticseg, if there is no post process
     /** this procedure is equal semanticseg, if there is no post process
     * @param ce image data
     * @param ce image data
     * @param segresult result of the semantic segmentation with a label for each pixel
     * @param segresult result of the semantic segmentation with a label for each pixel

+ 0 - 6
semseg/SemSegNovelty.h

@@ -244,12 +244,6 @@ class SemSegNovelty : public SemanticSegmentation
     void semanticseg ( CachedExample *ce,
     void semanticseg ( CachedExample *ce,
                        NICE::Image & segresult,
                        NICE::Image & segresult,
                        NICE::MultiChannelImageT<double> & probabilities );
                        NICE::MultiChannelImageT<double> & probabilities );
-    
-    void classify ( NICE::MultiChannelImage3DT<double> & imgData,
-                    NICE::MultiChannelImageT<double> & segresult,
-                    NICE::MultiChannelImage3DT<double> & probabilities,
-                    const std::vector<std::string> & filelist )
-    {}
 
 
     /**
     /**
      * @brief visualize a specific region in the original image
      * @brief visualize a specific region in the original image

+ 0 - 6
semseg/SemSegNoveltyBinary.h

@@ -197,12 +197,6 @@ class SemSegNoveltyBinary : public SemanticSegmentation
                        NICE::Image & segresult,
                        NICE::Image & segresult,
                        NICE::MultiChannelImageT<double> & probabilities );
                        NICE::MultiChannelImageT<double> & probabilities );
     
     
-    void classify ( NICE::MultiChannelImage3DT<double> & imgData,
-                    NICE::MultiChannelImageT<double> & segresult,
-                    NICE::MultiChannelImage3DT<double> & probabilities,
-                    const std::vector<std::string> & filelist )
-    {}
-    
     /**
     /**
      * @brief visualize a specific region in the original image
      * @brief visualize a specific region in the original image
      *
      *

+ 15 - 1
semseg/SemanticSegmentation.cpp

@@ -89,10 +89,24 @@ void SemanticSegmentation::semanticseg ( const std::string & filename,
     ce = new CachedExample ( img );
     ce = new CachedExample ( img );
   }
   }
   fprintf ( stderr, "Starting Semantic Segmentation !\n" );
   fprintf ( stderr, "Starting Semantic Segmentation !\n" );
-  semanticseg ( ce, segresult, probabilities );
+  this->semanticseg ( ce, segresult, probabilities );
   delete ce;
   delete ce;
 }
 }
 
 
+void SemanticSegmentation::classify ( const std::vector<std::string> & filelist,
+                                      NICE::MultiChannelImageT<double> & segresult,
+                                      NICE::MultiChannelImage3DT<double> & probabilities )
+{
+  for ( int it = 0; it < ( int ) filelist.size(); it++ )
+  {
+    NICE::MultiChannelImageT<double> probs;
+    NICE::Image res ( segresult.width(), segresult.height() );
+    this->semanticseg( filelist[it], res, probs );
+    probabilities.addChannel( probs );
+    segresult.addChannel( res );
+  }
+}
+
 ///////////////////// ///////////////////// /////////////////////
 ///////////////////// ///////////////////// /////////////////////
 //                      DATA CONVERSION
 //                      DATA CONVERSION
 ///////////////////// ///////////////////// ///////////////////// 
 ///////////////////// ///////////////////// ///////////////////// 

+ 11 - 13
semseg/SemanticSegmentation.h

@@ -102,6 +102,17 @@ class SemanticSegmentation : public NICE::Persistent
                        NICE::Image & segresult,
                        NICE::Image & segresult,
                        NICE::MultiChannelImageT<double> & probabilities );
                        NICE::MultiChannelImageT<double> & probabilities );
 
 
+    /**
+     * Classify each voxel of a 3D image (image stack)
+     * @author Sven Sickert
+     * @param filelist filename list of images that represent slices of a stack
+     * @param segresult segmentation results (output)
+     * @param probabilities probabilities for each pixel (output)
+     */
+    void classify ( const std::vector<std::string> & filelist,
+                    NICE::MultiChannelImageT<double> & segresult,
+                    NICE::MultiChannelImage3DT<double> & probabilities );
+
     /** this function has to be overloaded by all subclasses
     /** this function has to be overloaded by all subclasses
         @param ce image data
         @param ce image data
         @param segresult result of the semantic segmentation with a label for each
         @param segresult result of the semantic segmentation with a label for each
@@ -113,19 +124,6 @@ class SemanticSegmentation : public NICE::Persistent
                                NICE::Image & segresult,
                                NICE::Image & segresult,
                                NICE::MultiChannelImageT<double> & probabilities ) = 0;
                                NICE::MultiChannelImageT<double> & probabilities ) = 0;
 
 
-    /**
-     * @brief Classification function (has to be overloaded by all subclasses)
-     * @author Sven Sickert
-     * @param imgData image data
-     * @param segresult result of the semantic segmentation with a label for each pixel
-     * @param probabilities multi-channel image with one channel for each class and
-     *        corresponding probabilities for each pixel
-     * @param filelist filename list of images that represent slices of a stack
-     */
-    virtual void classify ( NICE::MultiChannelImage3DT<double> & imgData,
-                            NICE::MultiChannelImageT<double> & segresult,
-                            NICE::MultiChannelImage3DT<double> & probabilities,
-                            const std::vector<std::string> & filelist ) = 0;
 
 
     /** training function (has to be overloaded by all subclasses)
     /** training function (has to be overloaded by all subclasses)
      * @param md the data set
      * @param md the data set