Forráskód Böngészése

added missing rand init

Sven Sickert 9 éve
szülő
commit
8a820eb767
2 módosított fájl, 32 hozzáadás és 2 törlés
  1. 3 0
      semseg/SemSegContextTree.cpp
  2. 29 2
      semseg/SemSegContextTree3D.cpp

+ 3 - 0
semseg/SemSegContextTree.cpp

@@ -17,6 +17,7 @@
 #include "core/basics/vectorio.h"
 #include "core/image/FilterT.h"
 
+#include <time.h>
 #include <omp.h>
 #include <iostream>
 
@@ -170,6 +171,8 @@ SemSegContextTree::SemSegContextTree (const Config *conf, const MultiDataset *md
 
   classnames = md->getClassNames ("train");
 
+  srand(time(NULL));
+
   ///////////////////////////////////
   // Train Segmentation Context Trees
   ///////////////////////////////////

+ 29 - 2
semseg/SemSegContextTree3D.cpp

@@ -6,7 +6,6 @@
 #include <core/basics/StringTools.h>
 #include <core/basics/Timer.h>
 #include <core/basics/vectorio.h>
-#include <core/image/Filter.h>
 #include <core/image/FilterT.h>
 #include <core/image/Morph.h>
 #include <core/imagedisplay/ImageDisplay.h>
@@ -22,6 +21,7 @@
 #include <segmentation/RSSlic.h>
 
 #include <omp.h>
+#include <time.h>
 #include <iostream>
 
 #define VERBOSE
@@ -72,6 +72,8 @@ SemSegContextTree3D::SemSegContextTree3D () : SemanticSegmentation ()
 
     if (coarseMode)
         this->labelIncrement = 6;
+
+    srand(time(NULL));
 }
 
 
@@ -164,6 +166,8 @@ SemSegContextTree3D::SemSegContextTree3D (
     if ( useFeat4 )
         this->featTypes.push_back(4);
 
+    srand(time(NULL));
+
     this->initOperations();
 }
 
@@ -710,7 +714,12 @@ void SemSegContextTree3D::train ( const LabeledSet * trainp )
         rawChannels = 1;
 
     if ( useGradient )
-        rawChannels *= 3;   // gx, gy, gz
+    {
+        if ( run3Dseg )
+            rawChannels *= 4;   // gx, gy, gz
+        else
+            rawChannels *= 3;   // gx, gy
+    }
 
     if ( useWeijer )      // Weijer Colornames
         rawChannels += 11;
@@ -1334,6 +1343,7 @@ void SemSegContextTree3D::addFeatureMaps (
         int currentsize = imgData.channels();
         imgData.addChannel ( 2*currentsize );
 
+        // gradients for X and Y
         for ( int z = 0; z < zsize; z++ )
             for ( int c = 0; c < currentsize; c++ )
             {
@@ -1349,6 +1359,23 @@ void SemSegContextTree3D::addFeatureMaps (
                         imgData.set( x, y, z, sobY.getPixelQuick(x,y), c+(currentsize*2) );
                     }
             }
+
+        // gradients for Z
+        if ( run3Dseg )
+        {
+            imgData.addChannel ( currentsize );
+            for ( int x = 0; x < xsize; x++ )
+                for ( int c = 0; c < currentsize; c++ )
+                {
+                    ImageT<double> tmp = imgData.getXSlice(x, c);
+                    ImageT<double> sobZ( zsize, ysize );
+                    NICE::FilterT<double, double, double>::sobelX ( tmp, sobZ );
+                    for ( int y = 0; y < ysize; y++ )
+                        for ( int z = 0; z < zsize; z++ )
+                            imgData.set( x, y, z, sobZ.getPixelQuick(z,y), c+(currentsize*3) );
+                }
+        }
+
     }
 
     // Weijer color names