Operations.h 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441
  1. /**
  2. * @file Operation.h
  3. * @brief abstract class for any kind of feature extraction from 3d images
  4. * @author Björn Fröhlich, Sven Sickert
  5. * @date 24.04.2012
  6. */
  7. #include "core/image/MultiChannelImageT.h"
  8. #include "semseg3d/image/MultiChannelImage3DT.h"
  9. #define BOUND(x,min,max) (((x)<(min))?(min):((x)>(max)?(max):(x)))
  10. namespace OBJREC {
  11. class Operation;
  12. /**
  13. * @brief methods for value access
  14. **/
  15. enum ValueTypes
  16. {
  17. RAWFEAT,
  18. CONTEXT,
  19. SPARSE,
  20. NBVALUETYPES
  21. };
  22. /**
  23. * @brief feature extraction methods
  24. **/
  25. enum OperationTypes {
  26. MINUS,
  27. MINUSABS,
  28. ADDITION,
  29. ONLY1,
  30. INTEGRAL,
  31. INTEGRALCENT,
  32. BIINTEGRALCENT,
  33. HAARHORIZ,
  34. HAARVERT,
  35. HAARSTACK,
  36. HAARDIAGXY,
  37. HAARDIAGXZ,
  38. HAARDIAGYZ,
  39. HAAR3HORIZ,
  40. HAAR3VERT,
  41. HAAR3STACK,
  42. RELATIVEXPOSITION,
  43. RELATIVEYPOSITION,
  44. RELATIVEZPOSITION,
  45. GLOBALFEATS,
  46. EQUALITY,
  47. NBOPERATIONS
  48. };
  49. /**
  50. * @brief node class for context tree
  51. **/
  52. class TreeNode
  53. {
  54. public:
  55. /** left child node */
  56. int left;
  57. /** right child node */
  58. int right;
  59. /** position of feat for decision */
  60. Operation *feat;
  61. /** decision stamp */
  62. double decision;
  63. /** is the node a leaf or not */
  64. bool isleaf;
  65. /** distribution in current node */
  66. std::vector<double> dist;
  67. /** depth of the node in the tree */
  68. int depth;
  69. /** how many pixels are in this node */
  70. int featcounter;
  71. /** unique number */
  72. int nodeNumber;
  73. /** simple constructor */
  74. TreeNode() : left ( -1 ), right ( -1 ), feat ( NULL ), decision ( -1.0 ), isleaf ( false ) {}
  75. /** standard constructor */
  76. TreeNode ( int _left, int _right, Operation *_feat, double _decision ) : left ( _left ), right ( _right ), feat ( _feat ), decision ( _decision ), isleaf ( false ) {}
  77. };
  78. /**
  79. * @brief holds all necessary information for feature extraction of 3d images
  80. **/
  81. struct Features {
  82. /** simple features like RGB values */
  83. NICE::MultiChannelImage3DT<double> *feats;
  84. /** current leaf position for each pixel and each tree */
  85. NICE::MultiChannelImage3DT<unsigned short int> *cfeats;
  86. /** amount of trees */
  87. int cTree;
  88. /** tree nodes */
  89. std::vector<TreeNode> *tree;
  90. /** probabilities for each region */
  91. std::vector<std::vector<double> > *rProbs;
  92. };
  93. /**
  94. * @brief abstract values access class
  95. **/
  96. class ValueAccess
  97. {
  98. public:
  99. /**
  100. * @brief extract value on specific position x,y and channel;
  101. *
  102. * @param feats see struct Features
  103. * @param x position of feature
  104. * @param y position of feature
  105. * @param z position of feature
  106. * @param channel position of feature
  107. * @return double value
  108. **/
  109. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z, const int &channel ) = 0;
  110. /**
  111. * @brief print some infos about feature type
  112. *
  113. * @return string feature type
  114. **/
  115. virtual std::string writeInfos() = 0;
  116. /**
  117. * @brief get feature type
  118. *
  119. * @return feature type
  120. **/
  121. virtual ValueTypes getType() = 0;
  122. };
  123. /**
  124. * @brief simple MultiChannelImageT access
  125. **/
  126. class MCImageAccess: public ValueAccess
  127. {
  128. public:
  129. /**
  130. * @brief extract value on specific position x,y,z and channel;
  131. *
  132. * @param feats see struct Features
  133. * @param x position of feature
  134. * @param y position of feature
  135. * @param z position of feature
  136. * @param channel position of feature
  137. * @return double value
  138. **/
  139. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z, const int &channel )
  140. {
  141. return feats.feats->get ( x, y, z, channel );
  142. }
  143. /**
  144. * @brief print some infos about feature type
  145. *
  146. * @return string feature type
  147. **/
  148. virtual std::string writeInfos()
  149. {
  150. return "raw";
  151. }
  152. /**
  153. * @brief get feature type
  154. *
  155. * @return feature type
  156. **/
  157. virtual ValueTypes getType()
  158. {
  159. return RAWFEAT;
  160. }
  161. };
  162. class ClassificationResultAccess: public ValueAccess
  163. {
  164. public:
  165. /**
  166. * @brief extract value on specific position x,y,z and channel;
  167. *
  168. * @param feats see struct Features
  169. * @param x position of feature
  170. * @param y position of feature
  171. * @param z position of feature
  172. * @param channel position of feature
  173. * @return double value
  174. **/
  175. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z, const int &channel )
  176. {
  177. return ( *feats.tree ) [feats.cfeats->get ( x,y,z,feats.cTree ) ].dist[channel];
  178. }
  179. /**
  180. * @brief print some infos about feature type
  181. *
  182. * @return string feature type
  183. **/
  184. virtual std::string writeInfos()
  185. {
  186. return "context";
  187. }
  188. /**
  189. * @brief get feature type
  190. *
  191. * @return feature type
  192. **/
  193. virtual ValueTypes getType()
  194. {
  195. return CONTEXT;
  196. }
  197. };
  198. #if 0
  199. /**
  200. * @brief not finished yet, do we really need sparse feature representation or ClassificationResultAccess sufficient
  201. **/
  202. class SparseImageAccess: public ValueAccess
  203. {
  204. private:
  205. double scale;
  206. public:
  207. /**
  208. * @brief extract value on specific position x,y and channel;
  209. *
  210. * @param feats see struct Features
  211. * @param x position of feature
  212. * @param y position of feature
  213. * @param channel position of feature
  214. * @return double value
  215. **/
  216. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &channel )
  217. {
  218. //MultiChannelImageT<SparseVectorInt> textonMap;
  219. //TODO: implement access
  220. return -1.0;
  221. }
  222. /**
  223. * @brief print some infos about feature type
  224. *
  225. * @return string feature type
  226. **/
  227. virtual std::string writeInfos()
  228. {
  229. return "context";
  230. }
  231. /**
  232. * @brief get feature type
  233. *
  234. * @return feature type
  235. **/
  236. virtual ValueTypes getType()
  237. {
  238. return CONTEXT;
  239. }
  240. };
  241. #endif
  242. /**
  243. * @brief abstract operation class
  244. **/
  245. class Operation
  246. {
  247. protected:
  248. /** two different points (e.g. for an rectangle or two positions), channels and size */
  249. int x1, y1, z1, x2, y2, z2, channel1, channel2, maxtypes;
  250. /** type of feature */
  251. int featType;
  252. ValueAccess *values;
  253. bool context;
  254. public:
  255. /** simple constructor */
  256. Operation();
  257. /**
  258. * @brief set all parameters
  259. * @param _x1 position 1
  260. * @param _y1 position 1
  261. * @param _z1 position 1
  262. * @param _x2 position 2
  263. * @param _y2 position 2
  264. * @param _z2 position 2
  265. * @param _channel1 channel 1
  266. * @param _channel2 channel 2
  267. * @param _values value extraction method
  268. * @return void nothing
  269. **/
  270. virtual void set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _channel1, int _channel2, ValueAccess *_values );
  271. /**
  272. * @brief set whether it is a context feature or not
  273. * @param _context context boolean
  274. * @return void nothing
  275. **/
  276. void setContext ( bool _context );
  277. /**
  278. * @brief return context information (set by setContext(bool)
  279. *
  280. * @return bool whether context is used or not
  281. **/
  282. bool getContext();
  283. /**
  284. * @brief set type of feature
  285. * @param _featType type of feature
  286. * @return void nothing
  287. **/
  288. void setFeatType ( int _featType );
  289. /**
  290. * @brief return context information (set by setContext(bool)
  291. *
  292. * @return int get feature type
  293. **/
  294. int getFeatType();
  295. /**
  296. * @brief abstract interface for feature computation
  297. * @param feats features
  298. * @param cfeats number of tree node for each pixel
  299. * @param tree current tree
  300. * @param x current x position
  301. * @param y current y position
  302. * @param z current z position
  303. * @return double distance
  304. **/
  305. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z ) = 0;
  306. /**
  307. * @brief virtual clone operation instead of copy constructor (copy constructor does not work)
  308. **/
  309. virtual Operation* clone() = 0;
  310. /**
  311. * @brief print some infos about operation extraction type
  312. * @return string feature type
  313. **/
  314. virtual std::string writeInfos();
  315. /**
  316. * @brief exctract current image boarders
  317. * @param feats image information
  318. * @param xsize width
  319. * @param ysize height
  320. * @param zsize depth
  321. * @return void
  322. **/
  323. inline void getXYZ ( const Features &feats, int &xsize, int &ysize, int &zsize );
  324. /**
  325. * @brief return operation type (for store and restor)
  326. * @return OperationTypes
  327. **/
  328. virtual OperationTypes getOps() = 0;
  329. /**
  330. * @brief store all information for current operation in stream
  331. * @param os out stream
  332. * @return void
  333. **/
  334. virtual void store ( std::ostream & os );
  335. /**
  336. * @brief restore all information for current operation from stream
  337. * @param is in stream
  338. * @return void
  339. **/
  340. virtual void restore ( std::istream & is );
  341. };
  342. /**
  343. * @brief simple equality check ?(A==B)
  344. **/
  345. class RegionFeat: public Operation
  346. {
  347. public:
  348. /**
  349. * @brief interface for feature computation
  350. * @param feats features
  351. * @param cfeats number of tree node for each pixel
  352. * @param tree current tree
  353. * @param x current x position
  354. * @param y current y position
  355. * @param z current z position
  356. * @return double distance
  357. **/
  358. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  359. /**
  360. * @brief clone operation instead of copy constructor (copy constructor does not work)
  361. **/
  362. virtual Operation* clone()
  363. {
  364. return new RegionFeat();
  365. }
  366. /**
  367. * @brief print some infos about operation extraction type
  368. * @return string feature type
  369. **/
  370. virtual std::string writeInfos()
  371. {
  372. std::string out = "RegionFeat";
  373. if ( values != NULL )
  374. out += values->writeInfos();
  375. return out + Operation::writeInfos();
  376. }
  377. /**
  378. * @brief return operation type (for store and restor)
  379. * @return OperationTypes
  380. **/
  381. virtual OperationTypes getOps()
  382. {
  383. return EQUALITY;
  384. }
  385. };
  386. /**
  387. * @brief simple difference operation A-B
  388. **/
  389. class Minus: public Operation
  390. {
  391. public:
  392. /**
  393. * @brief interface for feature computation
  394. * @param feats features
  395. * @param cfeats number of tree node for each pixel
  396. * @param tree current tree
  397. * @param x current x position
  398. * @param y current y position
  399. * @param z current z position
  400. * @return double distance
  401. **/
  402. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  403. /**
  404. * @brief clone operation instead of copy constructor (copy constructor does not work)
  405. **/
  406. virtual Operation* clone()
  407. {
  408. return new Minus();
  409. }
  410. /**
  411. * @brief print some infos about operation extraction type
  412. * @return string feature type
  413. **/
  414. virtual std::string writeInfos()
  415. {
  416. std::string out = "Minus";
  417. if ( values != NULL )
  418. out += values->writeInfos();
  419. return out + Operation::writeInfos();
  420. }
  421. /**
  422. * @brief return operation type (for store and restor)
  423. * @return OperationTypes
  424. **/
  425. virtual OperationTypes getOps()
  426. {
  427. return MINUS;
  428. }
  429. };
  430. /**
  431. * @brief simple absolute difference operation |A-B|
  432. **/
  433. class MinusAbs: public Operation
  434. {
  435. public:
  436. /**
  437. * @brief interface for feature computation
  438. * @param feats features
  439. * @param cfeats number of tree node for each pixel
  440. * @param tree current tree
  441. * @param x current x position
  442. * @param y current y position
  443. * @param z current z position
  444. * @return double distance
  445. **/
  446. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  447. /**
  448. * @brief clone operation instead of copy constructor (copy constructor does not work)
  449. **/
  450. virtual Operation* clone()
  451. {
  452. return new MinusAbs();
  453. };
  454. /**
  455. * @brief print some infos about operation extraction type
  456. * @return string feature type
  457. **/
  458. virtual std::string writeInfos()
  459. {
  460. std::string out = "MinusAbs";
  461. if ( values != NULL )
  462. out += values->writeInfos();
  463. return out;
  464. }
  465. /**
  466. * @brief return operation type (for store and restor)
  467. * @return OperationTypes
  468. **/
  469. virtual OperationTypes getOps()
  470. {
  471. return MINUSABS;
  472. }
  473. };
  474. /**
  475. * @brief simple addition operation A+B
  476. **/
  477. class Addition: public Operation
  478. {
  479. public:
  480. /**
  481. * @brief interface for feature computation
  482. * @param feats features
  483. * @param cfeats number of tree node for each pixel
  484. * @param tree current tree
  485. * @param x current x position
  486. * @param y current y position
  487. * @param z current z position
  488. * @return double distance
  489. **/
  490. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  491. /**
  492. * @brief clone operation instead of copy constructor (copy constructor does not work)
  493. **/
  494. virtual Operation* clone()
  495. {
  496. return new Addition();
  497. }
  498. /**
  499. * @brief print some infos about operation extraction type
  500. * @return string feature type
  501. **/
  502. virtual std::string writeInfos()
  503. {
  504. std::string out = "Addition";
  505. if ( values != NULL )
  506. out += values->writeInfos();
  507. return out + Operation::writeInfos();
  508. }
  509. /**
  510. * @brief return operation type (for store and restor)
  511. * @return OperationTypes
  512. **/
  513. virtual OperationTypes getOps()
  514. {
  515. return ADDITION;
  516. }
  517. };
  518. /**
  519. * @brief simple single element access operation
  520. **/
  521. class Only1: public Operation
  522. {
  523. public:
  524. /**
  525. * @brief interface for feature computation
  526. * @param feats features
  527. * @param cfeats number of tree node for each pixel
  528. * @param tree current tree
  529. * @param x current x position
  530. * @param y current y position
  531. * @param z current z position
  532. * @return double distance
  533. **/
  534. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  535. /**
  536. * @brief clone operation instead of copy constructor (copy constructor does not work)
  537. **/
  538. virtual Operation* clone()
  539. {
  540. return new Only1();
  541. }
  542. /**
  543. * @brief print some infos about operation extraction type
  544. * @return string feature type
  545. **/
  546. virtual std::string writeInfos()
  547. {
  548. std::string out = "Only1";
  549. if ( values != NULL )
  550. out += values->writeInfos();
  551. return out + Operation::writeInfos();
  552. }
  553. /**
  554. * @brief return operation type (for store and restor)
  555. * @return OperationTypes
  556. **/
  557. virtual OperationTypes getOps()
  558. {
  559. return ONLY1;
  560. }
  561. };
  562. /**
  563. * @brief get current relative x position
  564. **/
  565. class RelativeXPosition: public Operation
  566. {
  567. public:
  568. /**
  569. * @brief interface for feature computation
  570. * @param feats features
  571. * @param cfeats number of tree node for each pixel
  572. * @param tree current tree
  573. * @param x current x position
  574. * @param y current y position
  575. * @param z current z position
  576. * @return double distance
  577. **/
  578. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  579. /**
  580. * @brief clone operation instead of copy constructor (copy constructor does not work)
  581. **/
  582. virtual Operation* clone()
  583. {
  584. return new RelativeXPosition();
  585. }
  586. /**
  587. * @brief print some infos about operation extraction type
  588. * @return string feature type
  589. **/
  590. virtual std::string writeInfos()
  591. {
  592. return "RelativeXPosition" + Operation::writeInfos();
  593. }
  594. /**
  595. * @brief return operation type (for store and restor)
  596. * @return OperationTypes
  597. **/
  598. virtual OperationTypes getOps()
  599. {
  600. return RELATIVEXPOSITION;
  601. }
  602. };
  603. /**
  604. * @brief get current relative y position
  605. **/
  606. class RelativeYPosition: public Operation
  607. {
  608. public:
  609. /**
  610. * @brief interface for feature computation
  611. * @param feats features
  612. * @param cfeats number of tree node for each pixel
  613. * @param tree current tree
  614. * @param x current x position
  615. * @param y current y position
  616. * @param z current z position
  617. * @return double distance
  618. **/
  619. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  620. /**
  621. * @brief clone operation instead of copy constructor (copy constructor does not work)
  622. **/
  623. virtual Operation* clone()
  624. {
  625. return new RelativeYPosition();
  626. }
  627. /**
  628. * @brief print some infos about operation extraction type
  629. * @return string feature type
  630. **/
  631. virtual std::string writeInfos()
  632. {
  633. return "RelativeYPosition" + Operation::writeInfos();
  634. }
  635. /**
  636. * @brief return operation type (for store and restor)
  637. * @return OperationTypes
  638. **/
  639. virtual OperationTypes getOps()
  640. {
  641. return RELATIVEYPOSITION;
  642. }
  643. };
  644. /**
  645. * @brief get current relative z position
  646. **/
  647. class RelativeZPosition: public Operation
  648. {
  649. public:
  650. /**
  651. * @brief interface for feature computation
  652. * @param feats features
  653. * @param cfeats number of tree node for each pixel
  654. * @param tree current tree
  655. * @param x current x position
  656. * @param y current y position
  657. * @param z current z position
  658. * @return double distance
  659. **/
  660. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  661. /**
  662. * @brief clone operation instead of copy constructor (copy constructor does not work)
  663. **/
  664. virtual Operation* clone()
  665. {
  666. return new RelativeZPosition();
  667. }
  668. /**
  669. * @brief print some infos about operation extraction type
  670. * @return string feature type
  671. **/
  672. virtual std::string writeInfos()
  673. {
  674. return "RelativeZPosition" + Operation::writeInfos();
  675. }
  676. /**
  677. * @brief return operation type (for store and restor)
  678. * @return OperationTypes
  679. **/
  680. virtual OperationTypes getOps()
  681. {
  682. return RELATIVEZPOSITION;
  683. }
  684. };
  685. /**
  686. * @brief uses mean in a window given by (x1,y1,z1) (x2,y2,z2)
  687. **/
  688. class IntegralOps: public Operation
  689. {
  690. public:
  691. /**
  692. * @brief set all parameters
  693. * @param _x1 position 1
  694. * @param _y1 position 1
  695. * @param _z1 position 1
  696. * @param _x2 position 2
  697. * @param _y2 position 2
  698. * @param _z2 position 2
  699. * @param _channel1 channel 1
  700. * @param _channel2 channel 2
  701. * @param _values value extraction method
  702. * @return void nothing
  703. **/
  704. virtual void set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _channel1, int _channel2, ValueAccess *_values );
  705. /**
  706. * @brief interface for feature computation
  707. * @param feats features
  708. * @param cfeats number of tree node for each pixel
  709. * @param tree current tree
  710. * @param x current x position
  711. * @param y current y position
  712. * @param z current z position
  713. * @return double distance
  714. **/
  715. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  716. /**
  717. * @brief clone operation instead of copy constructor (copy constructor does not work)
  718. **/
  719. virtual Operation* clone()
  720. {
  721. return new IntegralOps();
  722. }
  723. /**
  724. * @brief print some infos about operation extraction type
  725. * @return string feature type
  726. **/
  727. virtual std::string writeInfos()
  728. {
  729. return "IntegralOps" + Operation::writeInfos();
  730. }
  731. /**
  732. * @brief return operation type (for store and restor)
  733. * @return OperationTypes
  734. **/
  735. virtual OperationTypes getOps()
  736. {
  737. return INTEGRAL;
  738. }
  739. };
  740. /**
  741. * @brief like a global bag of words to model the current appearance of classes in an image without local context
  742. **/
  743. class GlobalFeats: public IntegralOps
  744. {
  745. public:
  746. /**
  747. * @brief interface for feature computation
  748. * @param feats features
  749. * @param cfeats number of tree node for each pixel
  750. * @param tree current tree
  751. * @param x current x position
  752. * @param y current y position
  753. * @param z current z position
  754. * @return double distance
  755. **/
  756. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  757. /**
  758. * @brief clone operation instead of copy constructor (copy constructor does not work)
  759. **/
  760. virtual Operation* clone()
  761. {
  762. return new GlobalFeats();
  763. }
  764. /**
  765. * @brief print some infos about operation extraction type
  766. * @return string feature type
  767. **/
  768. virtual std::string writeInfos()
  769. {
  770. return "GlobalFeats" + Operation::writeInfos();
  771. }
  772. /**
  773. * @brief return operation type (for store and restor)
  774. * @return OperationTypes
  775. **/
  776. virtual OperationTypes getOps()
  777. {
  778. return GLOBALFEATS;
  779. }
  780. };
  781. /**
  782. * @brief uses mean of Integral image given by x1, y1, z1 with current pixel as center
  783. **/
  784. class IntegralCenteredOps: public IntegralOps
  785. {
  786. public:
  787. /**
  788. * @brief set all parameters
  789. * @param _x1 position 1
  790. * @param _y1 position 1
  791. * @param _z1 position 1
  792. * @param _x2 position 2
  793. * @param _y2 position 2
  794. * @param _z2 position 2
  795. * @param _channel1 channel 1
  796. * @param _channel2 channel 2
  797. * @param _values value extraction method
  798. * @return void nothing
  799. **/
  800. virtual void set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _channel1, int _channel2, ValueAccess *_values );
  801. /**
  802. * @brief interface for feature computation
  803. * @param feats features
  804. * @param cfeats number of tree node for each pixel
  805. * @param tree current tree
  806. * @param x current x position
  807. * @param y current y position
  808. * @param z current z position
  809. * @return double distance
  810. **/
  811. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  812. /**
  813. * @brief clone operation instead of copy constructor (copy constructor does not work)
  814. **/
  815. virtual Operation* clone()
  816. {
  817. return new IntegralCenteredOps();
  818. }
  819. /**
  820. * @brief print some infos about operation extraction type
  821. * @return string feature type
  822. **/
  823. virtual std::string writeInfos()
  824. {
  825. return "IntegralCenteredOps" + Operation::writeInfos();
  826. }
  827. /**
  828. * @brief return operation type (for store and restor)
  829. * @return OperationTypes
  830. **/
  831. virtual OperationTypes getOps()
  832. {
  833. return INTEGRALCENT;
  834. }
  835. };
  836. /**
  837. * @brief uses different of mean of Integral image given by two windows, where (x1,y1,z1) is the width, height & depth of window1 and (x2,y2,z2) of window 2
  838. **/
  839. class BiIntegralCenteredOps: public IntegralCenteredOps
  840. {
  841. public:
  842. /**
  843. * @brief set all parameters
  844. * @param _x1 position 1
  845. * @param _y1 position 1
  846. * @param _z1 position 1
  847. * @param _x2 position 2
  848. * @param _y2 position 2
  849. * @param _z2 position 2
  850. * @param _channel1 channel 1
  851. * @param _channel2 channel 2
  852. * @param _values value extraction method
  853. * @return void nothing
  854. **/
  855. virtual void set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _channel1, int _channel2, ValueAccess *_values );
  856. /**
  857. * @brief interface for feature computation
  858. * @param feats features
  859. * @param cfeats number of tree node for each pixel
  860. * @param tree current tree
  861. * @param x current x position
  862. * @param y current y position
  863. * @param z current z position
  864. * @return double distance
  865. **/
  866. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  867. /**
  868. * @brief clone operation instead of copy constructor (copy constructor does not work)
  869. **/
  870. virtual Operation* clone()
  871. {
  872. return new BiIntegralCenteredOps();
  873. }
  874. /**
  875. * @brief print some infos about operation extraction type
  876. * @return string feature type
  877. **/
  878. virtual std::string writeInfos()
  879. {
  880. return "BiIntegralCenteredOps" + Operation::writeInfos();
  881. }
  882. /**
  883. * @brief return operation type (for store and restor)
  884. * @return OperationTypes
  885. **/
  886. virtual OperationTypes getOps()
  887. {
  888. return BIINTEGRALCENT;
  889. }
  890. };
  891. /**
  892. * @brief horizontal Haar features
  893. * ++
  894. * --
  895. **/
  896. class HaarHorizontal: public IntegralCenteredOps
  897. {
  898. public:
  899. /**
  900. * @brief interface for feature computation
  901. * @param feats features
  902. * @param cfeats number of tree node for each pixel
  903. * @param tree current tree
  904. * @param x current x position
  905. * @param y current y position
  906. * @param z current z position
  907. * @return double distance
  908. **/
  909. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  910. /**
  911. * @brief clone operation instead of copy constructor (copy constructor does not work)
  912. **/
  913. virtual Operation* clone()
  914. {
  915. return new HaarHorizontal();
  916. }
  917. /**
  918. * @brief print some infos about operation extraction type
  919. * @return string feature type
  920. **/
  921. virtual std::string writeInfos()
  922. {
  923. return "HaarHorizontal" + Operation::writeInfos();
  924. }
  925. /**
  926. * @brief return operation type (for store and restor)
  927. * @return OperationTypes
  928. **/
  929. virtual OperationTypes getOps()
  930. {
  931. return HAARHORIZ;
  932. }
  933. };
  934. /**
  935. * @brief vertical Haar features
  936. * +-
  937. * +-
  938. **/
  939. class HaarVertical: public IntegralCenteredOps
  940. {
  941. public:
  942. /**
  943. * @brief interface for feature computation
  944. * @param feats features
  945. * @param cfeats number of tree node for each pixel
  946. * @param tree current tree
  947. * @param x current x position
  948. * @param y current y position
  949. * @param z current z position
  950. * @return double distance
  951. **/
  952. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  953. /**
  954. * @brief clone operation instead of copy constructor (copy constructor does not work)
  955. **/
  956. virtual Operation* clone()
  957. {
  958. return new HaarVertical();
  959. }
  960. /**
  961. * @brief print some infos about operation extraction type
  962. * @return string feature type
  963. **/
  964. virtual std::string writeInfos()
  965. {
  966. return "HaarVertical" + Operation::writeInfos();
  967. }
  968. /**
  969. * @brief return operation type (for store and restor)
  970. * @return OperationTypes
  971. **/
  972. virtual OperationTypes getOps()
  973. {
  974. return HAARVERT;
  975. }
  976. };
  977. /**
  978. * @brief stacked (depth) Haar features
  979. * +-
  980. * +-
  981. **/
  982. class HaarStacked: public IntegralCenteredOps
  983. {
  984. public:
  985. /**
  986. * @brief interface for feature computation
  987. * @param feats features
  988. * @param cfeats number of tree node for each pixel
  989. * @param tree current tree
  990. * @param x current x position
  991. * @param y current y position
  992. * @param z current z position
  993. * @return double distance
  994. **/
  995. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  996. /**
  997. * @brief clone operation instead of copy constructor (copy constructor does not work)
  998. **/
  999. virtual Operation* clone()
  1000. {
  1001. return new HaarStacked();
  1002. }
  1003. /**
  1004. * @brief print some infos about operation extraction type
  1005. * @return string feature type
  1006. **/
  1007. virtual std::string writeInfos()
  1008. {
  1009. return "HaarStacked" + Operation::writeInfos();
  1010. }
  1011. /**
  1012. * @brief return operation type (for store and restor)
  1013. * @return OperationTypes
  1014. **/
  1015. virtual OperationTypes getOps()
  1016. {
  1017. return HAARSTACK;
  1018. }
  1019. };
  1020. /**
  1021. * @brief x-y diagonal Haar features
  1022. * +-
  1023. * -+
  1024. **/
  1025. class HaarDiagXY: public IntegralCenteredOps
  1026. {
  1027. public:
  1028. /**
  1029. * @brief interface for feature computation
  1030. * @param feats features
  1031. * @param cfeats number of tree node for each pixel
  1032. * @param tree current tree
  1033. * @param x current x position
  1034. * @param y current y position
  1035. * @param z current z position
  1036. * @return double distance
  1037. **/
  1038. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  1039. /**
  1040. * @brief clone operation instead of copy constructor (copy constructor does not work)
  1041. **/
  1042. virtual Operation* clone()
  1043. {
  1044. return new HaarDiagXY();
  1045. }
  1046. /**
  1047. * @brief print some infos about operation extraction type
  1048. * @return string feature type
  1049. **/
  1050. virtual std::string writeInfos()
  1051. {
  1052. return "HaarDiagXY" + Operation::writeInfos();
  1053. }
  1054. /**
  1055. * @brief return operation type (for store and restor)
  1056. * @return OperationTypes
  1057. **/
  1058. virtual OperationTypes getOps()
  1059. {
  1060. return HAARDIAGXY;
  1061. }
  1062. };
  1063. /**
  1064. * @brief x-z diagonal Haar features
  1065. * +-
  1066. * -+
  1067. **/
  1068. class HaarDiagXZ: public IntegralCenteredOps
  1069. {
  1070. public:
  1071. /**
  1072. * @brief interface for feature computation
  1073. * @param feats features
  1074. * @param cfeats number of tree node for each pixel
  1075. * @param tree current tree
  1076. * @param x current x position
  1077. * @param y current y position
  1078. * @param z current z position
  1079. * @return double distance
  1080. **/
  1081. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  1082. /**
  1083. * @brief clone operation instead of copy constructor (copy constructor does not work)
  1084. **/
  1085. virtual Operation* clone()
  1086. {
  1087. return new HaarDiagXZ();
  1088. }
  1089. /**
  1090. * @brief print some infos about operation extraction type
  1091. * @return string feature type
  1092. **/
  1093. virtual std::string writeInfos()
  1094. {
  1095. return "HaarDiagXZ" + Operation::writeInfos();
  1096. }
  1097. /**
  1098. * @brief return operation type (for store and restor)
  1099. * @return OperationTypes
  1100. **/
  1101. virtual OperationTypes getOps()
  1102. {
  1103. return HAARDIAGXZ;
  1104. }
  1105. };
  1106. /**
  1107. * @brief y-z diagonal Haar features
  1108. * +-
  1109. * -+
  1110. **/
  1111. class HaarDiagYZ: public IntegralCenteredOps
  1112. {
  1113. public:
  1114. /**
  1115. * @brief interface for feature computation
  1116. * @param feats features
  1117. * @param cfeats number of tree node for each pixel
  1118. * @param tree current tree
  1119. * @param x current x position
  1120. * @param y current y position
  1121. * @param z current z position
  1122. * @return double distance
  1123. **/
  1124. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  1125. /**
  1126. * @brief clone operation instead of copy constructor (copy constructor does not work)
  1127. **/
  1128. virtual Operation* clone()
  1129. {
  1130. return new HaarDiagYZ();
  1131. }
  1132. /**
  1133. * @brief print some infos about operation extraction type
  1134. * @return string feature type
  1135. **/
  1136. virtual std::string writeInfos()
  1137. {
  1138. return "HaarDiagYZ" + Operation::writeInfos();
  1139. }
  1140. /**
  1141. * @brief return operation type (for store and restor)
  1142. * @return OperationTypes
  1143. **/
  1144. virtual OperationTypes getOps()
  1145. {
  1146. return HAARDIAGYZ;
  1147. }
  1148. };
  1149. /**
  1150. * @brief horizontal Haar features
  1151. * +++
  1152. * ---
  1153. * +++
  1154. */
  1155. class Haar3Horiz: public BiIntegralCenteredOps
  1156. {
  1157. public:
  1158. /**
  1159. * @brief interface for feature computation
  1160. * @param feats features
  1161. * @param cfeats number of tree node for each pixel
  1162. * @param tree current tree
  1163. * @param x current x position
  1164. * @param y current y position
  1165. * @param z current z position
  1166. * @return double distance
  1167. **/
  1168. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  1169. /**
  1170. * @brief clone operation instead of copy constructor (copy constructor does not work)
  1171. **/
  1172. virtual Operation* clone()
  1173. {
  1174. return new Haar3Horiz();
  1175. }
  1176. /**
  1177. * @brief print some infos about operation extraction type
  1178. * @return string feature type
  1179. **/
  1180. virtual std::string writeInfos()
  1181. {
  1182. return "Haar3Horiz" + Operation::writeInfos();
  1183. }
  1184. /**
  1185. * @brief return operation type (for store and restor)
  1186. * @return OperationTypes
  1187. **/
  1188. virtual OperationTypes getOps()
  1189. {
  1190. return HAAR3HORIZ;
  1191. }
  1192. };
  1193. /**
  1194. * @brief vertical Haar features
  1195. * +-+
  1196. * +-+
  1197. * +-+
  1198. */
  1199. class Haar3Vert: public BiIntegralCenteredOps
  1200. {
  1201. public:
  1202. /**
  1203. * @brief interface for feature computation
  1204. * @param feats features
  1205. * @param cfeats number of tree node for each pixel
  1206. * @param tree current tree
  1207. * @param x current x position
  1208. * @param y current y position
  1209. * @param z current z position
  1210. * @return double distance
  1211. **/
  1212. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  1213. /**
  1214. * @brief clone operation instead of copy constructor (copy constructor does not work)
  1215. **/
  1216. virtual Operation* clone()
  1217. {
  1218. return new Haar3Vert();
  1219. }
  1220. /**
  1221. * @brief print some infos about operation extraction type
  1222. * @return string feature type
  1223. **/
  1224. virtual std::string writeInfos()
  1225. {
  1226. return "Haar3Vert" + Operation::writeInfos();
  1227. }
  1228. /**
  1229. * @brief return operation type (for store and restor)
  1230. * @return OperationTypes
  1231. **/
  1232. virtual OperationTypes getOps()
  1233. {
  1234. return HAAR3VERT;
  1235. }
  1236. };
  1237. /**
  1238. * @brief stacked Haar features
  1239. * +-+
  1240. * +-+
  1241. * +-+
  1242. */
  1243. class Haar3Stack: public BiIntegralCenteredOps
  1244. {
  1245. public:
  1246. /**
  1247. * @brief interface for feature computation
  1248. * @param feats features
  1249. * @param cfeats number of tree node for each pixel
  1250. * @param tree current tree
  1251. * @param x current x position
  1252. * @param y current y position
  1253. * @param z current z position
  1254. * @return double distance
  1255. **/
  1256. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  1257. /**
  1258. * @brief clone operation instead of copy constructor (copy constructor does not work)
  1259. **/
  1260. virtual Operation* clone()
  1261. {
  1262. return new Haar3Stack();
  1263. }
  1264. /**
  1265. * @brief print some infos about operation extraction type
  1266. * @return string feature type
  1267. **/
  1268. virtual std::string writeInfos()
  1269. {
  1270. return "Haar3Stack" + Operation::writeInfos();
  1271. }
  1272. /**
  1273. * @brief return operation type (for store and restor)
  1274. * @return OperationTypes
  1275. **/
  1276. virtual OperationTypes getOps()
  1277. {
  1278. return HAAR3STACK;
  1279. }
  1280. };
  1281. } //end namespace