Operations.h 32 KB

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