Operations3D.h 37 KB

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