浏览代码

gen aenderungen

Bjoern Froehlich 12 年之前
父节点
当前提交
1e49c59ed2
共有 1 个文件被更改,包括 48 次插入2 次删除
  1. 48 2
      semseg/SemSegNovelty.cpp

+ 48 - 2
semseg/SemSegNovelty.cpp

@@ -556,8 +556,54 @@ void SemSegNovelty::semanticseg ( CachedExample *ce, NICE::Image & segresult, NI
   if(regionSeg != NULL)
   {
     NICE::Matrix mask;
-    int regionsize = regionSeg->segRegions ( img, mask );
-    probabilities ( xl, yl, j ) = cr.scores[j];
+    int amountRegions = regionSeg->segRegions ( img, mask );
+    
+    //compute probs per region
+    vector<vector<double> > regionProb(amountRegions,vector<double>(probabilities.channels(),0.0);
+    vector<int> regionCounter(amountRegions, 0);
+    for ( int y = 0; y < ysize; y++)
+    {
+      for (int x = 0; x < xsize; x++)
+      {
+        int r = mask(x,y);
+        regionCounter[r]++;
+        for(int j = 0; j < probabilities.channels(); j++)
+        {
+          regionProb[r][j] = probabilities ( x, y, j );
+        }
+      }
+    }
+    
+    //find best class per region
+    vector<int> bestClassPerRegion(amountRegions,0);
+    
+    for(int r = 0; r < amountRegions; r++)
+    {
+      double maxval = -numeric_limit<double>::max();
+      for(int c = 0; c < probabilities.channels(); c++)
+      {
+        regionProb[r][c] /= regionCounter[r];
+        if(maxval < regionProb[r][c])
+        {
+          maxval = regionProb[r][c];
+          bestClassPerRegion[r] = c;
+        }
+      }
+    }
+    
+    //write back best results per region
+    for ( int y = 0; y < ysize; y++)
+    {
+      for (int x = 0; x < xsize; x++)
+      {
+        int r = mask(x,y);
+        for(int j = 0; j < probabilities.channels(); j++)
+        {
+          probabilities ( x, y, j ) = regionProb[r][j];
+        }
+        segresult(x,y) = bestClassPerRegion[r];
+      }
+    }
   }
 
   timer.stop();