SemSegContextTree.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. #include "SemSegContextTree.h"
  2. #include "vislearning/baselib/Globals.h"
  3. #include "vislearning/baselib/ProgressBar.h"
  4. #include "core/basics/StringTools.h"
  5. #include "vislearning/cbaselib/CachedExample.h"
  6. #include "vislearning/cbaselib/PascalResults.h"
  7. #include <omp.h>
  8. #include <iostream>
  9. #define BOUND(x,min,max) (((x)<(min))?(min):((x)>(max)?(max):(x)))
  10. using namespace OBJREC;
  11. using namespace std;
  12. using namespace NICE;
  13. class Minus:public Operation
  14. {
  15. public:
  16. virtual double getVal(const MultiChannelImageT<double> &feats, const int &x, const int &y)
  17. {
  18. int xsize = feats.width();
  19. int ysize = feats.height();
  20. double v1 = feats.get(BOUND(x+x1,0,xsize-1),BOUND(y+y1,0,ysize-1),channel1);
  21. double v2 = feats.get(BOUND(x+x2,0,xsize-1),BOUND(y+y2,0,ysize-1),channel2);
  22. return v1-v2;
  23. }
  24. virtual Operation* clone()
  25. {
  26. return new Minus();
  27. };
  28. };
  29. class MinusAbs:public Operation
  30. {
  31. public:
  32. virtual double getVal(const MultiChannelImageT<double> &feats, const int &x, const int &y)
  33. {
  34. int xsize = feats.width();
  35. int ysize = feats.height();
  36. double v1 = feats.get(BOUND(x+x1,0,xsize-1),BOUND(y+y1,0,ysize-1),channel1);
  37. double v2 = feats.get(BOUND(x+x2,0,xsize-1),BOUND(y+y2,0,ysize-1),channel2);
  38. return abs(v1-v2);
  39. }
  40. virtual Operation* clone()
  41. {
  42. return new MinusAbs();
  43. };
  44. };
  45. class Addition:public Operation
  46. {
  47. public:
  48. virtual double getVal(const MultiChannelImageT<double> &feats, const int &x, const int &y)
  49. {
  50. int xsize = feats.width();
  51. int ysize = feats.height();
  52. double v1 = feats.get(BOUND(x+x1,0,xsize-1),BOUND(y+y1,0,ysize-1),channel1);
  53. double v2 = feats.get(BOUND(x+x2,0,xsize-1),BOUND(y+y2,0,ysize-1),channel2);
  54. return v1+v2;
  55. }
  56. virtual Operation* clone()
  57. {
  58. return new Addition();
  59. };
  60. };
  61. class Only1:public Operation
  62. {
  63. public:
  64. virtual double getVal(const MultiChannelImageT<double> &feats, const int &x, const int &y)
  65. {
  66. int xsize = feats.width();
  67. int ysize = feats.height();
  68. double v1 = feats.get(BOUND(x+x1,0,xsize-1),BOUND(y+y1,0,ysize-1),channel1);
  69. return v1;
  70. }
  71. virtual Operation* clone()
  72. {
  73. return new Only1();
  74. };
  75. };
  76. SemSegContextTree::SemSegContextTree( const Config *conf, const MultiDataset *md )
  77. : SemanticSegmentation ( conf, &(md->getClassNames("train")) )
  78. {
  79. this->conf = conf;
  80. string section = "SSContextTree";
  81. lfcw = new LFColorWeijer(conf);
  82. grid = conf->gI(section, "grid", 10 );
  83. maxSamples = conf->gI(section, "max_samples", 2000);
  84. minFeats = conf->gI(section, "min_feats", 50 );
  85. maxDepth = conf->gI(section, "max_depth", 10 );
  86. windowSize = conf->gI(section, "window_size", 16);
  87. featsPerSplit = conf->gI(section, "feats_per_split", 200);
  88. useShannonEntropy = conf->gB(section, "use_shannon_entropy", true);
  89. ops.push_back(new Minus());
  90. ops.push_back(new MinusAbs());
  91. ops.push_back(new Addition());
  92. ops.push_back(new Only1());
  93. classnames = md->getClassNames ( "train" );
  94. ///////////////////////////////////
  95. // Train Segmentation Context Trees
  96. //////////////////////////////////
  97. train ( md );
  98. }
  99. SemSegContextTree::~SemSegContextTree()
  100. {
  101. }
  102. void SemSegContextTree::getBestSplit(const vector<MultiChannelImageT<double> > &feats, vector<vector<vector<int> > > &currentfeats,const vector<vector<vector<int> > > &labels, int node, Operation *&splitop, double &splitval)
  103. {
  104. int imgCount, featdim;
  105. try
  106. {
  107. imgCount = (int)feats.size();
  108. featdim = feats[0].channels();
  109. }
  110. catch(Exception)
  111. {
  112. cerr << "no features computed?" << endl;
  113. }
  114. double bestig = -numeric_limits< double >::max();
  115. splitop = NULL;
  116. splitval = -1.0;
  117. set<vector<int> >selFeats;
  118. map<int,int> e;
  119. int featcounter = 0;
  120. for(int iCounter = 0; iCounter < imgCount; iCounter++)
  121. {
  122. int xsize = (int)currentfeats[iCounter].size();
  123. int ysize = (int)currentfeats[iCounter][0].size();
  124. for(int x = 0; x < xsize; x++)
  125. {
  126. for(int y = 0; y < ysize; y++)
  127. {
  128. if(currentfeats[iCounter][x][y] == node)
  129. {
  130. featcounter++;
  131. }
  132. }
  133. }
  134. }
  135. if(featcounter < minFeats)
  136. {
  137. cout << "only " << featcounter << " feats in current node -> it's a leaf" << endl;
  138. return;
  139. }
  140. vector<double> fraction(a.size(),0.0);
  141. for(uint i = 0; i < fraction.size(); i++)
  142. {
  143. if ( forbidden_classes.find ( labelmapback[i] ) != forbidden_classes.end() )
  144. fraction[i] = 0;
  145. else
  146. fraction[i] = ((double)maxSamples)/((double)featcounter*a[i]*a.size());
  147. //cout << "fraction["<<i<<"]: "<< fraction[i] << " a[" << i << "]: " << a[i] << endl;
  148. }
  149. //cout << "a.size(): " << a.size() << endl;
  150. //getchar();
  151. featcounter = 0;
  152. for(int iCounter = 0; iCounter < imgCount; iCounter++)
  153. {
  154. int xsize = (int)currentfeats[iCounter].size();
  155. int ysize = (int)currentfeats[iCounter][0].size();
  156. for(int x = 0; x < xsize; x++)
  157. {
  158. for(int y = 0; y < ysize; y++)
  159. {
  160. if(currentfeats[iCounter][x][y] == node)
  161. {
  162. int cn = labels[iCounter][x][y];
  163. double randD = (double)rand()/(double)RAND_MAX;
  164. if(randD < fraction[labelmap[cn]])
  165. {
  166. vector<int> tmp(3,0);
  167. tmp[0] = iCounter;
  168. tmp[1] = x;
  169. tmp[2] = y;
  170. featcounter++;
  171. selFeats.insert(tmp);
  172. e[cn]++;
  173. }
  174. }
  175. }
  176. }
  177. }
  178. cout << "size: " << selFeats.size() << endl;
  179. //getchar();
  180. map<int,int>::iterator mapit;
  181. double globent = 0.0;
  182. for ( mapit=e.begin() ; mapit != e.end(); mapit++ )
  183. {
  184. //cout << "class: " << mapit->first << ": " << mapit->second << endl;
  185. double p = (double)(*mapit).second/(double)featcounter;
  186. globent += p*log2(p);
  187. }
  188. globent = -globent;
  189. if(globent < 0.5)
  190. {
  191. cout << "globent to small: " << globent << endl;
  192. return;
  193. }
  194. featsel.clear();
  195. for(int i = 0; i < featsPerSplit; i++)
  196. {
  197. int x1 = (int)((double)rand()/(double)RAND_MAX*(double)windowSize)-windowSize/2;
  198. int x2 = (int)((double)rand()/(double)RAND_MAX*(double)windowSize)-windowSize/2;
  199. int y1 = (int)((double)rand()/(double)RAND_MAX*(double)windowSize)-windowSize/2;
  200. int y2 = (int)((double)rand()/(double)RAND_MAX*(double)windowSize)-windowSize/2;
  201. int f1 = (int)((double)rand()/(double)RAND_MAX*(double)featdim);
  202. int f2 = (int)((double)rand()/(double)RAND_MAX*(double)featdim);
  203. int o = (int)((double)rand()/(double)RAND_MAX*(double)ops.size());
  204. Operation *op = ops[o]->clone();
  205. op->set(x1,y1,x2,y2,f1,f2);
  206. featsel.push_back(op);
  207. }
  208. #pragma omp parallel for private(mapit)
  209. for(int f = 0; f < featsPerSplit; f++)
  210. {
  211. double l_bestig = -numeric_limits< double >::max();
  212. double l_splitval = -1.0;
  213. set<vector<int> >::iterator it;
  214. vector<double> vals;
  215. for ( it=selFeats.begin() ; it != selFeats.end(); it++ )
  216. {
  217. vals.push_back(featsel[f]->getVal(feats[(*it)[0]],(*it)[1], (*it)[2]));
  218. }
  219. int counter = 0;
  220. for ( it=selFeats.begin() ; it != selFeats.end(); it++ , counter++)
  221. {
  222. set<vector<int> >::iterator it2;
  223. double val = vals[counter];
  224. map<int,int> eL, eR;
  225. int counterL = 0, counterR = 0;
  226. int counter2 = 0;
  227. for ( it2=selFeats.begin() ; it2 != selFeats.end(); it2++, counter2++ )
  228. {
  229. int cn = labels[(*it2)[0]][(*it2)[1]][(*it2)[2]];
  230. //cout << "vals[counter2] " << vals[counter2] << " val: " << val << endl;
  231. if(vals[counter2] < val)
  232. {
  233. //left entropie:
  234. eL[cn] = eL[cn]+1;
  235. counterL++;
  236. }
  237. else
  238. {
  239. //right entropie:
  240. eR[cn] = eR[cn]+1;
  241. counterR++;
  242. }
  243. }
  244. double leftent = 0.0;
  245. for ( mapit=eL.begin() ; mapit != eL.end(); mapit++ )
  246. {
  247. double p = (double)(*mapit).second/(double)counterL;
  248. leftent -= p*log2(p);
  249. }
  250. double rightent = 0.0;
  251. for ( mapit=eR.begin() ; mapit != eR.end(); mapit++ )
  252. {
  253. double p = (double)(*mapit).second/(double)counterR;
  254. rightent -= p*log2(p);
  255. }
  256. //cout << "rightent: " << rightent << " leftent: " << leftent << endl;
  257. double pl = (double)counterL/(double)(counterL+counterR);
  258. double ig = globent - (1.0-pl) * rightent - pl*leftent;
  259. //double ig = globent - rightent - leftent;
  260. if(useShannonEntropy)
  261. {
  262. double esplit = - ( pl*log(pl) + (1-pl)*log(1-pl) );
  263. ig = 2*ig / ( globent + esplit );
  264. }
  265. if(ig > l_bestig)
  266. {
  267. l_bestig = ig;
  268. l_splitval = val;
  269. }
  270. }
  271. #pragma omp critical
  272. {
  273. //cout << "globent: " << globent << " bestig " << bestig << " splitfeat: " << splitfeat << " splitval: " << splitval << endl;
  274. //cout << "globent: " << globent << " l_bestig " << l_bestig << " f: " << p << " l_splitval: " << l_splitval << endl;
  275. //cout << "p: " << featsubset[f] << endl;
  276. if(l_bestig > bestig)
  277. {
  278. bestig = l_bestig;
  279. splitop = featsel[f];
  280. splitval = l_splitval;
  281. }
  282. }
  283. }
  284. /*for(int i = 0; i < featsPerSplit; i++)
  285. {
  286. if(featsel[i] != splitop)
  287. delete featsel[i];
  288. }*/
  289. #ifdef debug
  290. cout << "globent: " << globent << " bestig " << bestig << " splitval: " << splitval << endl;
  291. #endif
  292. }
  293. void SemSegContextTree::train ( const MultiDataset *md )
  294. {
  295. const LabeledSet train = * ( *md ) ["train"];
  296. const LabeledSet *trainp = &train;
  297. ProgressBar pb ( "compute feats" );
  298. pb.show();
  299. //TODO: Speichefresser!, lohnt sich sparse?
  300. vector<MultiChannelImageT<double> > allfeats;
  301. vector<vector<vector<int> > > currentfeats;
  302. vector<vector<vector<int> > > labels;
  303. std::string forbidden_classes_s = conf->gS ( "analysis", "donttrain", "" );
  304. if ( forbidden_classes_s == "" )
  305. {
  306. forbidden_classes_s = conf->gS ( "analysis", "forbidden_classes", "" );
  307. }
  308. classnames.getSelection ( forbidden_classes_s, forbidden_classes );
  309. int imgcounter = 0;
  310. LOOP_ALL_S ( *trainp )
  311. {
  312. EACH_INFO ( classno,info );
  313. NICE::ColorImage img;
  314. std::string currentFile = info.img();
  315. CachedExample *ce = new CachedExample ( currentFile );
  316. const LocalizationResult *locResult = info.localization();
  317. if ( locResult->size() <= 0 )
  318. {
  319. fprintf ( stderr, "WARNING: NO ground truth polygons found for %s !\n",
  320. currentFile.c_str() );
  321. continue;
  322. }
  323. fprintf ( stderr, "SemSegCsurka: Collecting pixel examples from localization info: %s\n", currentFile.c_str() );
  324. int xsize, ysize;
  325. ce->getImageSize ( xsize, ysize );
  326. vector<vector<int> > tmp = vector<vector<int> >(xsize, vector<int>(ysize,0));
  327. currentfeats.push_back(tmp);
  328. labels.push_back(tmp);
  329. try {
  330. img = ColorImage(currentFile);
  331. } catch (Exception) {
  332. cerr << "SemSeg: error opening image file <" << currentFile << ">" << endl;
  333. continue;
  334. }
  335. Globals::setCurrentImgFN ( currentFile );
  336. //TODO: resize image?!
  337. MultiChannelImageT<double> feats;
  338. allfeats.push_back(feats);
  339. #if 0
  340. lfcw->getFeats(img, feats);
  341. #else
  342. allfeats[imgcounter].reInit(xsize, ysize, 3, true);
  343. for(int x = 0; x < xsize; x++)
  344. {
  345. for(int y = 0; y < ysize; y++)
  346. {
  347. for(int r = 0; r < 3; r++)
  348. {
  349. allfeats[imgcounter].set(x,y,img.getPixel(x,y,r),r);
  350. }
  351. }
  352. }
  353. #endif
  354. cout << 5 << endl;
  355. // getting groundtruth
  356. NICE::Image pixelLabels (xsize, ysize);
  357. pixelLabels.set(0);
  358. locResult->calcLabeledImage ( pixelLabels, ( *classNames ).getBackgroundClass() );
  359. for(int x = 0; x < xsize; x++)
  360. {
  361. for(int y = 0; y < ysize; y++)
  362. {
  363. classno = pixelLabels.getPixel(x, y);
  364. labels[imgcounter][x][y] = classno;
  365. if ( forbidden_classes.find ( classno ) != forbidden_classes.end() )
  366. continue;
  367. labelcounter[classno]++;
  368. }
  369. }
  370. imgcounter++;
  371. pb.update ( trainp->count());
  372. delete ce;
  373. }
  374. pb.hide();
  375. map<int,int>::iterator mapit;
  376. int classes = 0;
  377. for(mapit = labelcounter.begin(); mapit != labelcounter.end(); mapit++)
  378. {
  379. labelmap[mapit->first] = classes;
  380. labelmapback[classes] = mapit->first;
  381. classes++;
  382. }
  383. //balancing
  384. int featcounter = 0;
  385. a = vector<double>(classes,0.0);
  386. for(int iCounter = 0; iCounter < imgcounter; iCounter++)
  387. {
  388. int xsize = (int)currentfeats[iCounter].size();
  389. int ysize = (int)currentfeats[iCounter][0].size();
  390. for(int x = 0; x < xsize; x++)
  391. {
  392. for(int y = 0; y < ysize; y++)
  393. {
  394. featcounter++;
  395. int cn = labels[iCounter][x][y];
  396. a[labelmap[cn]] ++;
  397. }
  398. }
  399. }
  400. for(int i = 0; i < (int)a.size(); i++)
  401. {
  402. a[i] /= (double)featcounter;
  403. }
  404. #ifdef DEBUG
  405. for(int i = 0; i < (int)a.size(); i++)
  406. {
  407. cout << "a["<<i<<"]: " << a[i] << endl;
  408. }
  409. cout << "a.size: " << a.size() << endl;
  410. #endif
  411. tree.push_back(Node());
  412. tree[0].dist = vector<double>(classes,0.0);
  413. int depth = 0;
  414. tree[0].depth = depth;
  415. int startnode = 0;
  416. bool allleaf = false;
  417. while(!allleaf && depth < maxDepth)
  418. {
  419. allleaf = true;
  420. //TODO vielleicht parallel wenn nächste schleife trotzdem noch parallelsiert würde, die hat mehr gewicht
  421. int t = (int) tree.size();
  422. int s = startnode;
  423. startnode = t;
  424. //#pragma omp parallel for
  425. for(int i = s; i < t; i++)
  426. {
  427. if(!tree[i].isleaf && tree[i].left < 0)
  428. {
  429. Operation *splitfeat = NULL;
  430. double splitval;
  431. getBestSplit(allfeats, currentfeats,labels, i, splitfeat, splitval);
  432. tree[i].feat = splitfeat;
  433. tree[i].decision = splitval;
  434. if(splitfeat != NULL)
  435. {
  436. allleaf = false;
  437. int left = tree.size();
  438. tree.push_back(Node());
  439. tree.push_back(Node());
  440. int right = left+1;
  441. tree[i].left = left;
  442. tree[i].right = right;
  443. tree[left].dist = vector<double>(classes, 0.0);
  444. tree[right].dist = vector<double>(classes, 0.0);
  445. tree[left].depth = depth+1;
  446. tree[right].depth = depth+1;
  447. #pragma omp parallel for
  448. for(int iCounter = 0; iCounter < imgcounter; iCounter++)
  449. {
  450. int xsize = currentfeats[iCounter].size();
  451. int ysize = currentfeats[iCounter][0].size();
  452. for(int x = 0; x < xsize; x++)
  453. {
  454. for(int y = 0; y < ysize; y++)
  455. {
  456. if(currentfeats[iCounter][x][y] == i)
  457. {
  458. double val = splitfeat->getVal(allfeats[iCounter],x,y);
  459. if(val < splitval)
  460. {
  461. currentfeats[iCounter][x][y] = left;
  462. tree[left].dist[labelmap[labels[iCounter][x][y]]]++;
  463. }
  464. else
  465. {
  466. currentfeats[iCounter][x][y] = right;
  467. tree[right].dist[labelmap[labels[iCounter][x][y]]]++;
  468. }
  469. }
  470. }
  471. }
  472. }
  473. double lcounter = 0.0, rcounter = 0.0;
  474. for(uint d = 0; d < tree[left].dist.size(); d++)
  475. {
  476. if ( forbidden_classes.find ( labelmapback[d] ) != forbidden_classes.end() )
  477. {
  478. tree[left].dist[d] = 0;
  479. tree[right].dist[d] = 0;
  480. }
  481. else
  482. {
  483. tree[left].dist[d]/=a[d];
  484. lcounter +=tree[left].dist[d];
  485. tree[right].dist[d]/=a[d];
  486. rcounter +=tree[right].dist[d];
  487. }
  488. }
  489. if(lcounter <= 0 || rcounter <= 0)
  490. {
  491. cout << "lcounter : " << lcounter << " rcounter: " << rcounter << endl;
  492. cout << "splitval: " << splitval << endl;
  493. assert(lcounter > 0 && rcounter > 0);
  494. }
  495. for(uint d = 0; d < tree[left].dist.size(); d++)
  496. {
  497. tree[left].dist[d]/=lcounter;
  498. tree[right].dist[d]/=rcounter;
  499. }
  500. }
  501. else
  502. {
  503. tree[i].isleaf = true;
  504. }
  505. }
  506. }
  507. //TODO: features neu berechnen!
  508. depth++;
  509. #ifdef DEBUG
  510. cout << "depth: " << depth << endl;
  511. #endif
  512. }
  513. #ifdef DEBUG
  514. int t = (int) tree.size();
  515. for(int i = 0; i < t; i++)
  516. {
  517. printf("tree[%i]: left: %i, right: %i ", i, tree[i].left, tree[i].right);
  518. for(int d = 0; d < (int)tree[i].dist.size(); d++)
  519. {
  520. cout << " " << tree[i].dist[d];
  521. }
  522. cout << endl;
  523. }
  524. #endif
  525. }
  526. void SemSegContextTree::semanticseg ( CachedExample *ce, NICE::Image & segresult,NICE::MultiChannelImageT<double> & probabilities )
  527. {
  528. int xsize;
  529. int ysize;
  530. ce->getImageSize ( xsize, ysize );
  531. int numClasses = classNames->numClasses();
  532. fprintf (stderr, "ContextTree classification !\n");
  533. probabilities.reInit ( xsize, ysize, numClasses, true );
  534. probabilities.setAll ( 0 );
  535. NICE::ColorImage img;
  536. std::string currentFile = Globals::getCurrentImgFN();
  537. try {
  538. img = ColorImage(currentFile);
  539. } catch (Exception) {
  540. cerr << "SemSeg: error opening image file <" << currentFile << ">" << endl;
  541. return;
  542. }
  543. //TODO: resize image?!
  544. MultiChannelImageT<double> feats;
  545. #if 0
  546. lfcw->getFeats(img, feats);
  547. #else
  548. feats.reInit (xsize, ysize, 3, true);
  549. for(int x = 0; x < xsize; x++)
  550. {
  551. for(int y = 0; y < ysize; y++)
  552. {
  553. for(int r = 0; r < 3; r++)
  554. {
  555. feats.set(x,y,img.getPixel(x,y,r),r);
  556. }
  557. }
  558. }
  559. #endif
  560. bool allleaf = false;
  561. vector<vector<int> > currentfeats = vector<vector<int> >(xsize, vector<int>(ysize,0));
  562. int depth = 0;
  563. while(!allleaf)
  564. {
  565. allleaf = true;
  566. //TODO vielleicht parallel wenn nächste schleife auch noch parallelsiert würde, die hat mehr gewicht
  567. //#pragma omp parallel for
  568. int t = (int) tree.size();
  569. for(int i = 0; i < t; i++)
  570. {
  571. for(int x = 0; x < xsize; x++)
  572. {
  573. for(int y = 0; y < ysize; y++)
  574. {
  575. int t = currentfeats[x][y];
  576. if(tree[t].left > 0)
  577. {
  578. allleaf = false;
  579. double val = tree[t].feat->getVal(feats,x,y);
  580. if(val < tree[t].decision)
  581. {
  582. currentfeats[x][y] = tree[t].left;
  583. }
  584. else
  585. {
  586. currentfeats[x][y] = tree[t].right;
  587. }
  588. }
  589. }
  590. }
  591. }
  592. //TODO: features neu berechnen! analog zum training
  593. depth++;
  594. }
  595. //finales labeln:
  596. long int offset = 0;
  597. for(int x = 0; x < xsize; x++)
  598. {
  599. for(int y = 0; y < ysize; y++,offset++)
  600. {
  601. int t = currentfeats[x][y];
  602. double maxvalue = - numeric_limits<double>::max(); //TODO: das muss nur pro knoten gemacht werden, nicht pro pixel
  603. int maxindex = 0;
  604. for(uint i = 0; i < tree[i].dist.size(); i++)
  605. {
  606. probabilities.data[labelmapback[i]][offset] = tree[t].dist[i];
  607. if(tree[t].dist[i] > maxvalue)
  608. {
  609. maxvalue = tree[t].dist[i];
  610. maxindex = labelmapback[i];
  611. }
  612. segresult.setPixel(x,y,maxindex);
  613. }
  614. }
  615. }
  616. }