Ver código fonte

MCI3DT: added shading correction

Sven Sickert 12 anos atrás
pai
commit
0b1dca5ddc

+ 5 - 1
image/MultiChannelImage3DT.h

@@ -5,6 +5,7 @@
 #include <core/image/ImageT.h>
 #include <core/image/MultiChannelImageT.h>
 
+#include <vector>
 #include <fstream>
 
 namespace NICE {
@@ -141,12 +142,15 @@ public:
   /** calculate image statistics */
   void statistics( P & min, P & max, uint channel = 0 ) const;
 
+  /** correct inhomogeneous illuminations (shading) between the image slices **/
+  void correctShading( uint channel = 0 ) const;
+  
   /** dump all data to RAW format: xsize, ysize, numChannels, <data> */
   void store( std::string filename ) const;
 
   /** read all data from RAW format: xsize, ysize, numChannels, <data> */
   void restore( std::string filename );
-
+  
   /** copy alls data to new object */
   MultiChannelImage3DT<P>& operator=( const MultiChannelImage3DT<P>& orig );
   

+ 39 - 0
image/MultiChannelImage3DT.tcc

@@ -1,6 +1,7 @@
 #include <iostream>
 #include <assert.h>
 #include <stdio.h>
+#include <vector>
 
 namespace NICE {
 template<class P>
@@ -346,6 +347,44 @@ void MultiChannelImage3DT<P>::statistics( P & min, P & max, uint channel ) const
   assert(finite(min));
 }
 
+template<class P>
+void MultiChannelImage3DT<P>::correctShading( uint channel ) const
+{
+  assert( channel < numChannels );
+  
+  std::vector<double> meanVals;
+  for( int z = 0; z < zsize; z++ )
+  {
+    double sumVal = 0;
+    for( int y = 0; y < ysize; y++ )
+    {
+      for( int x = 0; x < xsize; x++ )
+      {
+        sumVal += data [channel][x + y*xsize + z*xsize*ysize];
+      }
+    }
+    sumVal /= (xsize*ysize);
+    meanVals.push_back( sumVal );
+  }
+
+  P newMax = std::numeric_limits<P>::min();
+  short int maxVal = 255;
+  for ( int z = 0; z < zsize; z++ )
+  {
+    for ( int y = 0; y < ysize; y++ )
+    {
+      for ( int x = 0; x < xsize; x++ )
+      {
+        P tmp = data [channel][x + y*xsize + z*xsize*ysize];
+        double newVal = maxVal * ( (double) tmp / (double) meanVals[z] );
+        if ( ( P ) newVal > newMax )
+          newMax = ( P ) newVal;
+        data [channel][x + y*xsize + z*xsize*ysize] = newVal;
+      }
+    }
+  }
+}
+
 template<class P>
 Image MultiChannelImage3DT<P>::getChannel( int z, uint channel ) const
 {

+ 2 - 4
progs/testSemanticSegmentation.cpp

@@ -143,11 +143,9 @@ int main ( int argc, char **argv )
     gt.addChannel ( lm_gt );
 
     int depthBoundary = 0;
-    int zsize = 1;
     if ( run_3dseg )
     {
       depthBoundary = zsizeVec[idx];
-      zsize = zsizeVec[idx];
     }
 
     if ( depthCount < depthBoundary ) continue;
@@ -160,7 +158,7 @@ int main ( int argc, char **argv )
     fprintf ( stderr, "testSemanticSegmentation: Segmentation finished !\n" );
 
     // save to file
-    for ( int z = 0; z < zsize; z++ )
+    for ( int z = 0; z < segresult.channels(); z++ )
     {
       std::string fname = StringTools::baseName ( filelist[z], false );
 
@@ -233,7 +231,7 @@ int main ( int argc, char **argv )
     }
 
 //#pragma omp critical
-    for ( int z = 0; z < zsize; z++ )
+    for ( int z = 0; z < segresult.channels(); z++ )
     {
       for ( int y = 0 ; y < segresult.height(); y++ )
       {

Diferenças do arquivo suprimidas por serem muito extensas
+ 415 - 412
semseg/SemSegContextTree.cpp


+ 29 - 6
semseg/SemanticSegmentation.cpp

@@ -167,7 +167,7 @@ void SemanticSegmentation::getDepthVector ( const LabeledSet *Files, vector<int>
 {
   std::string oldName;
   int zsize = 0;
-	bool isInit = false;
+  bool isInit = false;
 
   LOOP_ALL_S ( *Files )
   {
@@ -179,11 +179,11 @@ void SemanticSegmentation::getDepthVector ( const LabeledSet *Files, vector<int>
     std::string filename = list.back();
     uint found = filename.find_last_of ( "_" );
     std::string curName = filename.substr ( found-3,3 );
-		if (!isInit)
-		{
-			oldName = curName;
-			isInit = true;
-		}
+    if ( !isInit )
+    {
+      oldName = curName;
+      isInit = true;
+    }
     if ( curName.compare ( oldName ) == 0 )
     {
       zsize++;
@@ -259,4 +259,27 @@ void SemanticSegmentation::make3DImage ( const std::vector<std::string> & fileli
       }
     }
   }
+
+  if ( imagetype == IMAGETYPE_GRAY )
+  {
+    imgData.correctShading( 0 );
+    double val_max, val_min;
+    imgData.statistics(val_min, val_max, 0);
+    if ( val_max > 255 )
+    {
+      for( int z = 0; z < imgData.depth(); z++ )
+      {
+        for ( int y = 0; y < imgData.height(); y++ )
+        {
+          for ( int x = 0; x < imgData.width(); x++ )
+          {
+            double val = imgData.get ( x, y, z, 0 );
+            val = val / val_max * 255;
+            imgData.set(x, y, z, val, 0);
+          }
+        }
+      }
+    }
+  }
 }
+

Alguns arquivos não foram mostrados porque muitos arquivos mudaram nesse diff