Browse Source

always use double channels in convTrees

Sven Sickert 10 years ago
parent
commit
9088103219
1 changed files with 26 additions and 12 deletions
  1. 26 12
      semseg/SemSegConvolutionalTree.cpp

+ 26 - 12
semseg/SemSegConvolutionalTree.cpp

@@ -52,16 +52,16 @@ SemSegConvolutionalTree::~SemSegConvolutionalTree ()
 
 void SemSegConvolutionalTree::convertRGBToHSV ( CachedExample *ce ) const
 {
-    assert( imgHSV->channels() == 0 );
-
     NICE::MultiChannelImageT<int> * img = NULL;
-    NICE::MultiChannelImageT<double> * imgHSV = NULL;
+    NICE::MultiChannelImageT<double> * imgD = NULL;
     img     = & ce->getIChannel( CachedExample::I_COLOR );
-    imgHSV  = & ce->getDChannel( CachedExample::D_EOH );
+    imgD    = & ce->getDChannel( CachedExample::D_EOH );
+
+    assert( imgD->channels() == 0 );
 
     if ( img->channels() == 3 )
     {
-        imgHSV->reInit ( img->width(), img->height(), 3 );
+        imgD->reInit ( img->width(), img->height(), 3 );
 
         for ( int y = 0; y < img->height(); y++ )
             for ( int x = 0; x < img->width(); x++ )
@@ -73,19 +73,33 @@ void SemSegConvolutionalTree::convertRGBToHSV ( CachedExample *ce ) const
 
                 ColorConversion::ccRGBtoHSV(r, g, b, &h, &s, &v);
 
-                imgHSV->set( x, y, h, 0);
-                imgHSV->set( x, y, h, 1);
-                imgHSV->set( x, y, h, 2);
+                imgD->set( x, y, h, 0);
+                imgD->set( x, y, s, 1);
+                imgD->set( x, y, v, 2);
             }
 
-        // remove r,g,b (integer) channels
+        // remove integer channels
         img->freeData();
-        img = NULL;
     }
-    else
+    else if ( img->channels() == 1 )
     {
-        imgHSV = NULL;
+        // gray values to range [0,1]
+        imgD->reInit ( img->width(), img->height(), 1 );
+
+        for ( int y = 0; y < img->height(); y++ )
+            for ( int x = 0; x < img->width(); x++ )
+            {
+                double g = (double)img->get( x, y, 0) / 255.0;
+                imgD->set( x, y, g, 0);
+            }
+
+        // remove integer channel
+        img->freeData();
+
     }
+
+    img = NULL;
+    imgD = NULL;
 }