Răsfoiți Sursa

code revision - some cleaning

Sven Sickert 9 ani în urmă
părinte
comite
279c6a9adb
2 a modificat fișierele cu 40 adăugiri și 87 ștergeri
  1. 3 11
      progs/testSemSegObliqueTrees.cpp
  2. 37 76
      progs/testSemanticSegmentation3D.cpp

+ 3 - 11
progs/testSemSegObliqueTrees.cpp

@@ -25,7 +25,6 @@ int main ( int argc, char **argv )
     NICE::Config conf (argc, argv );
     NICE::ResourceStatistics rs;
 
-    bool postProcessing = conf.gB( "SemSegObliqueTree", "post_process", false);
     MultiDataset md ( &conf );
     const ClassNames & classNames = md.getClassNames ( "train" );
     const LabeledSet *testFiles = md["test"];
@@ -102,13 +101,6 @@ int main ( int argc, char **argv )
             std::cout << "Time for Classification: " << timer.getLastAbsolute()
                       << "\n\n";
 
-            // post processing results
-            if (postProcessing)
-            {
-                std::cerr << "testSemSegConvTrees: WARNING: Post processing not yet supported."
-                          << std::endl;
-            }
-
             // updating confusion matrix
             SemSegTools::updateConfusionMatrix ( segresult, gtruth, M,
                 forbiddenClasses, classMapping );
@@ -120,9 +112,9 @@ int main ( int argc, char **argv )
             classNames.labelToRGB( segresult, rgb);
             classNames.labelToRGB( gtruth, rgb_gt);
             std::string fname = NICE::StringTools::baseName ( file, false );
-
-            SemSegTools::saveResultsToImageFile(
-                        &conf, "analysis", orig, rgb_gt, rgb, fname );
+            std::string outStr;
+            SemSegTools::saveResultsToImageFile( &conf, "analysis", orig,
+                        rgb_gt, rgb, fname, outStr );
         }
     }
 

+ 37 - 76
progs/testSemanticSegmentation3D.cpp

@@ -43,16 +43,13 @@ void startClassification (SemanticSegmentation *semseg,
                           const string & resultdir,
                           const bool doCrossVal)
 {
-    bool show_results = conf.gB ( "debug", "show_results", false );
     bool write_results = conf.gB ( "debug", "write_results", false );
     bool writeProbMaps = conf.gB ( "debug", "write_prob_maps", false );
     if (doCrossVal)
         write_results = false;
 
     bool run_3Dseg = conf.gB( "SSContextTree", "run_3dseg", false);
-    bool postProcessing = conf.gB( "main", "post_process", false);
     string output_type = conf.gS ( "debug", "output_type", "ppm" );
-    string output_postfix = conf.gS ( "debug", "output_postfix", "" );
 
     vector< int > zsizeVec;
     semseg->getDepthVector ( testFiles, zsizeVec, run_3Dseg );
@@ -107,92 +104,56 @@ void startClassification (SemanticSegmentation *semseg,
             // save to file
             for ( int z = 0; z < segresult.channels(); z++ )
             {
-                std::string fname = StringTools::baseName ( filelist[z], false );
+                NICE::ColorImage orig ( filelist[z] );
+                NICE::ColorImage rgb;
+                NICE::ColorImage rgb_gt;
 
-                if ( show_results || write_results )
-                {
-                    NICE::ColorImage orig ( filelist[z] );
-                    NICE::ColorImage rgb;
-                    NICE::ColorImage rgb_gt;
-                    NICE::ColorImage ov_rgb;
-                    NICE::ColorImage ov_rgb_gt;
-
-                    for ( int y = 0 ; y < orig.height(); y++ )
+                for ( int y = 0 ; y < orig.height(); y++ )
+                    for ( int x = 0 ; x < orig.width(); x++ )
                     {
-                        for ( int x = 0 ; x < orig.width(); x++ )
-                        {
-                            lm.setPixel ( x, y, segresult.get ( x, y, ( uint ) z ) );
-                            if ( run_3Dseg )
-                                lm_gt.setPixel ( x, y, gt.get ( x, y, ( uint ) z ) );
-                        }
+                        lm.setPixel ( x, y, segresult.get ( x, y, ( uint ) z ) );
+                        if ( run_3Dseg )
+                            lm_gt.setPixel ( x, y, gt.get ( x, y, ( uint ) z ) );
                     }
 
-                    // confusion matrix
-                    NICE::Matrix M ( classMapping.size(), classMapping.size() );
-                    M.set ( 0 );
-                    SemSegTools::updateConfusionMatrix ( lm, lm_gt, M, forbidden_classes,
-                                                         classMapping );
-                    M_vec.push_back ( M );
+                // confusion matrix
+                NICE::Matrix M ( classMapping.size(), classMapping.size() );
+                M.set ( 0 );
+                SemSegTools::updateConfusionMatrix (
+                            lm, lm_gt, M, forbidden_classes, classMapping );
+                M_vec.push_back ( M );
 
-                    classNames.labelToRGB ( lm, rgb );
-                    classNames.labelToRGB ( lm_gt, rgb_gt );
+                classNames.labelToRGB ( lm, rgb );
+                classNames.labelToRGB ( lm_gt, rgb_gt );
 
-                    if (postProcessing)
-                    {
-                        // median filter
-                        for (int r = 0; r < 3; r++)
-                        {
-                            NICE::Image postIm(rgb.width(), rgb.height());
-                            NICE::median(*(rgb.getChannel(r)), &postIm, 1);
-                            for (int y = 0; y < rgb.height(); y++)
-                                for (int x = 0; x < rgb.width(); x++)
-                                    rgb.setPixel(x,y,r, postIm.getPixelQuick(x,y));
-                        }
-                    }
+                if ( write_results )
+                {
+                    std::string fname = StringTools::baseName ( filelist[z], false );
+                    std::string outStr;
+                    SemSegTools::saveResultsToImageFile ( &conf, "debug",
+                                orig, rgb_gt, rgb, fname, outStr );
 
-                    if ( write_results )
+                    // write Probability maps
+                    if (writeProbMaps)
                     {
-                        SemSegTools::segmentToOverlay ( orig.getChannel(1), rgb, ov_rgb );
-                        SemSegTools::segmentToOverlay ( orig.getChannel(1), rgb_gt, ov_rgb_gt );
-
-                        std::stringstream out;
-                        if ( output_postfix.size() > 0 )
-                            out << resultdir << "/" << fname << output_postfix;
-                        else
-                            out << resultdir << "/" << fname;
-#ifdef DEBUG
-                        cout << "Writing to file " << out.str() << "_*." << output_type << endl;
-#endif
-                        orig.write ( out.str() + "_orig." + output_type );
-                        rgb.write ( out.str() + "_result." + output_type );
-                        rgb_gt.write ( out.str() + "_groundtruth." + output_type );
-                        ov_rgb.write ( out.str() + "_overlay_res." + output_type );
-                        ov_rgb_gt.write ( out.str() + "_overlay_gt." + output_type );
-
-                        // write Probability maps
-                        if (writeProbMaps)
+                        NICE::ColorImage prob_map( probabilities.width(), probabilities.height() );
+                        prob_map.set(0,0,0);
+                        int iNumChannels = probabilities.channels();
+                        for ( int idxProbMap = 0; idxProbMap < iNumChannels; idxProbMap++)
                         {
-                            NICE::ColorImage prob_map( probabilities.width(), probabilities.height() );
-                            prob_map.set(0,0,0);
-                            int iNumChannels = probabilities.channels();
-                            for ( int idxProbMap = 0; idxProbMap < iNumChannels; idxProbMap++)
+                            for ( int y = 0 ; y < probabilities.height(); y++ )
                             {
-                                for ( int y = 0 ; y < probabilities.height(); y++ )
+                                for ( int x = 0 ; x < probabilities.width(); x++ )
                                 {
-                                    for ( int x = 0 ; x < probabilities.width(); x++ )
-                                    {
-                                        double probVal = probabilities.get( x, y, z, idxProbMap ) * 255.0;
-                                        int tmp = round(probVal);
-                                        for ( int c = 0 ; c < 3 ; c++ )
-                                            prob_map.setPixel( x, y, c, tmp );
-                                    }
+                                    double probVal = probabilities.get( x, y, z, idxProbMap ) * 255.0;
+                                    for ( int c = 0 ; c < 3 ; c++ )
+                                        prob_map.setPixel( x, y, c, round(probVal) );
                                 }
-                                std::stringstream ssFileProbMap;
-                                //ssFileProbMap << out.str() << "_probs." << "c" << idxProbMap << "." << output_type;
-                                ssFileProbMap << out.str() << "_probs." << "c-" << classNames.code( idxProbMap ) << "." << output_type;
-                                //classNames
-                                prob_map.write ( ssFileProbMap.str() );
                             }
+                            std::stringstream ssFileProbMap;
+                            ssFileProbMap << outStr << "_probs." << "c-" << classNames.code( idxProbMap ) << "." << output_type;
+                            //classNames
+                            prob_map.write ( ssFileProbMap.str() );
                         }
                     }
                 }