Operations.h 32 KB

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