Browse Source

added color conversion rgb->hsv

Sven Sickert 10 năm trước cách đây
mục cha
commit
75a1568e53
2 tập tin đã thay đổi với 48 bổ sung0 xóa
  1. 46 0
      semseg/SemSegConvolutionalTree.cpp
  2. 2 0
      semseg/SemSegConvolutionalTree.h

+ 46 - 0
semseg/SemSegConvolutionalTree.cpp

@@ -13,6 +13,7 @@
 
 #include "vislearning/classifier/fpclassifier/randomforest/FPCRandomForests.h"
 #include "vislearning/features/fpfeatures/ConvolutionFeature.h"
+#include "vislearning/baselib/cc.h"
 
 using namespace OBJREC;
 
@@ -49,6 +50,45 @@ SemSegConvolutionalTree::~SemSegConvolutionalTree ()
 
 //#################### MEMBER FUNCTIONS #######################//
 
+void SemSegConvolutionalTree::convertRGBToHSV ( CachedExample *ce ) const
+{
+    assert( imgHSV->channels() == 0 );
+
+    NICE::MultiChannelImageT<int> * img = NULL;
+    NICE::MultiChannelImageT<double> * imgHSV = NULL;
+    img     = & ce->getIChannel( CachedExample::I_COLOR );
+    imgHSV  = & ce->getDChannel( CachedExample::D_EOH );
+
+    if ( img->channels() == 3 )
+    {
+        imgHSV->reInit ( img->width(), img->height(), 3 );
+
+        for ( int y = 0; y < img->height(); y++ )
+            for ( int x = 0; x < img->width(); x++ )
+            {
+                double h,s,v;
+                double r = (double)img->get( x, y, 0);
+                double g = (double)img->get( x, y, 1);
+                double b = (double)img->get( x, y, 2);
+
+                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);
+            }
+
+        // remove r,g,b (integer) channels
+        img->freeData();
+        img = NULL;
+    }
+    else
+    {
+        imgHSV = NULL;
+    }
+}
+
+
 void SemSegConvolutionalTree::initFromConfig( const Config *_conf,
                                          const string &s_confSection )
 {
@@ -85,6 +125,10 @@ 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 );
@@ -119,6 +163,8 @@ void SemSegConvolutionalTree::semanticseg(
     probabilities.reInit ( xsize, ysize, classNames->getMaxClassno() + 1 );
     segresult.resize ( xsize, ysize );
 
+    convertRGBToHSV(ce);
+
     Example pce ( ce, 0, 0 );
     for ( int y = 0 ; y < ysize ; y++ )
       for ( int x = 0 ; x < xsize ; x++ )

+ 2 - 0
semseg/SemSegConvolutionalTree.h

@@ -36,6 +36,8 @@ class SemSegConvolutionalTree : public SemanticSegmentation
         /** classifier for categorization */
         FeaturePoolClassifier *fpc;
 
+        void convertRGBToHSV ( CachedExample *ce ) const;
+
     public:
 
         /** simple constructor */