Browse Source

LocalizationResult: calculate labeled images for more than 256 classes

Sven Sickert 10 years ago
parent
commit
8ed2e8ef71
2 changed files with 37 additions and 14 deletions
  1. 36 14
      cbaselib/LocalizationResult.cpp
  2. 1 0
      cbaselib/LocalizationResult.h

+ 36 - 14
cbaselib/LocalizationResult.cpp

@@ -586,25 +586,47 @@ void LocalizationResult::sortEmpricalDepth()
     sort ( begin(), end(), depthCompare );
 }
 
-void LocalizationResult::calcLabeledImage ( NICE::Image & mark, int backgroundClassNo ) const
+void LocalizationResult::calcLabeledImage (
+        NICE::ImageT<int> & mark,
+        int backgroundClassNo ) const
 {
     mark.set(backgroundClassNo);
 
     fprintf (stderr, "LocalizationResult: calcLabeledImage %zd\n", size() );
     for ( int y = 0 ; y < mark.height(); y++ )
-	for ( int x = 0 ; x < mark.width(); x++ )
-	{
-	    for ( LocalizationResult::const_iterator k = begin(); k != end() ; k++ )
-	    {
-			SingleLocalizationResult *slr = *k;
-			const NICE::Region & r = slr->getRegion();
-
-			if ( r.inside(x,y) ) {
-				mark.setPixel(x,y,slr->r->classno);
-				break;
-			}
-	    }
-	}
+        for ( int x = 0 ; x < mark.width(); x++ )
+            for ( LocalizationResult::const_iterator k = begin(); k != end() ; k++ )
+            {
+                SingleLocalizationResult *slr = *k;
+                const NICE::Region & r = slr->getRegion();
+
+                if ( r.inside(x,y) ) {
+                    mark.setPixel(x,y,slr->r->classno);
+                    break;
+                }
+            }
+}
+
+void LocalizationResult::calcLabeledImage (
+        NICE::Image & mark,
+        int backgroundClassNo ) const
+{
+    NICE::ImageT<int> markInt;
+    markInt.resize ( mark.width(), mark.height() );
+    calcLabeledImage( markInt, backgroundClassNo );
+
+    for ( int y = 0; y < markInt.height(); y++ )
+        for ( int x = 0; x < markInt.width(); x++ )
+        {
+            int cLabel = markInt.getPixelQuick( x, y );
+
+            if ( cLabel > std::numeric_limits<unsigned char>::max() )
+                std::cerr << "LocalizationResult::calcLabeledImage: To many classes! Labeled image with UCHAR is not sufficient!"
+                          << std::endl;
+
+            mark.setPixelQuick( x, y, (unsigned char) cLabel );
+        }
+
 }
 
 void LocalizationResult::getLabeledImageCache ( NICE::Image & mark ) const

+ 1 - 0
cbaselib/LocalizationResult.h

@@ -121,6 +121,7 @@ class LocalizationResult : public std::vector<SingleLocalizationResult *>, publi
     void sortDescendingConfidence();
     void getLabeledImageCache ( NICE::Image & mark ) const;
     void calcLabeledImage ( NICE::Image & mark, int backgroundClassNo ) const;
+    void calcLabeledImage ( NICE::ImageT<int> & mark, int backgroundClassNo ) const;
     void setMap ( const NICE::Image & labeledImage );
 
     void displayBoxes ( NICE::ColorImage & img,