Operations.h 36 KB

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