Operations3D.h 34 KB

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