Operations3D.h 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657
  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. bool init;
  132. bool context;
  133. public:
  134. /** simple constructor */
  135. Operation3D();
  136. /**
  137. * @brief set all parameters
  138. * @param _x1 position 1
  139. * @param _y1 position 1
  140. * @param _z1 position 1
  141. * @param _x2 position 2
  142. * @param _y2 position 2
  143. * @param _z2 position 2
  144. * @param _channel1 channel 1
  145. * @param _channel2 channel 2
  146. * @param _ftype feature type
  147. * @return void nothing
  148. **/
  149. virtual void set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _channel1, int _channel2, int _featType );
  150. /**
  151. * @brief set whether it is a context feature or not
  152. * @param _context context boolean
  153. * @return void nothing
  154. **/
  155. void setContext ( bool _context );
  156. /**
  157. * @brief return context information (set by setContext(bool)
  158. *
  159. * @return bool whether context is used or not
  160. **/
  161. bool getContext();
  162. /**
  163. * @brief set size of feature window
  164. * @param _wsize window size
  165. * @return void nothing
  166. **/
  167. void setWSize ( int _wsize );
  168. /**
  169. * @brief return context information (set by setContext(bool)
  170. *
  171. * @return int get feature type
  172. **/
  173. int getFeatType();
  174. /**
  175. * @brief abstract interface for feature computation
  176. * @param feats features
  177. * @param x current x position
  178. * @param y current y position
  179. * @param z current z position
  180. * @return double distance
  181. **/
  182. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z ) = 0;
  183. /**
  184. * @brief virtual clone operation instead of copy constructor (copy constructor does not work)
  185. **/
  186. virtual Operation3D* clone() = 0;
  187. /**
  188. * @brief print some infos about operation extraction type
  189. * @return string feature type
  190. **/
  191. virtual std::string writeInfos();
  192. /**
  193. * @brief exctract current image boarders
  194. * @param feats image information
  195. * @param xsize width
  196. * @param ysize height
  197. * @param zsize depth
  198. * @return void
  199. **/
  200. inline void getXYZ ( const Features &feats, int &xsize, int &ysize, int &zsize );
  201. /**
  202. * @brief return operation type (for store and restore)
  203. * @return OperationTypes
  204. **/
  205. virtual OperationTypes getOps() = 0;
  206. /**
  207. * @brief store all information for current operation in stream
  208. * @param os out stream
  209. * @return void
  210. **/
  211. virtual void store ( std::ostream & os );
  212. /**
  213. * @brief restore all information for current operation from stream
  214. * @param is in stream
  215. * @return void
  216. **/
  217. virtual void restore ( std::istream & is );
  218. };
  219. /**
  220. * @brief simple equality check ?(A==B)
  221. **/
  222. class RegionFeat3D: public Operation3D
  223. {
  224. public:
  225. /**
  226. * @brief interface for feature computation
  227. * @param feats features
  228. * @param x current x position
  229. * @param y current y position
  230. * @param z current z position
  231. * @return double distance
  232. **/
  233. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  234. /**
  235. * @brief clone operation instead of copy constructor (copy constructor does not work)
  236. **/
  237. virtual Operation3D* clone()
  238. {
  239. return new RegionFeat3D();
  240. }
  241. /**
  242. * @brief print some infos about operation extraction type
  243. * @return string feature type
  244. **/
  245. virtual std::string writeInfos()
  246. {
  247. return "(-)RegionFeat " + Operation3D::writeInfos();
  248. }
  249. /**
  250. * @brief return operation type (for store and restore)
  251. * @return OperationTypes
  252. **/
  253. virtual OperationTypes getOps()
  254. {
  255. return EQUALITY;
  256. }
  257. };
  258. /**
  259. * @brief simple difference operation A-B
  260. **/
  261. class Minus3D: public Operation3D
  262. {
  263. public:
  264. /**
  265. * @brief interface for feature computation
  266. * @param feats features
  267. * @param x current x position
  268. * @param y current y position
  269. * @param z current z position
  270. * @return double distance
  271. **/
  272. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  273. /**
  274. * @brief clone operation instead of copy constructor (copy constructor does not work)
  275. **/
  276. virtual Operation3D* clone()
  277. {
  278. return new Minus3D();
  279. }
  280. /**
  281. * @brief print some infos about operation extraction type
  282. * @return string feature type
  283. **/
  284. virtual std::string writeInfos()
  285. {
  286. std::string out = "Minus";
  287. if ( context )
  288. out = "(C)" + out;
  289. else
  290. out = "(R)" + out;
  291. return out + " " +Operation3D::writeInfos();
  292. }
  293. /**
  294. * @brief return operation type (for store and restore)
  295. * @return OperationTypes
  296. **/
  297. virtual OperationTypes getOps()
  298. {
  299. if (context)
  300. return MINUS_C;
  301. else
  302. return MINUS;
  303. }
  304. };
  305. /**
  306. * @brief simple absolute difference operation |A-B|
  307. **/
  308. class MinusAbs3D: public Operation3D
  309. {
  310. public:
  311. /**
  312. * @brief interface for feature computation
  313. * @param feats features
  314. * @param x current x position
  315. * @param y current y position
  316. * @param z current z position
  317. * @return double distance
  318. **/
  319. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  320. /**
  321. * @brief clone operation instead of copy constructor (copy constructor does not work)
  322. **/
  323. virtual Operation3D* clone()
  324. {
  325. return new MinusAbs3D();
  326. }
  327. /**
  328. * @brief print some infos about operation extraction type
  329. * @return string feature type
  330. **/
  331. virtual std::string writeInfos()
  332. {
  333. std::string out = "MinusAbs";
  334. if ( context )
  335. out = "(C)" + out;
  336. else
  337. out = "(R)" + out;
  338. return out + " " + Operation3D::writeInfos();
  339. }
  340. /**
  341. * @brief return operation type (for store and restore)
  342. * @return OperationTypes
  343. **/
  344. virtual OperationTypes getOps()
  345. {
  346. if (context)
  347. return MINUSABS_C;
  348. else
  349. return MINUSABS;
  350. }
  351. };
  352. /**
  353. * @brief simple addition operation A+B
  354. **/
  355. class Addition3D: public Operation3D
  356. {
  357. public:
  358. /**
  359. * @brief interface for feature computation
  360. * @param feats features
  361. * @param x current x position
  362. * @param y current y position
  363. * @param z current z position
  364. * @return double distance
  365. **/
  366. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  367. /**
  368. * @brief clone operation instead of copy constructor (copy constructor does not work)
  369. **/
  370. virtual Operation3D* clone()
  371. {
  372. return new Addition3D();
  373. }
  374. /**
  375. * @brief print some infos about operation extraction type
  376. * @return string feature type
  377. **/
  378. virtual std::string writeInfos()
  379. {
  380. std::string out = "Addition";
  381. if ( context )
  382. out = "(C)" + out;
  383. else
  384. out = "(R)" + out;
  385. return out + " " + Operation3D::writeInfos();
  386. }
  387. /**
  388. * @brief return operation type (for store and restore)
  389. * @return OperationTypes
  390. **/
  391. virtual OperationTypes getOps()
  392. {
  393. if (context)
  394. return ADDITION_C;
  395. else
  396. return ADDITION;
  397. }
  398. };
  399. /**
  400. * @brief simple single element access operation
  401. **/
  402. class Only13D: public Operation3D
  403. {
  404. public:
  405. /**
  406. * @brief interface for feature computation
  407. * @param feats features
  408. * @param x current x position
  409. * @param y current y position
  410. * @param z current z position
  411. * @return double distance
  412. **/
  413. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  414. /**
  415. * @brief clone operation instead of copy constructor (copy constructor does not work)
  416. **/
  417. virtual Operation3D* clone()
  418. {
  419. return new Only13D();
  420. }
  421. /**
  422. * @brief print some infos about operation extraction type
  423. * @return string feature type
  424. **/
  425. virtual std::string writeInfos()
  426. {
  427. std::string out = "Only1";
  428. if ( context )
  429. out = "(C)" + out;
  430. else
  431. out = "(R)" + out;
  432. return out + " " + Operation3D::writeInfos();
  433. }
  434. /**
  435. * @brief return operation type (for store and restore)
  436. * @return OperationTypes
  437. **/
  438. virtual OperationTypes getOps()
  439. {
  440. if (context)
  441. return ONLY1_C;
  442. else
  443. return ONLY1;
  444. }
  445. };
  446. /**
  447. * @brief get current relative x position
  448. **/
  449. class RelativeXPosition3D: public Operation3D
  450. {
  451. public:
  452. /**
  453. * @brief interface for feature computation
  454. * @param feats features
  455. * @param x current x position
  456. * @param y current y position
  457. * @param z current z position
  458. * @return double distance
  459. **/
  460. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  461. /**
  462. * @brief clone operation instead of copy constructor (copy constructor does not work)
  463. **/
  464. virtual Operation3D* clone()
  465. {
  466. return new RelativeXPosition3D();
  467. }
  468. /**
  469. * @brief print some infos about operation extraction type
  470. * @return string feature type
  471. **/
  472. virtual std::string writeInfos()
  473. {
  474. std::string out = "RelXPos";
  475. if ( context )
  476. out = "(C)" + out;
  477. else
  478. out = "(R)" + out;
  479. return out + " " + Operation3D::writeInfos();
  480. }
  481. /**
  482. * @brief return operation type (for store and restore)
  483. * @return OperationTypes
  484. **/
  485. virtual OperationTypes getOps()
  486. {
  487. return RELATIVEXPOSITION;
  488. }
  489. };
  490. /**
  491. * @brief get current relative y position
  492. **/
  493. class RelativeYPosition3D: public Operation3D
  494. {
  495. public:
  496. /**
  497. * @brief interface for feature computation
  498. * @param feats features
  499. * @param x current x position
  500. * @param y current y position
  501. * @param z current z position
  502. * @return double distance
  503. **/
  504. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  505. /**
  506. * @brief clone operation instead of copy constructor (copy constructor does not work)
  507. **/
  508. virtual Operation3D* clone()
  509. {
  510. return new RelativeYPosition3D();
  511. }
  512. /**
  513. * @brief print some infos about operation extraction type
  514. * @return string feature type
  515. **/
  516. virtual std::string writeInfos()
  517. {
  518. std::string out = "RelYPos";
  519. if ( context )
  520. out = "(C)" + out;
  521. else
  522. out = "(R)" + out;
  523. return out + " " + Operation3D::writeInfos();
  524. }
  525. /**
  526. * @brief return operation type (for store and restore)
  527. * @return OperationTypes
  528. **/
  529. virtual OperationTypes getOps()
  530. {
  531. return RELATIVEYPOSITION;
  532. }
  533. };
  534. /**
  535. * @brief get current relative z position
  536. **/
  537. class RelativeZPosition3D: public Operation3D
  538. {
  539. public:
  540. /**
  541. * @brief interface for feature computation
  542. * @param feats features
  543. * @param x current x position
  544. * @param y current y position
  545. * @param z current z position
  546. * @return double distance
  547. **/
  548. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  549. /**
  550. * @brief clone operation instead of copy constructor (copy constructor does not work)
  551. **/
  552. virtual Operation3D* clone()
  553. {
  554. return new RelativeZPosition3D();
  555. }
  556. /**
  557. * @brief print some infos about operation extraction type
  558. * @return string feature type
  559. **/
  560. virtual std::string writeInfos()
  561. {
  562. std::string out = "RelZPos";
  563. if ( context )
  564. out = "(C)" + out;
  565. else
  566. out = "(R)" + out;
  567. return out + " " + Operation3D::writeInfos();
  568. }
  569. /**
  570. * @brief return operation type (for store and restore)
  571. * @return OperationTypes
  572. **/
  573. virtual OperationTypes getOps()
  574. {
  575. return RELATIVEZPOSITION;
  576. }
  577. };
  578. /**
  579. * @brief uses mean in a window given by (x1,y1,z1) (x2,y2,z2)
  580. **/
  581. class IntegralOps3D: public Operation3D
  582. {
  583. public:
  584. /**
  585. * @brief set all parameters
  586. * @param _x1 position 1
  587. * @param _y1 position 1
  588. * @param _z1 position 1
  589. * @param _x2 position 2
  590. * @param _y2 position 2
  591. * @param _z2 position 2
  592. * @param _channel1 channel 1
  593. * @param _channel2 channel 2
  594. * @param _ftype feature type
  595. * @return void nothing
  596. **/
  597. virtual void set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _channel1, int _channel2, int _ftype );
  598. /**
  599. * @brief interface for feature computation
  600. * @param feats features
  601. * @param x current x position
  602. * @param y current y position
  603. * @param z current z position
  604. * @return double distance
  605. **/
  606. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  607. /**
  608. * @brief clone operation instead of copy constructor (copy constructor does not work)
  609. **/
  610. virtual Operation3D* clone()
  611. {
  612. return new IntegralOps3D();
  613. }
  614. /**
  615. * @brief print some infos about operation extraction type
  616. * @return string feature type
  617. **/
  618. virtual std::string writeInfos()
  619. {
  620. std::string out = "IntegralOps";
  621. if ( context )
  622. out = "(C)" + out;
  623. else
  624. out = "(R)" + out;
  625. return out + " " + Operation3D::writeInfos();
  626. }
  627. /**
  628. * @brief return operation type (for store and restore)
  629. * @return OperationTypes
  630. **/
  631. virtual OperationTypes getOps()
  632. {
  633. if (context)
  634. return INTEGRAL_C;
  635. else
  636. return INTEGRAL;
  637. }
  638. };
  639. /**
  640. * @brief uses mean in a window given by (x1,y1,z1) (x2,y2,z2) and full window
  641. **/
  642. class BiIntegralOps3D: public IntegralOps3D
  643. {
  644. public:
  645. /**
  646. * @brief interface for feature computation
  647. * @param feats features
  648. * @param x current x position
  649. * @param y current y position
  650. * @param z current z position
  651. * @return double distance
  652. **/
  653. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  654. /**
  655. * @brief clone operation instead of copy constructor (copy constructor does not work)
  656. **/
  657. virtual Operation3D* clone()
  658. {
  659. return new BiIntegralOps3D();
  660. }
  661. /**
  662. * @brief print some infos about operation extraction type
  663. * @return string feature type
  664. **/
  665. virtual std::string writeInfos()
  666. {
  667. std::string out = "BiIntegralOps";
  668. if ( context )
  669. out = "(C)" + out;
  670. else
  671. out = "(R)" + out;
  672. return out + " " + Operation3D::writeInfos();
  673. }
  674. /**
  675. * @brief return operation type (for store and restore)
  676. * @return OperationTypes
  677. **/
  678. virtual OperationTypes getOps()
  679. {
  680. if (context)
  681. return BIINTEGRAL_C;
  682. else
  683. return BIINTEGRAL;
  684. }
  685. };
  686. /**
  687. * @brief like a global bag of words to model the current appearance of classes in an image without local context
  688. **/
  689. class GlobalFeats3D: public IntegralOps3D
  690. {
  691. public:
  692. /**
  693. * @brief interface for feature computation
  694. * @param feats features
  695. * @param x current x position
  696. * @param y current y position
  697. * @param z current z position
  698. * @return double distance
  699. **/
  700. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  701. /**
  702. * @brief clone operation instead of copy constructor (copy constructor does not work)
  703. **/
  704. virtual Operation3D* clone()
  705. {
  706. return new GlobalFeats3D();
  707. }
  708. /**
  709. * @brief print some infos about operation extraction type
  710. * @return string feature type
  711. **/
  712. virtual std::string writeInfos()
  713. {
  714. std::string out = "GlobalFeats";
  715. if ( context )
  716. out = "(C)" + out;
  717. else
  718. out = "(R)" + out;
  719. return out + " " + Operation3D::writeInfos();
  720. }
  721. /**
  722. * @brief return operation type (for store and restore)
  723. * @return OperationTypes
  724. **/
  725. virtual OperationTypes getOps()
  726. {
  727. if ( context )
  728. return GLOBALFEATS_C;
  729. else
  730. return GLOBALFEATS;
  731. }
  732. };
  733. /**
  734. * @brief uses mean of Integral image given by x1, y1, z1 with current pixel as center
  735. **/
  736. class IntegralCenteredOps3D: public IntegralOps3D
  737. {
  738. public:
  739. /**
  740. * @brief set all parameters
  741. * @param _x1 position 1
  742. * @param _y1 position 1
  743. * @param _z1 position 1
  744. * @param _x2 position 2
  745. * @param _y2 position 2
  746. * @param _z2 position 2
  747. * @param _channel1 channel 1
  748. * @param _channel2 channel 2
  749. * @param _ftype feature type
  750. * @return void nothing
  751. **/
  752. virtual void set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _channel1, int _channel2, int _ftype );
  753. /**
  754. * @brief interface for feature computation
  755. * @param feats features
  756. * @param x current x position
  757. * @param y current y position
  758. * @param z current z position
  759. * @return double distance
  760. **/
  761. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  762. /**
  763. * @brief clone operation instead of copy constructor (copy constructor does not work)
  764. **/
  765. virtual Operation3D* clone()
  766. {
  767. return new IntegralCenteredOps3D();
  768. }
  769. /**
  770. * @brief print some infos about operation extraction type
  771. * @return string feature type
  772. **/
  773. virtual std::string writeInfos()
  774. {
  775. std::string out = "IntegralCenteredOps";
  776. if ( context )
  777. out = "(C)" + out;
  778. else
  779. out = "(R)" + out;
  780. return out + " " + Operation3D::writeInfos();
  781. }
  782. /**
  783. * @brief return operation type (for store and restore)
  784. * @return OperationTypes
  785. **/
  786. virtual OperationTypes getOps()
  787. {
  788. if ( context )
  789. return INTEGRALCENT_C;
  790. else
  791. return INTEGRALCENT;
  792. }
  793. };
  794. /**
  795. * @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
  796. **/
  797. class BiIntegralCenteredOps3D: public IntegralCenteredOps3D
  798. {
  799. public:
  800. /**
  801. * @brief set all parameters
  802. * @param _x1 position 1
  803. * @param _y1 position 1
  804. * @param _z1 position 1
  805. * @param _x2 position 2
  806. * @param _y2 position 2
  807. * @param _z2 position 2
  808. * @param _channel1 channel 1
  809. * @param _channel2 channel 2
  810. * @param _ftype feature type
  811. * @return void nothing
  812. **/
  813. virtual void set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _channel1, int _channel2, int ftype );
  814. /**
  815. * @brief interface for feature computation
  816. * @param feats features
  817. * @param x current x position
  818. * @param y current y position
  819. * @param z current z position
  820. * @return double distance
  821. **/
  822. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  823. /**
  824. * @brief clone operation instead of copy constructor (copy constructor does not work)
  825. **/
  826. virtual Operation3D* clone()
  827. {
  828. return new BiIntegralCenteredOps3D();
  829. }
  830. /**
  831. * @brief print some infos about operation extraction type
  832. * @return string feature type
  833. **/
  834. virtual std::string writeInfos()
  835. {
  836. std::string out = "BiIntegralCenteredOps";
  837. if ( context )
  838. out = "(C)" + out;
  839. else
  840. out = "(R)" + out;
  841. return out + Operation3D::writeInfos();
  842. }
  843. /**
  844. * @brief return operation type (for store and restore)
  845. * @return OperationTypes
  846. **/
  847. virtual OperationTypes getOps()
  848. {
  849. if ( context )
  850. return BIINTEGRALCENT_C;
  851. else
  852. return BIINTEGRALCENT;
  853. }
  854. };
  855. /**
  856. * @brief horizontal Haar features
  857. * ++
  858. * --
  859. **/
  860. class HaarHorizontal3D: public IntegralCenteredOps3D
  861. {
  862. public:
  863. /**
  864. * @brief interface for feature computation
  865. * @param feats features
  866. * @param x current x position
  867. * @param y current y position
  868. * @param z current z position
  869. * @return double distance
  870. **/
  871. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  872. /**
  873. * @brief clone operation instead of copy constructor (copy constructor does not work)
  874. **/
  875. virtual Operation3D* clone()
  876. {
  877. return new HaarHorizontal3D();
  878. }
  879. /**
  880. * @brief print some infos about operation extraction type
  881. * @return string feature type
  882. **/
  883. virtual std::string writeInfos()
  884. {
  885. std::string out = "HaarHorizontal";
  886. if ( context )
  887. out = "(C)" + out;
  888. else
  889. out = "(R)" + out;
  890. return out + " " + Operation3D::writeInfos();
  891. }
  892. /**
  893. * @brief return operation type (for store and restore)
  894. * @return OperationTypes
  895. **/
  896. virtual OperationTypes getOps()
  897. {
  898. if ( context )
  899. return HAARHORIZ_C;
  900. else
  901. return HAARHORIZ;
  902. }
  903. };
  904. /**
  905. * @brief vertical Haar features
  906. * +-
  907. * +-
  908. **/
  909. class HaarVertical3D: public IntegralCenteredOps3D
  910. {
  911. public:
  912. /**
  913. * @brief interface for feature computation
  914. * @param feats features
  915. * @param x current x position
  916. * @param y current y position
  917. * @param z current z position
  918. * @return double distance
  919. **/
  920. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  921. /**
  922. * @brief clone operation instead of copy constructor (copy constructor does not work)
  923. **/
  924. virtual Operation3D* clone()
  925. {
  926. return new HaarVertical3D();
  927. }
  928. /**
  929. * @brief print some infos about operation extraction type
  930. * @return string feature type
  931. **/
  932. virtual std::string writeInfos()
  933. {
  934. std::string out = "HaarVertical";
  935. if ( context )
  936. out = "(C)" + out;
  937. else
  938. out = "(R)" + out;
  939. return out + " " + Operation3D::writeInfos();
  940. }
  941. /**
  942. * @brief return operation type (for store and restore)
  943. * @return OperationTypes
  944. **/
  945. virtual OperationTypes getOps()
  946. {
  947. if ( context )
  948. return HAARVERT_C;
  949. else
  950. return HAARVERT;
  951. }
  952. };
  953. /**
  954. * @brief stacked (depth) Haar features
  955. * +-
  956. * +-
  957. **/
  958. class HaarStacked3D: public IntegralCenteredOps3D
  959. {
  960. public:
  961. /**
  962. * @brief interface for feature computation
  963. * @param feats features
  964. * @param x current x position
  965. * @param y current y position
  966. * @param z current z position
  967. * @return double distance
  968. **/
  969. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  970. /**
  971. * @brief clone operation instead of copy constructor (copy constructor does not work)
  972. **/
  973. virtual Operation3D* clone()
  974. {
  975. return new HaarStacked3D();
  976. }
  977. /**
  978. * @brief print some infos about operation extraction type
  979. * @return string feature type
  980. **/
  981. virtual std::string writeInfos()
  982. {
  983. std::string out = "HaarStacked";
  984. if ( context )
  985. out = "(C)" + out;
  986. else
  987. out = "(R)" + out;
  988. return out + " " + Operation3D::writeInfos();
  989. }
  990. /**
  991. * @brief return operation type (for store and restore)
  992. * @return OperationTypes
  993. **/
  994. virtual OperationTypes getOps()
  995. {
  996. if ( context )
  997. return HAARSTACK_C;
  998. else
  999. return HAARSTACK;
  1000. }
  1001. };
  1002. /**
  1003. * @brief x-y diagonal Haar features
  1004. * +-
  1005. * -+
  1006. **/
  1007. class HaarDiagXY3D: public IntegralCenteredOps3D
  1008. {
  1009. public:
  1010. /**
  1011. * @brief interface for feature computation
  1012. * @param feats features
  1013. * @param x current x position
  1014. * @param y current y position
  1015. * @param z current z position
  1016. * @return double distance
  1017. **/
  1018. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  1019. /**
  1020. * @brief clone operation instead of copy constructor (copy constructor does not work)
  1021. **/
  1022. virtual Operation3D* clone()
  1023. {
  1024. return new HaarDiagXY3D();
  1025. }
  1026. /**
  1027. * @brief print some infos about operation extraction type
  1028. * @return string feature type
  1029. **/
  1030. virtual std::string writeInfos()
  1031. {
  1032. std::string out = "HaarDiagXY";
  1033. if ( context )
  1034. out = "(C)" + out;
  1035. else
  1036. out = "(R)" + out;
  1037. return out + " " + Operation3D::writeInfos();
  1038. }
  1039. /**
  1040. * @brief return operation type (for store and restore)
  1041. * @return OperationTypes
  1042. **/
  1043. virtual OperationTypes getOps()
  1044. {
  1045. if ( context )
  1046. return HAARDIAGXY_C;
  1047. else
  1048. return HAARDIAGXY;
  1049. }
  1050. };
  1051. /**
  1052. * @brief x-z diagonal Haar features
  1053. * +-
  1054. * -+
  1055. **/
  1056. class HaarDiagXZ3D: public IntegralCenteredOps3D
  1057. {
  1058. public:
  1059. /**
  1060. * @brief interface for feature computation
  1061. * @param feats features
  1062. * @param x current x position
  1063. * @param y current y position
  1064. * @param z current z position
  1065. * @return double distance
  1066. **/
  1067. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  1068. /**
  1069. * @brief clone operation instead of copy constructor (copy constructor does not work)
  1070. **/
  1071. virtual Operation3D* clone()
  1072. {
  1073. return new HaarDiagXZ3D();
  1074. }
  1075. /**
  1076. * @brief print some infos about operation extraction type
  1077. * @return string feature type
  1078. **/
  1079. virtual std::string writeInfos()
  1080. {
  1081. std::string out = "HaarDiagXZ";
  1082. if ( context )
  1083. out = "(C)" + out;
  1084. else
  1085. out = "(R)" + out;
  1086. return out + " " + Operation3D::writeInfos();
  1087. }
  1088. /**
  1089. * @brief return operation type (for store and restore)
  1090. * @return OperationTypes
  1091. **/
  1092. virtual OperationTypes getOps()
  1093. {
  1094. if ( context )
  1095. return HAARDIAGXZ_C;
  1096. else
  1097. return HAARDIAGXZ;
  1098. }
  1099. };
  1100. /**
  1101. * @brief y-z diagonal Haar features
  1102. * +-
  1103. * -+
  1104. **/
  1105. class HaarDiagYZ3D: public IntegralCenteredOps3D
  1106. {
  1107. public:
  1108. /**
  1109. * @brief interface for feature computation
  1110. * @param feats features
  1111. * @param x current x position
  1112. * @param y current y position
  1113. * @param z current z position
  1114. * @return double distance
  1115. **/
  1116. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  1117. /**
  1118. * @brief clone operation instead of copy constructor (copy constructor does not work)
  1119. **/
  1120. virtual Operation3D* clone()
  1121. {
  1122. return new HaarDiagYZ3D();
  1123. }
  1124. /**
  1125. * @brief print some infos about operation extraction type
  1126. * @return string feature type
  1127. **/
  1128. virtual std::string writeInfos()
  1129. {
  1130. std::string out = "HaarDiagYZ";
  1131. if ( context )
  1132. out = "(C)" + out;
  1133. else
  1134. out = "(R)" + out;
  1135. return out + " " + Operation3D::writeInfos();
  1136. }
  1137. /**
  1138. * @brief return operation type (for store and restore)
  1139. * @return OperationTypes
  1140. **/
  1141. virtual OperationTypes getOps()
  1142. {
  1143. if ( context )
  1144. return HAARDIAGYZ_C;
  1145. else
  1146. return HAARDIAGYZ;
  1147. }
  1148. };
  1149. /**
  1150. * @brief horizontal Haar features
  1151. * +++
  1152. * ---
  1153. * +++
  1154. */
  1155. class Haar3Horiz3D: public BiIntegralCenteredOps3D
  1156. {
  1157. public:
  1158. /**
  1159. * @brief interface for feature computation
  1160. * @param feats features
  1161. * @param x current x position
  1162. * @param y current y position
  1163. * @param z current z position
  1164. * @return double distance
  1165. **/
  1166. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  1167. /**
  1168. * @brief clone operation instead of copy constructor (copy constructor does not work)
  1169. **/
  1170. virtual Operation3D* clone()
  1171. {
  1172. return new Haar3Horiz3D();
  1173. }
  1174. /**
  1175. * @brief print some infos about operation extraction type
  1176. * @return string feature type
  1177. **/
  1178. virtual std::string writeInfos()
  1179. {
  1180. std::string out = "Haar3Horiz";
  1181. if ( context )
  1182. out = "(C)" + out;
  1183. else
  1184. out = "(R)" + out;
  1185. return out + " " + Operation3D::writeInfos();
  1186. }
  1187. /**
  1188. * @brief return operation type (for store and restore)
  1189. * @return OperationTypes
  1190. **/
  1191. virtual OperationTypes getOps()
  1192. {
  1193. if ( context )
  1194. return HAAR3HORIZ_C;
  1195. else
  1196. return HAAR3HORIZ;
  1197. }
  1198. };
  1199. /**
  1200. * @brief vertical Haar features
  1201. * +-+
  1202. * +-+
  1203. * +-+
  1204. */
  1205. class Haar3Vert3D: public BiIntegralCenteredOps3D
  1206. {
  1207. public:
  1208. /**
  1209. * @brief interface for feature computation
  1210. * @param feats features
  1211. * @param x current x position
  1212. * @param y current y position
  1213. * @param z current z position
  1214. * @return double distance
  1215. **/
  1216. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  1217. /**
  1218. * @brief clone operation instead of copy constructor (copy constructor does not work)
  1219. **/
  1220. virtual Operation3D* clone()
  1221. {
  1222. return new Haar3Vert3D();
  1223. }
  1224. /**
  1225. * @brief print some infos about operation extraction type
  1226. * @return string feature type
  1227. **/
  1228. virtual std::string writeInfos()
  1229. {
  1230. std::string out = "Haar3Vert";
  1231. if ( context )
  1232. out = "(C)" + out;
  1233. else
  1234. out = "(R)" + out;
  1235. return out + " " + Operation3D::writeInfos();
  1236. }
  1237. /**
  1238. * @brief return operation type (for store and restore)
  1239. * @return OperationTypes
  1240. **/
  1241. virtual OperationTypes getOps()
  1242. {
  1243. if ( context )
  1244. return HAAR3VERT_C;
  1245. else
  1246. return HAAR3VERT;
  1247. }
  1248. };
  1249. /**
  1250. * @brief stacked Haar features
  1251. * +-+
  1252. * +-+
  1253. * +-+
  1254. */
  1255. class Haar3Stack3D: public BiIntegralCenteredOps3D
  1256. {
  1257. public:
  1258. /**
  1259. * @brief interface for feature computation
  1260. * @param feats features
  1261. * @param x current x position
  1262. * @param y current y position
  1263. * @param z current z position
  1264. * @return double distance
  1265. **/
  1266. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  1267. /**
  1268. * @brief clone operation instead of copy constructor (copy constructor does not work)
  1269. **/
  1270. virtual Operation3D* clone()
  1271. {
  1272. return new Haar3Stack3D();
  1273. }
  1274. /**
  1275. * @brief print some infos about operation extraction type
  1276. * @return string feature type
  1277. **/
  1278. virtual std::string writeInfos()
  1279. {
  1280. std::string out = "Haar3Stack";
  1281. if ( context )
  1282. out = "(C)" + out;
  1283. else
  1284. out = "(R)" + out;
  1285. return out + " " + Operation3D::writeInfos();
  1286. }
  1287. /**
  1288. * @brief return operation type (for store and restore)
  1289. * @return OperationTypes
  1290. **/
  1291. virtual OperationTypes getOps()
  1292. {
  1293. if ( context )
  1294. return HAAR3STACK_C;
  1295. else
  1296. return HAAR3STACK;
  1297. }
  1298. };
  1299. /**
  1300. * @brief Ray features
  1301. */
  1302. /**
  1303. * @brief Ray Distance-Difference features
  1304. */
  1305. class RayDiff3D: public Operation3D
  1306. {
  1307. public:
  1308. /**
  1309. * @brief interface for feature computation
  1310. * @param feats features
  1311. * @param x current x position
  1312. * @param y current y position
  1313. * @param z current z position
  1314. * @return double distance
  1315. **/
  1316. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  1317. /**
  1318. * @brief clone operation instead of copy constructor (copy constructor does not work)
  1319. **/
  1320. virtual Operation3D* clone()
  1321. {
  1322. return new RayDiff3D();
  1323. }
  1324. /**
  1325. * @brief print some infos about operation extraction type
  1326. * @return string feature type
  1327. **/
  1328. virtual std::string writeInfos()
  1329. {
  1330. return "(-)RayDiff " + Operation3D::writeInfos();
  1331. }
  1332. /**
  1333. * @brief return operation type (for store and restore)
  1334. * @return OperationTypes
  1335. **/
  1336. virtual OperationTypes getOps()
  1337. {
  1338. return RAYDIFF;
  1339. }
  1340. };
  1341. /**
  1342. * @brief Ray Distance features
  1343. */
  1344. class RayDist3D: public Operation3D
  1345. {
  1346. public:
  1347. /**
  1348. * @brief interface for feature computation
  1349. * @param feats features
  1350. * @param x current x position
  1351. * @param y current y position
  1352. * @param z current z position
  1353. * @return double distance
  1354. **/
  1355. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  1356. /**
  1357. * @brief clone operation instead of copy constructor (copy constructor does not work)
  1358. **/
  1359. virtual Operation3D* clone()
  1360. {
  1361. return new RayDist3D();
  1362. }
  1363. /**
  1364. * @brief print some infos about operation extraction type
  1365. * @return string feature type
  1366. **/
  1367. virtual std::string writeInfos()
  1368. {
  1369. return "(-)RayDist " + Operation3D::writeInfos();
  1370. }
  1371. /**
  1372. * @brief return operation type (for store and restore)
  1373. * @return OperationTypes
  1374. **/
  1375. virtual OperationTypes getOps()
  1376. {
  1377. return RAYDIST;
  1378. }
  1379. };
  1380. /**
  1381. * @brief Ray Orientation features
  1382. */
  1383. class RayOrient3D: public Operation3D
  1384. {
  1385. public:
  1386. /**
  1387. * @brief interface for feature computation
  1388. * @param feats features
  1389. * @param x current x position
  1390. * @param y current y position
  1391. * @param z current z position
  1392. * @return double distance
  1393. **/
  1394. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  1395. /**
  1396. * @brief clone operation instead of copy constructor (copy constructor does not work)
  1397. **/
  1398. virtual Operation3D* clone()
  1399. {
  1400. return new RayOrient3D();
  1401. }
  1402. /**
  1403. * @brief print some infos about operation extraction type
  1404. * @return string feature type
  1405. **/
  1406. virtual std::string writeInfos()
  1407. {
  1408. return "(-)RayOrient " + Operation3D::writeInfos();
  1409. }
  1410. /**
  1411. * @brief return operation type (for store and restore)
  1412. * @return OperationTypes
  1413. **/
  1414. virtual OperationTypes getOps()
  1415. {
  1416. return RAYORIENT;
  1417. }
  1418. };
  1419. /**
  1420. * @brief Ray Norm features
  1421. */
  1422. class RayNorm3D: public Operation3D
  1423. {
  1424. public:
  1425. /**
  1426. * @brief interface for feature computation
  1427. * @param feats features
  1428. * @param x current x position
  1429. * @param y current y position
  1430. * @param z current z position
  1431. * @return double distance
  1432. **/
  1433. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  1434. /**
  1435. * @brief clone operation instead of copy constructor (copy constructor does not work)
  1436. **/
  1437. virtual Operation3D* clone()
  1438. {
  1439. return new RayNorm3D();
  1440. }
  1441. /**
  1442. * @brief print some infos about operation extraction type
  1443. * @return string feature type
  1444. **/
  1445. virtual std::string writeInfos()
  1446. {
  1447. return "(-)RayNorm " + Operation3D::writeInfos();
  1448. }
  1449. /**
  1450. * @brief return operation type (for store and restore)
  1451. * @return OperationTypes
  1452. **/
  1453. virtual OperationTypes getOps()
  1454. {
  1455. return RAYNORM;
  1456. }
  1457. };
  1458. } //end namespace