Browse Source

*** empty log message ***

froehlich 14 years ago
parent
commit
abd1787576
3 changed files with 192 additions and 4 deletions
  1. 65 0
      progs/adaptmedfilter.cpp
  2. 124 0
      progs/getRelevantClasses.cpp
  3. 3 4
      progs/testSemanticSegmentation.cpp

+ 65 - 0
progs/adaptmedfilter.cpp

@@ -0,0 +1,65 @@
+/**
+* @file testSegmentation.cpp
+* @brief test segmentation algorithm
+* @author Björn Fröhlich
+* @date 01/20/2010
+
+*/
+#include <objrec/nice.h>
+
+#include <objrec/baselib/Config.h>
+#include <list>
+
+
+using namespace OBJREC;
+using namespace NICE;
+using namespace std;
+
+int main (int argc, char **argv)
+{
+	if(argc < 1)
+	{
+		cerr << "Bitte Bild angeben" << endl;
+		return -1;
+	}
+
+	string filename;
+	filename += argv[1];
+
+	//RSMeanShift rg;
+	NICE::Image img;
+
+	img.read(filename);
+	NICE::Image out(img);
+	
+	int masksize = 5;
+	int mh = masksize/2;
+	
+	int width = img.width();
+	int height = img.height();
+	
+	for(int x= 0; x < width; x++)
+	{
+	 for(int y = 0; y < height; y++)
+	 {
+	   vector<int> nh;
+	   for(int i = -mh; i <= mh; i++)
+	   {
+	    for(int j = -mh; j <= mh; j++)
+	    {
+	      int xpos = x + i;
+	      int ypos = y + j;
+	      if(xpos < 0 || ypos < 0 || xpos >= width || ypos >= height)
+		continue;
+	      nh.push_back(img.getPixel(xpos,ypos));
+	    }
+	   }
+	   sort(nh.begin(), nh.end());
+	   int val = nh[nh.size()/2];
+	   out.setPixel(x,y,val);
+	 }
+	}
+	
+	out.write("res.ppm");
+	return 0;
+}

+ 124 - 0
progs/getRelevantClasses.cpp

@@ -0,0 +1,124 @@
+// Beispielhafter Aufruf: BUILD_x86_64/progs/testSemanticSegmentation -config <CONFIGFILE>
+
+/**
+* @file testSemanticSegmentation.cpp
+* @brief test semantic segmentation routines
+* @author Erik Rodner
+* @date 03/20/2008
+*/
+
+#ifdef NICE_USELIB_OPENMP
+#include <omp.h>
+#endif
+
+#include <objrec/baselib/Config.h>
+#include <objrec/baselib/StringTools.h>
+#include <objrec/baselib/ICETools.h>
+
+#include <objrec/semanticsegmentation/SemanticSegmentation.h>
+#include <objrec/semanticsegmentation/SemSegLocal.h>
+#include <objrec/semanticsegmentation/SemSegSTF.h>
+#include <objrec/semanticsegmentation/SemSegCsurka.h>
+#include <objrec/semanticsegmentation/SemSegCsurka2.h>
+#include <objrec/semanticsegmentation/SemSegRegionBased.h>
+
+#include <fstream>
+
+using namespace OBJREC;
+
+using namespace NICE;
+
+using namespace std;
+
+/**
+ test semantic segmentation routines
+*/
+int main(int argc, char **argv)
+{
+	Config conf(argc, argv);
+
+	MultiDataset md(&conf);
+
+	const ClassNames & classNames = md.getClassNames("train");
+	
+	const LabeledSet *testFiles = md["test"];
+
+	set<int> forbidden_classes;
+
+	std::string forbidden_classes_s = conf.gS("analysis", "forbidden_classes", "");
+
+	classNames.getSelection(forbidden_classes_s, forbidden_classes);
+
+	LOOP_ALL_S(*testFiles)
+	{
+		EACH_INFO(classno, info);
+
+		std::string file = info.img();
+
+		NICE::Image lm;
+		GenericImage<double> probabilities;
+		
+		if (info.hasLocalizationInfo())
+		{
+			const LocalizationResult *l_gt = info.localization();
+
+			lm.resize(l_gt->xsize, l_gt->ysize);
+			lm.set(0);
+			l_gt->calcLabeledImage(lm, classNames.getBackgroundClass());
+		}
+
+		//semseg->semanticseg(file, lm, probabilities);
+
+		NICE::Image lm_gt;
+
+		if (info.hasLocalizationInfo())
+		{
+			const LocalizationResult *l_gt = info.localization();
+
+			lm_gt.resize(l_gt->xsize, l_gt->ysize);
+			lm_gt.set(0);
+
+			fprintf(stderr, "testSemanticSegmentation: Generating Labeled NICE::Image (Ground-Truth)\n");
+			l_gt->calcLabeledImage(lm_gt, classNames.getBackgroundClass());
+		}
+		
+		set<int> classes;
+		for(int x = 0; x < lm_gt.width(); x++)
+		{
+		  for(int y = 0; y < lm_gt.height(); y++)
+		  {
+		    classes.insert(lm_gt.getPixel(x,y));
+		  }
+		}
+		
+		
+		
+		// write allowed classes
+		string cndir = conf.gS("SemSegCsurka", "cndir", "");
+		std::vector< std::string > list;
+		StringTools::split (file, '/', list);
+		cout << cndir<< "/" << list.back() << ".dat" << endl;
+		
+		string cname = list.back();
+		
+		if(cndir != "")
+		{
+			string fname = cndir+"/"+cname+".dat";
+			cout << fname << endl;
+			ofstream outfile(fname.c_str());
+			
+			set<int>::iterator theIterator;
+			for( theIterator = classes.begin(); theIterator != classes.end(); theIterator++ ) {
+			  outfile << *theIterator << endl;
+			}     
+			
+		}
+		else
+		{
+			cerr << "please define directory for writing filenames in config: SemSegCsurka::cndir" << endl;
+			exit(-1);
+		}
+	}
+
+	return 0;
+}

+ 3 - 4
progs/testSemanticSegmentation.cpp

@@ -19,6 +19,7 @@
 #include <objrec/semanticsegmentation/SemSegLocal.h>
 #include <objrec/semanticsegmentation/SemSegSTF.h>
 #include <objrec/semanticsegmentation/SemSegCsurka.h>
+#include <objrec/semanticsegmentation/SemSegCsurka2.h>
 #include <objrec/semanticsegmentation/SemSegRegionBased.h>
 
 #include <fstream>
@@ -88,9 +89,9 @@ int main(int argc, char **argv)
 
 	//SemanticSegmentation *semseg = new SemSegLocal ( &conf, &md );
 	//SemanticSegmentation *semseg = new SemSegSTF ( &conf, &md );
-	//SemanticSegmentation *semseg = new SemSegCsurka ( &conf, &md);
+	SemanticSegmentation *semseg = new SemSegCsurka ( &conf, &md);
 
-	SemanticSegmentation *semseg = new SemSegRegionBased(&conf, &md);
+	//SemanticSegmentation *semseg = new SemSegRegionBased(&conf, &md);
 
 	const LabeledSet *testFiles = md["test"];
 	NICE::Matrix M(classNames.getMaxClassno() + 1, classNames.getMaxClassno() + 1);
@@ -109,7 +110,6 @@ int main(int argc, char **argv)
 
 	LOOP_ALL_S(*testFiles)
 	{
-		cout << 1 << endl;
 		EACH_INFO(classno, info);
 		pb.update(testFiles->count());
 
@@ -207,7 +207,6 @@ int main(int argc, char **argv)
 
 		cerr << M << endl;
 		fileno++;
-		cout << 7 << endl;
 	}
 
 	pb.hide();