Эх сурвалжийг харах

fixed bug in rgb->hsv function for gray-scale images

Sven Sickert 10 жил өмнө
parent
commit
0a18751f72

+ 20 - 10
semseg/SemSegConvolutionalTree.cpp

@@ -50,17 +50,20 @@ SemSegConvolutionalTree::~SemSegConvolutionalTree ()
 
 //#################### MEMBER FUNCTIONS #######################//
 
-void SemSegConvolutionalTree::convertRGBToHSV ( CachedExample *ce ) const
+void SemSegConvolutionalTree::convertRGBToHSV (
+        CachedExample *ce,
+        bool isColor ) const
 {
     NICE::MultiChannelImageT<int> * img = NULL;
     NICE::MultiChannelImageT<double> * imgD = NULL;
-    img     = & ce->getIChannel( CachedExample::I_COLOR );
-    imgD    = & ce->getDChannel( CachedExample::D_EOH );
 
+    imgD    = & ce->getDChannel( CachedExample::D_EOH );
     assert( imgD->channels() == 0 );
 
-    if ( img->channels() == 3 )
+    if ( isColor )
     {
+        img = & ce->getIChannel( CachedExample::I_COLOR );
+
         imgD->reInit ( img->width(), img->height(), 3 );
 
         for ( int y = 0; y < img->height(); y++ )
@@ -81,8 +84,11 @@ void SemSegConvolutionalTree::convertRGBToHSV ( CachedExample *ce ) const
         // remove integer channels
         img->freeData();
     }
-    else if ( img->channels() == 1 )
+    // FIXME: never true because of CachedExample implementation of getXChannel
+    else
     {
+        img = & ce->getIChannel( CachedExample::I_GRAYVALUES );
+
         // gray values to range [0,1]
         imgD->reInit ( img->width(), img->height(), 1 );
 
@@ -139,14 +145,14 @@ void SemSegConvolutionalTree::train ( const MultiDataset *md )
 
         assert ( examples.size() > 0 );
 
-        for ( vector<CachedExample *>::iterator cei = imgexamples.begin();
-              cei != imgexamples.end(); cei++ )
-            convertRGBToHSV ( *cei );
-
         FeaturePool fp;
         ConvolutionFeature cf ( conf );
         cf.explode( fp );
 
+        for ( vector<CachedExample *>::iterator cei = imgexamples.begin();
+              cei != imgexamples.end(); cei++ )
+            convertRGBToHSV ( *cei, cf.isColorMode() );
+
         // start training using random forests
         fpc->train( fp, examples);
 
@@ -177,7 +183,11 @@ void SemSegConvolutionalTree::semanticseg(
     probabilities.reInit ( xsize, ysize, classNames->getMaxClassno() + 1 );
     segresult.resize ( xsize, ysize );
 
-    convertRGBToHSV(ce);
+    vector<DecisionTree *> forest = fpcrf->getForest ();
+    DecisionNode *root = forest[0]->getRoot ();
+    ConvolutionFeature* cf = dynamic_cast<ConvolutionFeature*> (root->f);
+
+    convertRGBToHSV( ce, cf->isColorMode() ); //FIXME!!!
 
     Example pce ( ce, 0, 0 );
     for ( int y = 0 ; y < ysize ; y++ )

+ 1 - 1
semseg/SemSegConvolutionalTree.h

@@ -36,7 +36,7 @@ class SemSegConvolutionalTree : public SemanticSegmentation
         /** classifier for categorization */
         FeaturePoolClassifier *fpc;
 
-        void convertRGBToHSV ( CachedExample *ce ) const;
+        void convertRGBToHSV ( CachedExample *ce, bool isColor ) const;
 
     public: