Operations3D.h 36 KB

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