Operations3D.h 39 KB

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