Prechádzať zdrojové kódy

fixed bug in overlay image creation

Sven Sickert 9 rokov pred
rodič
commit
be62344735
2 zmenil súbory, kde vykonal 7 pridanie a 62 odobranie
  1. 3 48
      progs/testSemanticSegmentation3D.cpp
  2. 4 14
      semseg/SemSegTools.cpp

+ 3 - 48
progs/testSemanticSegmentation3D.cpp

@@ -17,6 +17,7 @@
 
 
 #include "core/image/MultiChannelImage3DT.h"
 #include "core/image/MultiChannelImage3DT.h"
 #include "semseg/semseg/SemSegContextTree3D.h"
 #include "semseg/semseg/SemSegContextTree3D.h"
+#include "semseg/semseg/SemSegTools.h"
 
 
 #include "core/basics/ResourceStatistics.h"
 #include "core/basics/ResourceStatistics.h"
 #include "core/image/Morph.h"
 #include "core/image/Morph.h"
@@ -32,52 +33,6 @@ using namespace NICE;
 
 
 using namespace std;
 using namespace std;
 
 
-void segmentToOverlay ( const NICE::Image *orig, const NICE::ColorImage & segment,
-                        NICE::ColorImage & result )
-{
-  int xsize = orig->width();
-  int ysize = orig->height();
-  
-  result.resize( xsize, ysize );
-  vector< NICE::MatrixT<double> > channelMat;
-  
-  double alpha = .5;
-  
-  for (int c = 0; c < 3; c++)
-  {
-    NICE::MatrixT<double> chan ( xsize, ysize );
-    channelMat.push_back( chan );
-  }
-
-  for (int y = 0; y < ysize; y++)
-  {
-    for (int x = 0; x < xsize; x++)
-    {
-      uchar val = orig->getPixelQuick(x,y);
-      for (int c = 0; c < 3; c++)
-        channelMat[c](x,y) = (double)val + alpha*(double)segment.getPixel( x, y, c );
-    }
-  }
-  
-  for (int c = 0; c < 3; c++)
-  {
-    channelMat[c] /= channelMat[c].Max();
-    channelMat[c] *= 255;
-  }
-  
-  for (int y = 0; y < ysize; y++)
-  {
-    for (int x = 0; x < xsize; x++)
-    {
-      for (int c = 0; c < 3; c++)
-      {
-        int val = channelMat[c](x,y);
-        result.setPixel( x, y, c, (uchar)val);
-      }
-    }
-  }
-}
-
 void updateMatrix ( const NICE::ImageT<int> & img,
 void updateMatrix ( const NICE::ImageT<int> & img,
                     const NICE::ImageT<int> & gt,
                     const NICE::ImageT<int> & gt,
                     NICE::Matrix & M,
                     NICE::Matrix & M,
@@ -230,8 +185,8 @@ void startClassification (SemanticSegmentation *semseg,
 
 
           if ( write_results )
           if ( write_results )
           {
           {
-            segmentToOverlay ( orig.getChannel(1), rgb, ov_rgb );
-            segmentToOverlay ( orig.getChannel(1), rgb_gt, ov_rgb_gt );
+            SemSegTools::segmentToOverlay ( orig.getChannel(1), rgb, ov_rgb );
+            SemSegTools::segmentToOverlay ( orig.getChannel(1), rgb_gt, ov_rgb_gt );
 
 
             std::stringstream out;
             std::stringstream out;
             if ( output_postfix.size() > 0 )
             if ( output_postfix.size() > 0 )

+ 4 - 14
semseg/SemSegTools.cpp

@@ -28,7 +28,7 @@ void SemSegTools::segmentToOverlay (
     result.resize( xsize, ysize );
     result.resize( xsize, ysize );
     std::vector< NICE::MatrixT<double> > channelMat;
     std::vector< NICE::MatrixT<double> > channelMat;
 
 
-    double alpha = .5;
+    double alpha = .3;
 
 
     for (int c = 0; c < 3; c++)
     for (int c = 0; c < 3; c++)
     {
     {
@@ -37,32 +37,22 @@ void SemSegTools::segmentToOverlay (
     }
     }
 
 
     for (int y = 0; y < ysize; y++)
     for (int y = 0; y < ysize; y++)
-    {
         for (int x = 0; x < xsize; x++)
         for (int x = 0; x < xsize; x++)
         {
         {
             uchar val = orig->getPixelQuick(x,y);
             uchar val = orig->getPixelQuick(x,y);
             for (int c = 0; c < 3; c++)
             for (int c = 0; c < 3; c++)
-                channelMat[c](x,y) = (double)val + alpha*(double)segment.getPixel( x, y, c );
+                channelMat[c](x,y) = alpha*(double)val
+                                   + (1.0-alpha)*(double)segment.getPixel( x, y, c );
         }
         }
-    }
-
-    for (int c = 0; c < 3; c++)
-    {
-        channelMat[c] /= channelMat[c].Max();
-        channelMat[c] *= 255;
-    }
 
 
     for (int y = 0; y < ysize; y++)
     for (int y = 0; y < ysize; y++)
-    {
         for (int x = 0; x < xsize; x++)
         for (int x = 0; x < xsize; x++)
-        {
             for (int c = 0; c < 3; c++)
             for (int c = 0; c < 3; c++)
             {
             {
                 int val = channelMat[c](x,y);
                 int val = channelMat[c](x,y);
                 result.setPixel( x, y, c, (uchar)val);
                 result.setPixel( x, y, c, (uchar)val);
             }
             }
-        }
-    }
+
 }
 }
 
 
 void SemSegTools::updateConfusionMatrix(
 void SemSegTools::updateConfusionMatrix(