Operations3D.h 38 KB

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