No Description

arrays-GreenScreen.html 73KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574
  1. <!DOCTYPE html><html><head><meta charset="utf-8"><style>body {
  2. width: 45em;
  3. border: 1px solid #ddd;
  4. outline: 1300px solid #fff;
  5. margin: 16px auto;
  6. }
  7. body .markdown-body
  8. {
  9. padding: 30px;
  10. }
  11. @font-face {
  12. font-family: octicons-anchor;
  13. src: url(data:font/woff;charset=utf-8;base64,d09GRgABAAAAAAYcAA0AAAAACjQAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABGRlRNAAABMAAAABwAAAAca8vGTk9TLzIAAAFMAAAARAAAAFZG1VHVY21hcAAAAZAAAAA+AAABQgAP9AdjdnQgAAAB0AAAAAQAAAAEACICiGdhc3AAAAHUAAAACAAAAAj//wADZ2x5ZgAAAdwAAADRAAABEKyikaNoZWFkAAACsAAAAC0AAAA2AtXoA2hoZWEAAALgAAAAHAAAACQHngNFaG10eAAAAvwAAAAQAAAAEAwAACJsb2NhAAADDAAAAAoAAAAKALIAVG1heHAAAAMYAAAAHwAAACABEAB2bmFtZQAAAzgAAALBAAAFu3I9x/Nwb3N0AAAF/AAAAB0AAAAvaoFvbwAAAAEAAAAAzBdyYwAAAADP2IQvAAAAAM/bz7t4nGNgZGFgnMDAysDB1Ml0hoGBoR9CM75mMGLkYGBgYmBlZsAKAtJcUxgcPsR8iGF2+O/AEMPsznAYKMwIkgMA5REMOXicY2BgYGaAYBkGRgYQsAHyGMF8FgYFIM0ChED+h5j//yEk/3KoSgZGNgYYk4GRCUgwMaACRoZhDwCs7QgGAAAAIgKIAAAAAf//AAJ4nHWMMQrCQBBF/0zWrCCIKUQsTDCL2EXMohYGSSmorScInsRGL2DOYJe0Ntp7BK+gJ1BxF1stZvjz/v8DRghQzEc4kIgKwiAppcA9LtzKLSkdNhKFY3HF4lK69ExKslx7Xa+vPRVS43G98vG1DnkDMIBUgFN0MDXflU8tbaZOUkXUH0+U27RoRpOIyCKjbMCVejwypzJJG4jIwb43rfl6wbwanocrJm9XFYfskuVC5K/TPyczNU7b84CXcbxks1Un6H6tLH9vf2LRnn8Ax7A5WQAAAHicY2BkYGAA4teL1+yI57f5ysDNwgAC529f0kOmWRiYVgEpDgYmEA8AUzEKsQAAAHicY2BkYGB2+O/AEMPCAAJAkpEBFbAAADgKAe0EAAAiAAAAAAQAAAAEAAAAAAAAKgAqACoAiAAAeJxjYGRgYGBhsGFgYgABEMkFhAwM/xn0QAIAD6YBhwB4nI1Ty07cMBS9QwKlQapQW3VXySvEqDCZGbGaHULiIQ1FKgjWMxknMfLEke2A+IJu+wntrt/QbVf9gG75jK577Lg8K1qQPCfnnnt8fX1NRC/pmjrk/zprC+8D7tBy9DHgBXoWfQ44Av8t4Bj4Z8CLtBL9CniJluPXASf0Lm4CXqFX8Q84dOLnMB17N4c7tBo1AS/Qi+hTwBH4rwHHwN8DXqQ30XXAS7QaLwSc0Gn8NuAVWou/gFmnjLrEaEh9GmDdDGgL3B4JsrRPDU2hTOiMSuJUIdKQQayiAth69r6akSSFqIJuA19TrzCIaY8sIoxyrNIrL//pw7A2iMygkX5vDj+G+kuoLdX4GlGK/8Lnlz6/h9MpmoO9rafrz7ILXEHHaAx95s9lsI7AHNMBWEZHULnfAXwG9/ZqdzLI08iuwRloXE8kfhXYAvE23+23DU3t626rbs8/8adv+9DWknsHp3E17oCf+Z48rvEQNZ78paYM38qfk3v/u3l3u3GXN2Dmvmvpf1Srwk3pB/VSsp512bA/GG5i2WJ7wu430yQ5K3nFGiOqgtmSB5pJVSizwaacmUZzZhXLlZTq8qGGFY2YcSkqbth6aW1tRmlaCFs2016m5qn36SbJrqosG4uMV4aP2PHBmB3tjtmgN2izkGQyLWprekbIntJFing32a5rKWCN/SdSoga45EJykyQ7asZvHQ8PTm6cslIpwyeyjbVltNikc2HTR7YKh9LBl9DADC0U/jLcBZDKrMhUBfQBvXRzLtFtjU9eNHKin0x5InTqb8lNpfKv1s1xHzTXRqgKzek/mb7nB8RZTCDhGEX3kK/8Q75AmUM/eLkfA+0Hi908Kx4eNsMgudg5GLdRD7a84npi+YxNr5i5KIbW5izXas7cHXIMAau1OueZhfj+cOcP3P8MNIWLyYOBuxL6DRylJ4cAAAB4nGNgYoAALjDJyIAOWMCiTIxMLDmZedkABtIBygAAAA==) format('woff');
  14. }
  15. .markdown-body {
  16. -ms-text-size-adjust: 100%;
  17. -webkit-text-size-adjust: 100%;
  18. color: #333;
  19. overflow: hidden;
  20. font-family: "Helvetica Neue", Helvetica, "Segoe UI", Arial, freesans, sans-serif;
  21. font-size: 16px;
  22. line-height: 1.6;
  23. word-wrap: break-word;
  24. }
  25. .markdown-body a {
  26. background: transparent;
  27. }
  28. .markdown-body a:active,
  29. .markdown-body a:hover {
  30. outline: 0;
  31. }
  32. .markdown-body strong {
  33. font-weight: bold;
  34. }
  35. .markdown-body h1 {
  36. font-size: 2em;
  37. margin: 0.67em 0;
  38. }
  39. .markdown-body img {
  40. border: 0;
  41. }
  42. .markdown-body hr {
  43. -moz-box-sizing: content-box;
  44. box-sizing: content-box;
  45. height: 0;
  46. }
  47. .markdown-body pre {
  48. overflow: auto;
  49. }
  50. .markdown-body code,
  51. .markdown-body kbd,
  52. .markdown-body pre {
  53. font-family: monospace, monospace;
  54. font-size: 1em;
  55. }
  56. .markdown-body input {
  57. color: inherit;
  58. font: inherit;
  59. margin: 0;
  60. }
  61. .markdown-body html input[disabled] {
  62. cursor: default;
  63. }
  64. .markdown-body input {
  65. line-height: normal;
  66. }
  67. .markdown-body input[type="checkbox"] {
  68. -moz-box-sizing: border-box;
  69. box-sizing: border-box;
  70. padding: 0;
  71. }
  72. .markdown-body table {
  73. border-collapse: collapse;
  74. border-spacing: 0;
  75. }
  76. .markdown-body td,
  77. .markdown-body th {
  78. padding: 0;
  79. }
  80. .markdown-body * {
  81. -moz-box-sizing: border-box;
  82. box-sizing: border-box;
  83. }
  84. .markdown-body input {
  85. font: 13px/1.4 Helvetica, arial, freesans, clean, sans-serif, "Segoe UI Emoji", "Segoe UI Symbol";
  86. }
  87. .markdown-body a {
  88. color: #4183c4;
  89. text-decoration: none;
  90. }
  91. .markdown-body a:hover,
  92. .markdown-body a:focus,
  93. .markdown-body a:active {
  94. text-decoration: underline;
  95. }
  96. .markdown-body hr {
  97. height: 0;
  98. margin: 15px 0;
  99. overflow: hidden;
  100. background: transparent;
  101. border: 0;
  102. border-bottom: 1px solid #ddd;
  103. }
  104. .markdown-body hr:before {
  105. display: table;
  106. content: "";
  107. }
  108. .markdown-body hr:after {
  109. display: table;
  110. clear: both;
  111. content: "";
  112. }
  113. .markdown-body h1,
  114. .markdown-body h2,
  115. .markdown-body h3,
  116. .markdown-body h4,
  117. .markdown-body h5,
  118. .markdown-body h6 {
  119. margin-top: 15px;
  120. margin-bottom: 15px;
  121. line-height: 1.1;
  122. }
  123. .markdown-body h1 {
  124. font-size: 30px;
  125. }
  126. .markdown-body h2 {
  127. font-size: 21px;
  128. }
  129. .markdown-body h3 {
  130. font-size: 16px;
  131. }
  132. .markdown-body h4 {
  133. font-size: 14px;
  134. }
  135. .markdown-body h5 {
  136. font-size: 12px;
  137. }
  138. .markdown-body h6 {
  139. font-size: 11px;
  140. }
  141. .markdown-body blockquote {
  142. margin: 0;
  143. }
  144. .markdown-body ul,
  145. .markdown-body ol {
  146. padding: 0;
  147. margin-top: 0;
  148. margin-bottom: 0;
  149. }
  150. .markdown-body ol ol,
  151. .markdown-body ul ol {
  152. list-style-type: lower-roman;
  153. }
  154. .markdown-body ul ul ol,
  155. .markdown-body ul ol ol,
  156. .markdown-body ol ul ol,
  157. .markdown-body ol ol ol {
  158. list-style-type: lower-alpha;
  159. }
  160. .markdown-body dd {
  161. margin-left: 0;
  162. }
  163. .markdown-body code {
  164. font: 12px Consolas, "Liberation Mono", Menlo, Courier, monospace;
  165. }
  166. .markdown-body pre {
  167. margin-top: 0;
  168. margin-bottom: 0;
  169. font: 12px Consolas, "Liberation Mono", Menlo, Courier, monospace;
  170. }
  171. .markdown-body .octicon {
  172. font: normal normal 16px octicons-anchor;
  173. line-height: 1;
  174. display: inline-block;
  175. text-decoration: none;
  176. -webkit-font-smoothing: antialiased;
  177. -moz-osx-font-smoothing: grayscale;
  178. -webkit-user-select: none;
  179. -moz-user-select: none;
  180. -ms-user-select: none;
  181. user-select: none;
  182. }
  183. .markdown-body .octicon-link:before {
  184. content: '\f05c';
  185. }
  186. .markdown-body>*:first-child {
  187. margin-top: 0 !important;
  188. }
  189. .markdown-body>*:last-child {
  190. margin-bottom: 0 !important;
  191. }
  192. .markdown-body .anchor {
  193. position: absolute;
  194. top: 0;
  195. bottom: 0;
  196. left: 0;
  197. display: block;
  198. padding-right: 6px;
  199. padding-left: 30px;
  200. margin-left: -30px;
  201. }
  202. .markdown-body .anchor:focus {
  203. outline: none;
  204. }
  205. .markdown-body h1,
  206. .markdown-body h2,
  207. .markdown-body h3,
  208. .markdown-body h4,
  209. .markdown-body h5,
  210. .markdown-body h6 {
  211. position: relative;
  212. margin-top: 1em;
  213. margin-bottom: 16px;
  214. font-weight: bold;
  215. line-height: 1.4;
  216. }
  217. .markdown-body h1 .octicon-link,
  218. .markdown-body h2 .octicon-link,
  219. .markdown-body h3 .octicon-link,
  220. .markdown-body h4 .octicon-link,
  221. .markdown-body h5 .octicon-link,
  222. .markdown-body h6 .octicon-link {
  223. display: none;
  224. color: #000;
  225. vertical-align: middle;
  226. }
  227. .markdown-body h1:hover .anchor,
  228. .markdown-body h2:hover .anchor,
  229. .markdown-body h3:hover .anchor,
  230. .markdown-body h4:hover .anchor,
  231. .markdown-body h5:hover .anchor,
  232. .markdown-body h6:hover .anchor {
  233. padding-left: 8px;
  234. margin-left: -30px;
  235. line-height: 1;
  236. text-decoration: none;
  237. }
  238. .markdown-body h1:hover .anchor .octicon-link,
  239. .markdown-body h2:hover .anchor .octicon-link,
  240. .markdown-body h3:hover .anchor .octicon-link,
  241. .markdown-body h4:hover .anchor .octicon-link,
  242. .markdown-body h5:hover .anchor .octicon-link,
  243. .markdown-body h6:hover .anchor .octicon-link {
  244. display: inline-block;
  245. }
  246. .markdown-body h1 {
  247. padding-bottom: 0.3em;
  248. font-size: 2.25em;
  249. line-height: 1.2;
  250. border-bottom: 1px solid #eee;
  251. }
  252. .markdown-body h2 {
  253. padding-bottom: 0.3em;
  254. font-size: 1.75em;
  255. line-height: 1.225;
  256. border-bottom: 1px solid #eee;
  257. }
  258. .markdown-body h3 {
  259. font-size: 1.5em;
  260. line-height: 1.43;
  261. }
  262. .markdown-body h4 {
  263. font-size: 1.25em;
  264. }
  265. .markdown-body h5 {
  266. font-size: 1em;
  267. }
  268. .markdown-body h6 {
  269. font-size: 1em;
  270. color: #777;
  271. }
  272. .markdown-body p,
  273. .markdown-body blockquote,
  274. .markdown-body ul,
  275. .markdown-body ol,
  276. .markdown-body dl,
  277. .markdown-body table,
  278. .markdown-body pre {
  279. margin-top: 0;
  280. margin-bottom: 16px;
  281. }
  282. .markdown-body hr {
  283. height: 4px;
  284. padding: 0;
  285. margin: 16px 0;
  286. background-color: #e7e7e7;
  287. border: 0 none;
  288. }
  289. .markdown-body ul,
  290. .markdown-body ol {
  291. padding-left: 2em;
  292. }
  293. .markdown-body ul ul,
  294. .markdown-body ul ol,
  295. .markdown-body ol ol,
  296. .markdown-body ol ul {
  297. margin-top: 0;
  298. margin-bottom: 0;
  299. }
  300. .markdown-body li>p {
  301. margin-top: 16px;
  302. }
  303. .markdown-body dl {
  304. padding: 0;
  305. }
  306. .markdown-body dl dt {
  307. padding: 0;
  308. margin-top: 16px;
  309. font-size: 1em;
  310. font-style: italic;
  311. font-weight: bold;
  312. }
  313. .markdown-body dl dd {
  314. padding: 0 16px;
  315. margin-bottom: 16px;
  316. }
  317. .markdown-body blockquote {
  318. padding: 0 15px;
  319. color: #777;
  320. border-left: 4px solid #ddd;
  321. }
  322. .markdown-body blockquote>:first-child {
  323. margin-top: 0;
  324. }
  325. .markdown-body blockquote>:last-child {
  326. margin-bottom: 0;
  327. }
  328. .markdown-body table {
  329. display: block;
  330. width: 100%;
  331. overflow: auto;
  332. word-break: normal;
  333. word-break: keep-all;
  334. }
  335. .markdown-body table th {
  336. font-weight: bold;
  337. }
  338. .markdown-body table th,
  339. .markdown-body table td {
  340. padding: 6px 13px;
  341. border: 1px solid #ddd;
  342. }
  343. .markdown-body table tr {
  344. background-color: #fff;
  345. border-top: 1px solid #ccc;
  346. }
  347. .markdown-body table tr:nth-child(2n) {
  348. background-color: #f8f8f8;
  349. }
  350. .markdown-body img {
  351. max-width: 100%;
  352. -moz-box-sizing: border-box;
  353. box-sizing: border-box;
  354. }
  355. .markdown-body code {
  356. padding: 0;
  357. padding-top: 0.2em;
  358. padding-bottom: 0.2em;
  359. margin: 0;
  360. font-size: 85%;
  361. background-color: rgba(0,0,0,0.04);
  362. border-radius: 3px;
  363. }
  364. .markdown-body code:before,
  365. .markdown-body code:after {
  366. letter-spacing: -0.2em;
  367. content: "\00a0";
  368. }
  369. .markdown-body pre>code {
  370. padding: 0;
  371. margin: 0;
  372. font-size: 100%;
  373. word-break: normal;
  374. white-space: pre;
  375. background: transparent;
  376. border: 0;
  377. }
  378. .markdown-body .highlight {
  379. margin-bottom: 16px;
  380. }
  381. .markdown-body .highlight pre,
  382. .markdown-body pre {
  383. padding: 16px;
  384. overflow: auto;
  385. font-size: 85%;
  386. line-height: 1.45;
  387. background-color: #f7f7f7;
  388. border-radius: 3px;
  389. }
  390. .markdown-body .highlight pre {
  391. margin-bottom: 0;
  392. word-break: normal;
  393. }
  394. .markdown-body pre {
  395. word-wrap: normal;
  396. }
  397. .markdown-body pre code {
  398. display: inline;
  399. max-width: initial;
  400. padding: 0;
  401. margin: 0;
  402. overflow: initial;
  403. line-height: inherit;
  404. word-wrap: normal;
  405. background-color: transparent;
  406. border: 0;
  407. }
  408. .markdown-body pre code:before,
  409. .markdown-body pre code:after {
  410. content: normal;
  411. }
  412. .markdown-body .highlight {
  413. background: #fff;
  414. }
  415. .markdown-body .highlight .h {
  416. color: #333;
  417. font-style: normal;
  418. font-weight: normal;
  419. }
  420. .markdown-body .highlight .mf,
  421. .markdown-body .highlight .mh,
  422. .markdown-body .highlight .mi,
  423. .markdown-body .highlight .mo,
  424. .markdown-body .highlight .il,
  425. .markdown-body .highlight .m {
  426. color: #945277;
  427. }
  428. .markdown-body .highlight .s,
  429. .markdown-body .highlight .sb,
  430. .markdown-body .highlight .sc,
  431. .markdown-body .highlight .sd,
  432. .markdown-body .highlight .s2,
  433. .markdown-body .highlight .se,
  434. .markdown-body .highlight .sh,
  435. .markdown-body .highlight .si,
  436. .markdown-body .highlight .sx,
  437. .markdown-body .highlight .s1 {
  438. color: #df5000;
  439. }
  440. .markdown-body .highlight .kc,
  441. .markdown-body .highlight .kd,
  442. .markdown-body .highlight .kn,
  443. .markdown-body .highlight .kp,
  444. .markdown-body .highlight .kr,
  445. .markdown-body .highlight .kt,
  446. .markdown-body .highlight .k,
  447. .markdown-body .highlight .o {
  448. font-weight: bold;
  449. }
  450. .markdown-body .highlight .kt {
  451. color: #458;
  452. }
  453. .markdown-body .highlight .c,
  454. .markdown-body .highlight .cm,
  455. .markdown-body .highlight .c1 {
  456. color: #998;
  457. font-style: italic;
  458. }
  459. .markdown-body .highlight .cp,
  460. .markdown-body .highlight .cs,
  461. .markdown-body .highlight .cp .h {
  462. color: #999;
  463. font-weight: bold;
  464. }
  465. .markdown-body .highlight .cs {
  466. font-style: italic;
  467. }
  468. .markdown-body .highlight .n {
  469. color: #333;
  470. }
  471. .markdown-body .highlight .na,
  472. .markdown-body .highlight .nv,
  473. .markdown-body .highlight .vc,
  474. .markdown-body .highlight .vg,
  475. .markdown-body .highlight .vi {
  476. color: #008080;
  477. }
  478. .markdown-body .highlight .nb {
  479. color: #0086B3;
  480. }
  481. .markdown-body .highlight .nc {
  482. color: #458;
  483. font-weight: bold;
  484. }
  485. .markdown-body .highlight .no {
  486. color: #094e99;
  487. }
  488. .markdown-body .highlight .ni {
  489. color: #800080;
  490. }
  491. .markdown-body .highlight .ne {
  492. color: #990000;
  493. font-weight: bold;
  494. }
  495. .markdown-body .highlight .nf {
  496. color: #945277;
  497. font-weight: bold;
  498. }
  499. .markdown-body .highlight .nn {
  500. color: #555;
  501. }
  502. .markdown-body .highlight .nt {
  503. color: #000080;
  504. }
  505. .markdown-body .highlight .err {
  506. color: #a61717;
  507. background-color: #e3d2d2;
  508. }
  509. .markdown-body .highlight .gd {
  510. color: #000;
  511. background-color: #fdd;
  512. }
  513. .markdown-body .highlight .gd .x {
  514. color: #000;
  515. background-color: #faa;
  516. }
  517. .markdown-body .highlight .ge {
  518. font-style: italic;
  519. }
  520. .markdown-body .highlight .gr {
  521. color: #aa0000;
  522. }
  523. .markdown-body .highlight .gh {
  524. color: #999;
  525. }
  526. .markdown-body .highlight .gi {
  527. color: #000;
  528. background-color: #dfd;
  529. }
  530. .markdown-body .highlight .gi .x {
  531. color: #000;
  532. background-color: #afa;
  533. }
  534. .markdown-body .highlight .go {
  535. color: #888;
  536. }
  537. .markdown-body .highlight .gp {
  538. color: #555;
  539. }
  540. .markdown-body .highlight .gs {
  541. font-weight: bold;
  542. }
  543. .markdown-body .highlight .gu {
  544. color: #800080;
  545. font-weight: bold;
  546. }
  547. .markdown-body .highlight .gt {
  548. color: #aa0000;
  549. }
  550. .markdown-body .highlight .ow {
  551. font-weight: bold;
  552. }
  553. .markdown-body .highlight .w {
  554. color: #bbb;
  555. }
  556. .markdown-body .highlight .sr {
  557. color: #017936;
  558. }
  559. .markdown-body .highlight .ss {
  560. color: #8b467f;
  561. }
  562. .markdown-body .highlight .bp {
  563. color: #999;
  564. }
  565. .markdown-body .highlight .gc {
  566. color: #999;
  567. background-color: #EAF2F5;
  568. }
  569. .markdown-body kbd {
  570. background-color: #e7e7e7;
  571. background-image: -webkit-linear-gradient(#fefefe, #e7e7e7);
  572. background-image: linear-gradient(#fefefe, #e7e7e7);
  573. background-repeat: repeat-x;
  574. display: inline-block;
  575. padding: 3px 5px;
  576. font: 11px Consolas, "Liberation Mono", Menlo, Courier, monospace;
  577. line-height: 10px;
  578. color: #000;
  579. border: 1px solid #cfcfcf;
  580. border-radius: 2px;
  581. }
  582. .markdown-body .highlight .pl-coc,
  583. .markdown-body .highlight .pl-entm,
  584. .markdown-body .highlight .pl-eoa,
  585. .markdown-body .highlight .pl-mai .pl-sf,
  586. .markdown-body .highlight .pl-pdv,
  587. .markdown-body .highlight .pl-sc,
  588. .markdown-body .highlight .pl-sr,
  589. .markdown-body .highlight .pl-v,
  590. .markdown-body .highlight .pl-vpf {
  591. color: #0086b3;
  592. }
  593. .markdown-body .highlight .pl-eoac,
  594. .markdown-body .highlight .pl-mdht,
  595. .markdown-body .highlight .pl-mi1,
  596. .markdown-body .highlight .pl-mri,
  597. .markdown-body .highlight .pl-va,
  598. .markdown-body .highlight .pl-vpu {
  599. color: #008080;
  600. }
  601. .markdown-body .highlight .pl-c,
  602. .markdown-body .highlight .pl-pdc {
  603. color: #b4b7b4;
  604. font-style: italic;
  605. }
  606. .markdown-body .highlight .pl-k,
  607. .markdown-body .highlight .pl-ko,
  608. .markdown-body .highlight .pl-kolp,
  609. .markdown-body .highlight .pl-mc,
  610. .markdown-body .highlight .pl-mr,
  611. .markdown-body .highlight .pl-ms,
  612. .markdown-body .highlight .pl-s,
  613. .markdown-body .highlight .pl-sok,
  614. .markdown-body .highlight .pl-st {
  615. color: #6e5494;
  616. }
  617. .markdown-body .highlight .pl-ef,
  618. .markdown-body .highlight .pl-enf,
  619. .markdown-body .highlight .pl-enm,
  620. .markdown-body .highlight .pl-entc,
  621. .markdown-body .highlight .pl-eoi,
  622. .markdown-body .highlight .pl-sf,
  623. .markdown-body .highlight .pl-smc {
  624. color: #d12089;
  625. }
  626. .markdown-body .highlight .pl-ens,
  627. .markdown-body .highlight .pl-eoai,
  628. .markdown-body .highlight .pl-kos,
  629. .markdown-body .highlight .pl-mh .pl-pdh,
  630. .markdown-body .highlight .pl-mp,
  631. .markdown-body .highlight .pl-pde,
  632. .markdown-body .highlight .pl-stp {
  633. color: #458;
  634. }
  635. .markdown-body .highlight .pl-enti {
  636. color: #d12089;
  637. font-weight: bold;
  638. }
  639. .markdown-body .highlight .pl-cce,
  640. .markdown-body .highlight .pl-enc,
  641. .markdown-body .highlight .pl-kou,
  642. .markdown-body .highlight .pl-mq {
  643. color: #f93;
  644. }
  645. .markdown-body .highlight .pl-mp1 .pl-sf {
  646. color: #458;
  647. font-weight: bold;
  648. }
  649. .markdown-body .highlight .pl-cos,
  650. .markdown-body .highlight .pl-ent,
  651. .markdown-body .highlight .pl-md,
  652. .markdown-body .highlight .pl-mdhf,
  653. .markdown-body .highlight .pl-ml,
  654. .markdown-body .highlight .pl-pdc1,
  655. .markdown-body .highlight .pl-pds,
  656. .markdown-body .highlight .pl-s1,
  657. .markdown-body .highlight .pl-scp,
  658. .markdown-body .highlight .pl-sol {
  659. color: #df5000;
  660. }
  661. .markdown-body .highlight .pl-c1,
  662. .markdown-body .highlight .pl-cn,
  663. .markdown-body .highlight .pl-pse,
  664. .markdown-body .highlight .pl-pse .pl-s2,
  665. .markdown-body .highlight .pl-vi {
  666. color: #a31515;
  667. }
  668. .markdown-body .highlight .pl-mb,
  669. .markdown-body .highlight .pl-pdb {
  670. color: #df5000;
  671. font-weight: bold;
  672. }
  673. .markdown-body .highlight .pl-mi,
  674. .markdown-body .highlight .pl-pdi {
  675. color: #6e5494;
  676. font-style: italic;
  677. }
  678. .markdown-body .highlight .pl-ms1 {
  679. background-color: #f5f5f5;
  680. }
  681. .markdown-body .highlight .pl-mdh,
  682. .markdown-body .highlight .pl-mdi {
  683. font-weight: bold;
  684. }
  685. .markdown-body .highlight .pl-mdr {
  686. color: #0086b3;
  687. font-weight: bold;
  688. }
  689. .markdown-body .highlight .pl-s2 {
  690. color: #333;
  691. }
  692. .markdown-body .highlight .pl-ii {
  693. background-color: #df5000;
  694. color: #fff;
  695. }
  696. .markdown-body .highlight .pl-ib {
  697. background-color: #f93;
  698. }
  699. .markdown-body .highlight .pl-id {
  700. background-color: #a31515;
  701. color: #fff;
  702. }
  703. .markdown-body .highlight .pl-iu {
  704. background-color: #b4b7b4;
  705. }
  706. .markdown-body .highlight .pl-mo {
  707. color: #969896;
  708. }
  709. .markdown-body .task-list-item {
  710. list-style-type: none;
  711. }
  712. .markdown-body .task-list-item+.task-list-item {
  713. margin-top: 3px;
  714. }
  715. .markdown-body .task-list-item input {
  716. float: left;
  717. margin: 0.3em 0 0.25em -1.6em;
  718. vertical-align: middle;
  719. }</style><script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
  720. <script>
  721. MathJax.Hub.Config({
  722. config: ["MMLorHTML.js"],
  723. extensions: ["tex2jax.js"],
  724. jax: ["input/TeX"],
  725. tex2jax: {
  726. inlineMath: [ ['$','$'], ["\\(","\\)"] ],
  727. displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
  728. processEscapes: false
  729. },
  730. TeX: {
  731. extensions: ["AMSmath.js", "AMSsymbols.js"],
  732. TagSide: "right",
  733. TagIndent: ".8em",
  734. MultLineWidth: "85%",
  735. equationNumbers: {
  736. autoNumber: "AMS",
  737. },
  738. unicode: {
  739. fonts: "STIXGeneral,'Arial Unicode MS'"
  740. }
  741. },
  742. showProcessingMessages: false
  743. });
  744. </script>
  745. <title>arrays-GreenScreen</title></head><body><article class="markdown-body"><p><a href="#markdown-header-arrays-green-screen">English</a> | <a href="#markdown-header-arreglos-pantalla-verde">Español</a></p>
  746. <h1>
  747. <a id="user-content-arreglos---pantalla-verde" class="anchor" href="#arreglos---pantalla-verde" aria-hidden="true"><span class="octicon octicon-link"></span></a>Arreglos - Pantalla Verde</h1>
  748. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/main1.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/main1.png" alt="main1.png" style="max-width:100%;"></a>
  749. <a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/main2.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/main2.png" alt="main2.png" style="max-width:100%;"></a>
  750. <a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/main3.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/main3.png" alt="main3.png" style="max-width:100%;"></a></p>
  751. <p>Los arreglos de datos (<em>arrays</em>) nos facilitan guardar y trabajar con grupos de datos del mismo tipo. Los datos se guardan en espacios de memoria consecutivos a los que se puede acceder utilizando el nombre del arreglo e índices o suscritos que indican la posición en que se encuentra el dato. Las estructuras de repetición nos proveen una manera simple de acceder a los datos de un arreglo. En la experiencia de laboratorio de hoy practicarás el uso de ciclos anidados en la manipulación de arreglos bi-dimensionales usando técnicas de "pantalla verde".</p>
  752. <h2>
  753. <a id="user-content-objetivos" class="anchor" href="#objetivos" aria-hidden="true"><span class="octicon octicon-link"></span></a>Objetivos:</h2>
  754. <ol>
  755. <li><p>Practicar el acceso y manipulación de datos en un arreglo.</p></li>
  756. <li><p>Aplicar ciclos anidados para implementar técnicas de "pantalla verde".</p></li>
  757. <li><p>Utilizar expresiones aritméticas y estructuras de selección para transformar colores de píxeles.</p></li>
  758. <li><p>Acceder píxeles en una imagen y descomponerlos en sus componentes rojo, azul y verde.</p></li>
  759. </ol>
  760. <h2>
  761. <a id="user-content-pre-lab" class="anchor" href="#pre-lab" aria-hidden="true"><span class="octicon octicon-link"></span></a>Pre-Lab:</h2>
  762. <p>Antes de llegar al laboratorio debes:</p>
  763. <ol>
  764. <li><p>Haber repasado los conceptos básicos relacionados a estructuras de repetición, ciclos anidados y arreglos bi-dimensionales.</p></li>
  765. <li><p>Conocer los métodos básicos de <code>QImage</code> para manipular los pixeles de las imágenes. </p></li>
  766. <li><p>Haber estudiado los conceptos e instrucciones para la sesión de laboratorio.</p></li>
  767. <li><p>Haber tomado el quiz Pre-Lab que se encuentra en Moodle.</p></li>
  768. </ol>
  769. <hr>
  770. <hr>
  771. <h2>
  772. <a id="user-content-tecnología-de-pantalla-verde-green-screen" class="anchor" href="#tecnolog%C3%ADa-de-pantalla-verde-green-screen" aria-hidden="true"><span class="octicon octicon-link"></span></a>Tecnología de pantalla verde ("Green Screen")</h2>
  773. <p>En esta experiencia de laboratorio, aprenderás los conceptos y destrezas básicas de la tecnología de pantalla verde que se usa en boletines informativos de televisión, películas, juegos de video y otros. La composición de pantalla verde, o composición cromática, es una técnica que se usa para combinar dos imágenes o cuadros de video [1]. Esta técnica de post-producción crea efectos especiales al componer dos imágenes o transmisiones de video sustituyendo el área de un color sólido por otra imágen [2]. La composición cromática se puede hacer con imágenes de objetos sobre fondos de cualquier color que sean uniformes y diferentes a los de la imagen. Los fondos azules y verdes son los que se usan con más frecuencia porque se distinguen con más facilidad de los tonos de la mayoría de los colores de piel humanos.</p>
  774. <p>Para esta experiencia de laboratorio te proveemos un interfaz gráfico (GUI) simple que permite al usuario cargar una imagen con un objeto sobre un fondo de color sólido (preferiblemente azul o verde) y una imagen para sustituir el fondo. Tu tarea es crear e implementar una función que cree una tercera imagen compuesta en la cual, a la imagen del objeto con el fondo de color sólido se le removerá el color de fondo y el objeto aparecerá sobre la imagen que será el nuevo fondo. La Figura 1 muestra un ejemplo de los resultados esperados.</p>
  775. <hr>
  776. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure1.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure1.png" alt="figure1.png" style="max-width:100%;"></a></p>
  777. <p><strong>Figura 1.</strong> Ejemplo de los resultados esperados. El objeto de interés es la mano con las gafas.</p>
  778. <hr>
  779. <p>Con el propósito de ilustrar el procedimiento, llamemos la imagen del objeto con el fondo de color sólido <em>imagen A</em>, y supongamos que el color sólido en el fondo tiene un "RGB" <code>0x00ff00</code> (verde puro). Llamemos <em>imagen B</em> a la imagen que usaremos para el fondo, un fondo que resulte interesante. Para este ejemplo, supongamos también que los tamaños de ambas imágenes son iguales (mismo ancho y alto).</p>
  780. <p>Para producir la imagen compuesta (<em>imagen C</em>), podríamos comenzar copiando toda la <em>imagen B</em> que usaremos de fondo a la <em>imagen C</em>. Luego, para insertar solo el objeto que nos interesa en la imagen compuesta podemos recorrer la <em>imagen A</em> píxel por píxel. Compararíamos el color de cada píxel <em>p</em> en la <em>imagen A</em> con el color de fondo <code>0x00ff00</code>. Si son <em>similares</em>, el píxel de la <em>imagen A</em> corresponde al color sólido de fondo y dejamos el píxel de la <em>imagen C</em> como está (el fondo nuevo). Si el color de <em>p</em> no es <em>similar</em> a <code>0x00ff00</code>, modificamos el píxel correspondiente en la <em>imagen C</em>, copiando el color del píxel del objeto a la imagen compuesta. Esto se ilustra en la Figura 2.</p>
  781. <hr>
  782. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure2.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure2.png" alt="figure2.png" style="max-width:100%;"></a></p>
  783. <p><strong>Figura 2.</strong> Ilustración de cómo el algoritmo decide cuáles píxeles de la <em>imagen A</em> incluir en la <em>imagen C</em>.</p>
  784. <hr>
  785. <hr>
  786. <h2>
  787. <a id="user-content-píxeles" class="anchor" href="#p%C3%ADxeles" aria-hidden="true"><span class="octicon octicon-link"></span></a>Píxeles</h2>
  788. <p>Al elemento más pequeño de una imagen se le llama un <em>píxel</em>. Esta unidad consiste de un solo color. Como cada color es una combinación de tonalidades de los colores primarios rojo, verde y azul, se codifica como un entero sin signo cuyos bytes representan los tonos de rojo, verde y azul del pixel (Figura 3). A esta combinación se le llama el <em>RGB</em> del color por las siglas de "Red-Green-Blue". Por ejemplo un píxel de color rojo (puro) tiene una representación RGB <code>0x00ff0000</code>, mientras que un píxel de color blanco tiene una representación RGB de <code>0x00FFFFFF</code> (ya que el color blanco es la combinación de los tonos rojo, verde y azul en toda su intensidad).</p>
  789. <hr>
  790. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure3.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure3.png" alt="figure3.png" style="max-width:100%;"></a></p>
  791. <p><strong>Figura 3.</strong> Distribución de bits para las tonalidades de rojo, verde y azul dentro de la representación RGB. Cada tonalidad puede tener valores entre 0x00 (los ocho bits en 0) y 0xFF (los 8 bits en 1). </p>
  792. <hr>
  793. <p>En <code>Qt</code> se utiliza el tipo <code>QRgb</code> para representar valores <code>RGB</code>. Utilizando ciertas funciones que describimos abajo podemos obtener los componentes rojo, verde y azul del valor <code>QRgb</code> del píxel y así manipular imágenes.</p>
  794. <h3>
  795. <a id="user-content-biblioteca" class="anchor" href="#biblioteca" aria-hidden="true"><span class="octicon octicon-link"></span></a>Biblioteca</h3>
  796. <p>La experiencia de laboratorio de hoy utilizará la clase <code>QImage</code>. Esta clase permite acceder a los datos de los pixeles de una imagen para poder manipularla. La documentación de la clase <code>QImage</code> se encuentra en <a href="http://doc.qt.io/qt-4.8/qimage.html">http://doc.qt.io/qt-4.8/qimage.html</a>.</p>
  797. <p>El código que te proveemos contiene los siguiente objetos de la clase <code>QImage</code>:</p>
  798. <ul>
  799. <li>
  800. <code>originalImage</code> // contiene la información de la imagen original que vas a editar</li>
  801. <li> <code>editedImage</code> // contendrá la imagen editada</li>
  802. </ul>
  803. <p>Los objetos de clase <code>QImage</code> tienen los siguiente métodos que serán útiles para la experiencia de laboratorio de hoy:</p>
  804. <ul>
  805. <li>
  806. <code>width()</code> // devuelve el valor entero del ancho de la imagen</li>
  807. <li>
  808. <code>height()</code> // devuelve el valor entero de la altura de la imagen</li>
  809. <li>
  810. <code>pixel(i, j)</code> // devuelve el <code>QRgb</code> del píxel en la posición <code>(i,j)</code>
  811. </li>
  812. <li>
  813. <code>setPixel(i,j, pixel)</code> // modifica el valor del píxel en la posición <code>(i, j)</code> al valor píxel <code>QRgb</code>
  814. </li>
  815. </ul>
  816. <p>Las siguientes funciones son útiles para trabajar con datos de tipo <code>QRgb</code>:</p>
  817. <ul>
  818. <li>
  819. <code>qRed(pixel)</code> // devuelve el tono del color rojo del píxel</li>
  820. <li>
  821. <code>qGreen(pixel)</code> // devuelve el tono del color verde del píxel</li>
  822. <li>
  823. <code>qBlue(pixel)</code> // devuelve el tono del color azul del píxel</li>
  824. <li>
  825. <code>qRgb(int red, int green, int blue)</code> // devuelve un píxel <code>QRgb</code> compuesto de los valores de rojo, verde y azul recibidos.</li>
  826. </ul>
  827. <h4>
  828. <a id="user-content-ejemplos" class="anchor" href="#ejemplos" aria-hidden="true"><span class="octicon octicon-link"></span></a>Ejemplos:</h4>
  829. <ol>
  830. <li>
  831. <p><code>QRgb myRgb = qRgb(0xff, 0x00, 0xff);</code>: Asigna a <code>myRgb</code> el valor <code>0xff00ff</code> que representa el color <a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure4.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure4.png" alt="figure4.png" style="max-width:100%;"></a></p>
  832. <p>Nota que el valor <code>0xff00ff</code> representa los valores <code>0xff</code>, <code>0x0</code>, <code>0xff</code>, que corresponden a los componentes rojo, verde y azul de <code>myRgb</code>.</p>
  833. </li>
  834. <li>
  835. <p>Si la siguiente imagen <code>4 x 4</code> de píxeles representa el objeto <code>originalImage</code>,</p>
  836. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/ejemplo.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/ejemplo.png" alt="ejemplo.png" style="max-width:100%;"></a></p>
  837. <p>entonces <code>originalImage.pixel(2,1)</code> devuelve un valor <code>rgb</code> que representa el color azul (<code>0x0000ff</code>).</p>
  838. </li>
  839. <li>
  840. <p>La siguiente instrucción asigna el color rojo al píxel en posición <code>(2,3)</code> en la imagen editada:</p>
  841. <p><code>editedImage.setPixel(2,3,qRgb(0xff,0x00,0x00));</code>.</p>
  842. </li>
  843. <li>
  844. <p>La siguiente instrucción le asigna a <code>greenContent</code> el valor del tono de verde que contiene el pixel <code>(1,1)</code> de <code>originalImage</code>:</p>
  845. <p><code>int greenContent = qGreen(originalImage.pixel(1,1));</code>.</p>
  846. </li>
  847. <li><p>El siguiente programa crea un objeto de clase <code>QImage</code> e imprime los componentes rojo, verde y azul del pixel en el centro de la imagen. La imagen utilizada es la que se especifica dentro del paréntesis durante la creación del objeto, esto es, el archivo <code>chuck.png</code>.</p></li>
  848. </ol>
  849. <hr>
  850. <div class="highlight highlight-cpp"><pre>#<span class="pl-k">include</span> <span class="pl-s"><span class="pl-pds">&lt;</span>QImage<span class="pl-pds">&gt;</span></span>
  851. #<span class="pl-k">include</span> <span class="pl-s"><span class="pl-pds">&lt;</span>iostream<span class="pl-pds">&gt;</span></span>
  852. <span class="pl-k">using</span> <span class="pl-k">namespace</span> <span class="pl-en">std</span><span class="pl-k">;</span>
  853. <span class="pl-k">int</span> <span class="pl-en">main</span>() {
  854. QImage <span class="pl-smi">myImage</span>(“/Users/rarce/Downloads/chuck.<span class="pl-smi">png</span>”);
  855. QRgb centralPixel;
  856. centralPixel = myImage.<span class="pl-c1">pixel</span>(myImage.<span class="pl-c1">width</span>() / <span class="pl-c1">2</span>, myImage.<span class="pl-c1">height</span>() / <span class="pl-c1">2</span>);
  857. cout &lt;&lt; hex;
  858. cout &lt;&lt; “Los componentes rojo, verde y azul del pixel central son: “
  859. &lt;&lt; <span class="pl-c1">qRed</span>(centralPixel) &lt;&lt; “, “
  860. &lt;&lt; <span class="pl-c1">qGreen</span>(centralPixel) &lt;&lt; “, “
  861. &lt;&lt; <span class="pl-c1">qBlue</span>(centralPixel) &lt;&lt; endl;
  862. <span class="pl-k">return</span> <span class="pl-c1">0</span>;
  863. }</pre></div>
  864. <hr>
  865. <h3>
  866. <a id="user-content-midiendo-la-similaridad-de-los-colores-de-los-pixeles" class="anchor" href="#midiendo-la-similaridad-de-los-colores-de-los-pixeles" aria-hidden="true"><span class="octicon octicon-link"></span></a>Midiendo la similaridad de los colores de los pixeles</h3>
  867. <p>Observa la Figura 4 abajo. Aunque el fondo en la <em>imagen A</em> parece uniforme, realmente incluye píxeles de diferentes colores (aunque parecidos).</p>
  868. <hr>
  869. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure5.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure5.png" alt="figure5.png" style="max-width:100%;"></a></p>
  870. <p><strong>Figura 4.</strong> Lo que puede parecer un color <em>sólido</em>, realmente no lo es. </p>
  871. <hr>
  872. <p>Por esto, en lugar de solo considerar como parte del fondo sólido los píxeles cuyo color es <strong>exactamente</strong> <code>0x00FF00</code>, medimos la <em>distancia</em> del valor del color del píxel al valor del color <em>puro</em>. Una distancia pequeña significa que el color es <em>casi</em> verde puro. La ecuación para la <em>distancia</em> es:</p>
  873. <p>$$distancia = \sqrt{(P_R-S_R)^2+(P_G-S_G)^2+(P_B-S_B)^2},$$</p>
  874. <p>donde $$P_R, P_G, P_B$$ son los valores de los componentes rojo, verde y azul del píxel bajo consideración, y $$S_R, S_G, S_B$$ son los valores de los componentes rojo, verde y azul del fondo sólido. En nuestro ejemplo, $$S_R=S_B=0$$ y $$S_G=255$$.</p>
  875. <hr>
  876. <hr>
  877. <h2>
  878. <a id="user-content-sesión-de-laboratorio" class="anchor" href="#sesi%C3%B3n-de-laboratorio" aria-hidden="true"><span class="octicon octicon-link"></span></a>Sesión de laboratorio:</h2>
  879. <p>En el laboratorio de hoy, comenzando con una imagen con un objeto de interés sobre un fondo de color sólido y una imagen para utilizar como fondo, definirás e implantarás una función que cree una tercera imagen compuesta en la cual, a la imagen del objeto de interés se le removerá el color de fondo y aparecerá sobre la imagen para el fondo.</p>
  880. <p>Estarás trabajando con el archivo <code>Filter.cpp</code>. Lo que sigue es un resumen de las variables en este archivo.</p>
  881. <ul>
  882. <li>
  883. <code>objectImage</code>: referencia a la imagen del objeto de interés y fondo sólido</li>
  884. <li>
  885. <code>backgroundImage</code>: referencia a la imagen para el fondo</li>
  886. <li>
  887. <code>mergedImage</code>: referencia a la imagen compuesta</li>
  888. <li>
  889. <code>threshold</code>: valor umbral usado para comparar las distancias entre el valor del color del píxel de la imagen con el objeto sobre fondo sólido. En el código que se provee, el valor del umbral se lee del valor de la barra deslizable.</li>
  890. <li>
  891. <code>ghost</code>: valor Booleano utilizado para aplicar el filtro "fantasma" a los pixeles. </li>
  892. <li>
  893. <code>(x, y)</code>: coordenadas de un pixel de la imagen del objeto sobre fondo sólido. El valor por defecto es <code>(0,0)</code>. </li>
  894. <li>
  895. <code>(offset_x, offset_y)</code>: coordenadas de la imagen compuesta en donde la esquina superior izquierda de la imagen del objeto sobre fondo sólido será insertada. El valor por defecto es <code>(0,0)</code>. </li>
  896. </ul>
  897. <h3>
  898. <a id="user-content-ejercicio-1-crear-imagen-compuesta" class="anchor" href="#ejercicio-1-crear-imagen-compuesta" aria-hidden="true"><span class="octicon octicon-link"></span></a>Ejercicio 1: Crear imagen compuesta</h3>
  899. <h4>
  900. <a id="user-content-instrucciones" class="anchor" href="#instrucciones" aria-hidden="true"><span class="octicon octicon-link"></span></a>Instrucciones</h4>
  901. <ol>
  902. <li><p>Carga a QtCreator el proyecto <code>GreenScreen</code> haciendo doble "click" en el archivo <code>GreenScreen.pro</code> en el directorio <code>Documents/eip/Arrays-GreenScreen</code> de tu computadora. También puedes ir a <code>http://bitbucket.org/eip-uprrp/arrays-greenscreen</code> para descargar la carpeta <code>Arrays-GreenScreen</code> a tu computadora.</p></li>
  903. <li>
  904. <p>Compila y corre el programa. El código que te proveemos crea la interfaz de la Figura 5. Los botones <em>Select Image</em> y <em>Select Background Image</em> ya han sido programados.</p>
  905. <hr>
  906. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure6.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure6.png" alt="figure6.png" style="max-width:100%;"></a></p>
  907. <p><strong>Figura 5.</strong> Interfaz de la aplicación GreenScreen.</p>
  908. <hr>
  909. </li>
  910. <li><p>Marca el botón para cargar una imagen del objeto de interés sobre fondo sólido, luego marca el botón para seleccionar la imagen para el fondo. El directorio con los archivos fuente contiene una carpeta llamada <code>landscapes</code> que contiene imágenes de fondo, y una carpeta llamada <code>green_background</code> que contiene imágenes de objetos sobre fondo de color sólido.</p></li>
  911. <li><p>Tu primera tarea es completar la función <code>MergeImages</code> en el archivo <code>Filter.cpp</code>. La función <code>MergeImages</code> se invoca cuando el usuario marca el botón <code>Merge Images</code> y cuando se desliza la barra. La función <code>MergeImages</code> recibe las referencias a la imagen con objeto de interés y fondo sólido, la imagen para el fondo y la imagen compuesta, un valor umbral, las coordenadas <code>(x,y)</code> de un píxel de la imagen del objeto sobre fondo sólido, y las coordenadas <code>(offset_x, offset_y)</code> de la imagen compuesta. </p></li>
  912. </ol>
  913. <p>Para este ejercicio puedes ignorar el filtro "fantasma" <code>ghost</code> y las coordenadas <code>(offset_x, offset_y)</code>, y solo componer la imagen con el objeto de interés en la imagen de fondo, comenzando en la posición <code>(0,0)</code>.</p>
  914. <p><strong>Algoritmo</strong></p>
  915. <ol>
  916. <li><p>Adquiere el valor del color sólido. El color sólido será el color del píxel en la posición <code>(x,y)</code> en la imagen del objeto sobre fondo sólido. El valor por defecto para <code>(x,y)</code> es <code>(0,0)</code>.</p></li>
  917. <li><p>Para todas las posiciones <code>(i,j)</code>, adquiere el valor del color del píxel en la posición <code>(i,j)</code> de la imagen con el objeto. Computa la distancia entre el color de la imagen con el objeto y el valor del color sólido. Si la distancia entre el color sólido y el color del píxel de la imagen es mayor que que el valor umbral, cambia el valor del color del píxel en la posición <code>(i,j)</code> de la imagen de fondo al valor del color de la imagen con el objeto.</p></li>
  918. </ol>
  919. <p>Prueba tu implantación cargando imágenes de objetos e imágenes para el fondo y verificando la imagen compuesta.</p>
  920. <h3>
  921. <a id="user-content-ejercicio-2-crear-imagen-compuesta-usando-filtro-ghost" class="anchor" href="#ejercicio-2-crear-imagen-compuesta-usando-filtro-ghost" aria-hidden="true"><span class="octicon octicon-link"></span></a>Ejercicio 2: Crear imagen compuesta usando filtro <code>ghost</code>
  922. </h3>
  923. <p>En este ejercicio modificarás el Ejercicio 1 para aplicar el filtro fantasma a cada uno de los píxeles que se compondrán sobre la imagen de fondo en el caso de que la variable <code>ghost</code> sea cierta. El filtro fantasma creará el efecto de que el objeto en la imagen compuesta se verá como un "fantasma" sobre la imagen de fondo, como en la Figura 6.</p>
  924. <hr>
  925. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure7.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure7.png" alt="figure7.png" style="max-width:100%;"></a></p>
  926. <p><strong>Figura 6.</strong> Imagen con filtro fantasma. En este ejemplo, el perro en la imagen con el fondo sólido se compone sobre la imagen de fondo utilizando el filtro fantasma.</p>
  927. <hr>
  928. <p>El efecto fantasma se consigue promediando el valor del color del píxel del fondo con el valor del color del píxel correspondiente del objeto, en lugar de solo reemplazar el valor del color del píxel del fondo por el del objeto. Calculamos el promedio de cada uno de los componentes (rojo, verde y azul)</p>
  929. <p>$$N_R=\frac{S_R+B_R}{2}$$
  930. $$N_G=\frac{S_G+B_G}{2}$$
  931. $$N_B=\frac{S_B+B_B}{2},$$</p>
  932. <p>en donde $$N_R, N_G, N_B$$ son los componentes rojo, verde y azul del nuevo píxel fantasma, $$S_R, S_G, S_B$$ son los componentes de la imagen del objeto, y $$B_R, B_G, B_B$$ son los componentes de la imagen de fondo.</p>
  933. <h3>
  934. <a id="user-content-ejercicio-3-crear-imagen-compuesta-colocando-el-objeto-en-una-posición-específica" class="anchor" href="#ejercicio-3-crear-imagen-compuesta-colocando-el-objeto-en-una-posici%C3%B3n-espec%C3%ADfica" aria-hidden="true"><span class="octicon octicon-link"></span></a>Ejercicio 3: Crear imagen compuesta colocando el objeto en una posición específica</h3>
  935. <p>El "widget" que despliega el fondo fue programado para que detecte la posición marcada por el usuario. En este ejercicio programarás la función <code>MergeImages</code> para que el objeto sea desplegado en la posición marcada por el usuario en la imagen de fondo, en lugar de ser desplegado en la esquina superior izquierda. Las Figuras 7 y 8 muestran el efecto. Nota los valores de <code>Selected Coord</code> bajo la imagen del medio.</p>
  936. <hr>
  937. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure8.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure8.png" alt="figure8.png" style="max-width:100%;"></a></p>
  938. <p><strong>Figura 7.</strong> En este ejemplo, la imagen del fondo no ha sido marcada y <code>Selected Coord</code> tiene <code>(0,0)</code> que es su valor por defecto. El perro se inserta en la imagen compuesta con su esquina superior izquierda en el lugar <code>(0,0)</code>.</p>
  939. <hr>
  940. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure9.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure9.png" alt="figure9.png" style="max-width:100%;"></a></p>
  941. <p><strong>Figura 8.</strong> En este ejemplo, la imagen del fondo fue marcada en las coordenadas <code>(827,593)</code>. La imagen del perro se inserta en la imagen compuesta con su esquina superior izquierda en la posición <code>(827,593)</code>.</p>
  942. <hr>
  943. <p>Tu tarea en este ejercicio es la misma que en el Ejercicio 1, pero esta vez debes ajustar la imagen del objeto dentro de la composición con las cantidades especificadas en los parámetros <code>x_offset</code> y <code>y_offset</code>. Recuerda tomar en consideración los límites de la imagen compuesta cuando insertes el objeto; el usuario pudiera especificar unos parámetros que se salgan de los límites y el objeto se cortará, como sucede en la Figura 9.</p>
  944. <hr>
  945. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure10.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure10.png" alt="figure10.png" style="max-width:100%;"></a></p>
  946. <p><strong>Figura 9.</strong> En este ejemplo, el usuario seleccionó una posición que asignó valores muy grandes para <code>x_offset</code> y <code>y_offset</code>; la implementación hizo el ajuste para que parte de la imagen del perro saliera en la imagen compuesta.</p>
  947. <hr>
  948. <p>El ejemplo de la Figura 10 muestra cómo se comportará la imagen del objeto al sobreponerla en la imagen que queremos de fondo. Las variables <code>offset_x, offset_y</code> representan el punto en la imagen de fondo en el que se colocará la esquina superior izquierda de la imagen del objeto. Nota que si se escoge un punto muy cerca del borde para la composición, parte de la imagen del objeto se sale de los límites de la imagen de fondo. Como hemos visto en la manipulación de arreglos, si se intenta acceder o alterar elementos que estan fuera del rango de tamaño del arreglo, al compilar occurre un error fatal. Lo mismo sucede con las imágenes. </p>
  949. <p>Debes asegurarte de que tu implementación toma en cuenta los valores de <code>offset x</code> y <code>offset y</code> para que la composición no intente acceder o alterar píxeles fuera del límite de la imagen de fondo. Si intentas acceder o alterar píxeles fuera de esos límites, resulta en un error fatal.</p>
  950. <hr>
  951. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure11.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure11.png" alt="figure11.png" style="max-width:100%;"></a></p>
  952. <p><strong>Figura 10.</strong> Ilustración de la imagen del objeto de interés con píxeles que se salen de los límites de la imagen de fondo. Si no se toma en consideración esta posibilidad en la implementación, ocurrirá un error fatal.</p>
  953. <hr>
  954. <p>Valida tu implantación seleccionando varios valores para el ajuste de "offset" y observando el efecto que tienen en la imagen compuesta. Asegúrate de tratar casos en los que tus valores para <code>x_offset</code> y <code>y_offset</code> ocasionarían que la imagen fuera cortada como ocurrió en la imagen compuesta de la Figura 9.</p>
  955. <hr>
  956. <hr>
  957. <h2>
  958. <a id="user-content-entrega" class="anchor" href="#entrega" aria-hidden="true"><span class="octicon octicon-link"></span></a>Entrega</h2>
  959. <p>Utiliza "Entrega" en Moodle para entregar el archivo <code>filter.cpp</code> que contiene la función <code>MergeImages</code>. Recuerda utilizar buenas prácticas de programación, incluir el nombre de los programadores y documentar tu programa.</p>
  960. <hr>
  961. <hr>
  962. <h2>
  963. <a id="user-content-referencias" class="anchor" href="#referencias" aria-hidden="true"><span class="octicon octicon-link"></span></a>Referencias</h2>
  964. <p>[1] <a href="http://en.wikipedia.org/wiki/Green_screen_(disambiguation)">http://en.wikipedia.org/wiki/Green_screen_(disambiguation)</a></p>
  965. <p>[2] <a href="http://en.wikipedia.org/wiki/Chroma_key">http://en.wikipedia.org/wiki/Chroma_key</a></p>
  966. <p>[3] <a href="http://doc.qt.io/qt-4.8/qimage.html">http://doc.qt.io/qt-4.8/qimage.html</a>.</p>
  967. <hr>
  968. <hr>
  969. <hr>
  970. <p><a href="#markdown-header-arrays-green-screen">English</a> | <a href="#markdown-header-arreglos-pantalla-verde">Español</a></p>
  971. <h1>
  972. <a id="user-content-arrays---green-screen" class="anchor" href="#arrays---green-screen" aria-hidden="true"><span class="octicon octicon-link"></span></a>Arrays - Green Screen</h1>
  973. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/main1.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/main1.png" alt="main1.png" style="max-width:100%;"></a>
  974. <a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/main2.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/main2.png" alt="main2.png" style="max-width:100%;"></a>
  975. <a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/main3.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/main3.png" alt="main3.png" style="max-width:100%;"></a></p>
  976. <p>Arrays help us to store and work with groups of data of the same type. The data is stored in consecutive memory spaces which can be accessed by using the name of the array and indexes or subscripts that indicate the position where the data is stored. Repetition structures provide us a simple way of accessing the data within an array. In this laboratory experience, you will be using nested loops to process bi-dimensional arrays and implement the functionality of a green-screen.</p>
  977. <h2>
  978. <a id="user-content-objectives" class="anchor" href="#objectives" aria-hidden="true"><span class="octicon octicon-link"></span></a>Objectives:</h2>
  979. <ol>
  980. <li><p>Practice accessing and modifying elements in an array.</p></li>
  981. <li><p>Use nested loops to implement greens-screen techniques.</p></li>
  982. <li><p>Use arithmetic expressions and selection structures to transform pixel colors.</p></li>
  983. <li><p>Read pixels from an image and decompose them in their red, green and blue components.</p></li>
  984. </ol>
  985. <h2>
  986. <a id="user-content-pre-lab-1" class="anchor" href="#pre-lab-1" aria-hidden="true"><span class="octicon octicon-link"></span></a>Pre-Lab:</h2>
  987. <p>Before coming to the laboratory you should have:</p>
  988. <ol>
  989. <li><p>Reviewed the basic concepts about repetition structures, nested loops, and bi-dimensional arrays.</p></li>
  990. <li><p>Understood the methods of the <code>QImage</code> class for pixel manipulation.</p></li>
  991. <li><p>Studied the concepts and instructions for the laboratory session.</p></li>
  992. <li><p>Taken the Pre-Lab quiz that is found in Moodle.</p></li>
  993. </ol>
  994. <hr>
  995. <hr>
  996. <h2>
  997. <a id="user-content-green-screen-technology" class="anchor" href="#green-screen-technology" aria-hidden="true"><span class="octicon octicon-link"></span></a>Green-screen technology</h2>
  998. <p>In this laboratory experience the student will be exposed to the basics of the green screen technology used in newscasting, motion pictures, video games, and others. Green screen compositing, or more generally chroma key compositing, is a technique for combining two still images or video frames[1]. Chroma key compositing, or chroma keying, is a special effects / post-production technique for compositing (layering) two images or video streams together based on color hues (range)[2]. Chroma keying can be done with backgrounds of any color that are uniform and distinct, but green and blue backgrounds are more commonly used because they differ most distinctly in hue from most human skin colors.</p>
  999. <p>With this laboratory we provide a simple GUI that allows the user to load an image with any solid background (although green or blue are preferred), and a background image. Your task is to implement a function that creates a third, merged image, in which the image with the solid background appears over the background image (with the solid background removed). Figure 1 shows an example of the expected results.</p>
  1000. <hr>
  1001. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure1.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure1.png" alt="figure1.png" style="max-width:100%;"></a></p>
  1002. <p>Figure 1: Example of the expected results. The object of interest is the hand carrying the sunglasses.</p>
  1003. <hr>
  1004. <p>For illustration purposes, let's call the image with the solid background <em>image A</em> and let's say that the solid color in the background has an RGB <code>0x00ff00</code> (pure green). We will refer to the image with the interesting background as <em>image B</em>. Let's also assume that both images are the same size (width and height). </p>
  1005. <p>To produce the merged image (<em>image C</em>), we could start by completely copying <em>image B</em> to <em>image *C</em>. Then, to insert only the object of interest into the merged image we could traverse <em>image A</em> pixel by pixel. We would compare the color of each pixel <em>p</em> in <em>image A</em> to the color <code>0x00FF00</code>, if they are <em>similar</em> we do nothing (because it means that this pixel is part of the solid color background). If the color of <em>p</em> is not <em>similar</em> to <code>0x00FF00</code>, we modify the corresponding pixel in <em>image C</em>, copying the color of the object's pixel to the merged image.</p>
  1006. <hr>
  1007. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure2.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure2.png" alt="figure2.png" style="max-width:100%;"></a></p>
  1008. <p><strong>Figure 2</strong> - Illustration of how the algorithm decides which pixels to include from <em>image A</em> into <em>image C</em>.</p>
  1009. <hr>
  1010. <hr>
  1011. <h3>
  1012. <a id="user-content-pixels" class="anchor" href="#pixels" aria-hidden="true"><span class="octicon octicon-link"></span></a>Pixels</h3>
  1013. <p>The smallest element in an image is called a <em>pixel</em>. This unit consists of a single color. Since each color is a combination of tones for the primary red, green and blue colors, it is coded as an unsigned integer whose bytes represent the tones of red, green and blue of the pixel (Figure 3). This combination is called the color's <em>RGB</em> which is an acronym for "Red-Green-Blue". For example, a pure red pixel has an RGB representation of <code>0x00ff0000</code>, while a white pixel has an RGB representation of <code>0x00FFFFFF</code> (since the color white is a combination of tones of red, green and blue in all of their intensity).</p>
  1014. <hr>
  1015. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure3.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure3.png" alt="figure3.png" style="max-width:100%;"></a></p>
  1016. <p><strong>Figure 3.</strong> Bit distribution for the tones of red, green and blue in an RGB representation. Each tone can have values between 0x00 (the eight bits in 0) and (0xFF (the 8 bits in 1).</p>
  1017. <hr>
  1018. <p><code>Qt</code> uses the <code>QRgb</code> type to represent <code>RGB</code> values. Using certain functions that are described below we can obtains the red, green and blue components of the <code>QRgb</code> value of the pixel and manipulate the images.</p>
  1019. <h3>
  1020. <a id="user-content-library" class="anchor" href="#library" aria-hidden="true"><span class="octicon octicon-link"></span></a>Library</h3>
  1021. <p>In today's laboratory experience you will use the <code>QImage</code> class. This class permits access to the data in the pixels of an image to manipulate it. The documentation for the <code>QImage</code> class can be found in <a href="http://doc.qt.io/qt-4.8/qimage.html">http://doc.qt.io/qt-4.8/qimage.html</a>.</p>
  1022. <p>The code provided in this project contains the following objects of the <code>QImage</code> class:</p>
  1023. <ul>
  1024. <li>
  1025. <code>originalImage</code> // contains the information of the original image that you will edit</li>
  1026. <li> <code>editedImage</code> // will contain the edited image</li>
  1027. </ul>
  1028. <p>The objects of the <code>QImage</code> class have the following methods that will be useful for today's laboratory experience:</p>
  1029. <ul>
  1030. <li>
  1031. <code>width()</code> // returns the integer value for the image's width</li>
  1032. <li>
  1033. <code>height()</code> // returns the integer value for the image's height</li>
  1034. <li>
  1035. <code>pixel(i, j)</code> // returns the <code>QRgb</code> for the pixel in position <code>(i,j)</code>
  1036. </li>
  1037. <li>
  1038. <code>setPixel(i,j, pixel)</code> // modifies the value for the pixel in position <code>(i,j)</code> to the value of pixel <code>QRgb</code>
  1039. </li>
  1040. </ul>
  1041. <p>The following functions are useful to work with data of type <code>QRgb</code>:</p>
  1042. <ul>
  1043. <li>
  1044. <code>qRed(pixel)</code> // returns the tone for the pixel's red color</li>
  1045. <li>
  1046. <code>qGreen(pixel)</code> // returns the tone for the pixel's green color</li>
  1047. <li>
  1048. <code>qBlue(pixel)</code> // returns the tone for the pixel's blue color</li>
  1049. <li>
  1050. <code>qRgb(int red, int green, int blue)</code> // returns the <code>QRgb</code> pixel composed of the red, green and blue values received.</li>
  1051. </ul>
  1052. <h4>
  1053. <a id="user-content-examples" class="anchor" href="#examples" aria-hidden="true"><span class="octicon octicon-link"></span></a>Examples:</h4>
  1054. <ol>
  1055. <li>
  1056. <p><code>QRgb myRgb = qRgb(0xff, 0x00, 0xff);</code>: Assigns the value <code>0xff00ff</code> to <code>myRgb</code> which represents the color <a href="images/figure4.jpg" target="_blank"><img src="images/figure4.jpg" alt="figure2.jpg" style="max-width:100%;"></a></p>
  1057. <p>Notice that the value <code>0xff00ff</code> represents the values <code>0xff</code>, <code>0x0</code>, and <code>0xff</code>, that correspond to the red, green and blue components in <code>myRgb</code>.</p>
  1058. </li>
  1059. <li>
  1060. <p>If the following <code>4 x 4</code> image of pixels represents the object <code>originalImage</code>,</p>
  1061. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/ejemplo.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/ejemplo.png" alt="ejemplo.png" style="max-width:100%;"></a></p>
  1062. </li>
  1063. </ol>
  1064. <p>then <code>originalImage.pixel(2,1)</code> returns the <code>rgb</code> value that represents the color blue ( <code>0x0000ff</code>).</p>
  1065. <ol>
  1066. <li>The following instruction assigns the color red to the pixel in position <code>(2,3)</code> in the edited image:</li>
  1067. </ol>
  1068. <p><code>editedImage.setPixel(2,3,qRgb(0xff,0x00,0x00));</code>.</p>
  1069. <ol>
  1070. <li>
  1071. <p>The following instruction assigns to <code>greenContent</code> the value of the green tone that is contained in the pixel <code>(1,1)</code> of <code>originalImage</code>:</p>
  1072. <p><code>int greenContent = qGreen(originalImage.pixel(1,1));</code>.</p>
  1073. </li>
  1074. <li><p>The following program creates an object of the <code>QImage</code> class and prints the red, green and blue components of the pixel in the center of the image. The image used is the one specified within the parenthesis during the creation of the object, that is, the file <code>chuck.png</code></p></li>
  1075. </ol>
  1076. <hr>
  1077. <div class="highlight highlight-cpp"><pre>#<span class="pl-k">include</span> <span class="pl-s"><span class="pl-pds">&lt;</span>QImage<span class="pl-pds">&gt;</span></span>
  1078. #<span class="pl-k">include</span> <span class="pl-s"><span class="pl-pds">&lt;</span>iostream<span class="pl-pds">&gt;</span></span>
  1079. <span class="pl-k">using</span> <span class="pl-k">namespace</span> <span class="pl-en">std</span><span class="pl-k">;</span>
  1080. <span class="pl-k">int</span> <span class="pl-en">main</span>() {
  1081. QImage <span class="pl-smi">myImage</span>(“/Users/rarce/Downloads/chuck.<span class="pl-smi">png</span>”);
  1082. QRgb centralPixel;
  1083. centralPixel = myImage.<span class="pl-c1">pixel</span>(myImage.<span class="pl-c1">width</span>() / <span class="pl-c1">2</span>, myImage.<span class="pl-c1">height</span>() / <span class="pl-c1">2</span>);
  1084. cout &lt;&lt; hex;
  1085. cout &lt;&lt; “The red, green <span class="pl-k">and</span> blue components of the middle pixel are: “
  1086. &lt;&lt; <span class="pl-c1">qRed</span>(centralPixel) &lt;&lt; “, “
  1087. &lt;&lt; <span class="pl-c1">qGreen</span>(centralPixel) &lt;&lt; “, “
  1088. &lt;&lt; <span class="pl-c1">qBlue</span>(centralPixel) &lt;&lt; endl;
  1089. <span class="pl-k">return</span> <span class="pl-c1">0</span>;
  1090. }</pre></div>
  1091. <hr>
  1092. <h3>
  1093. <a id="user-content-measuring-similarity-of-pixel-colors" class="anchor" href="#measuring-similarity-of-pixel-colors" aria-hidden="true"><span class="octicon octicon-link"></span></a>Measuring similarity of pixel colors</h3>
  1094. <p>Look at Figure 4, although the background in <em>image A</em> looks uniform, it really includes pixels of diverse (although similar) colors.</p>
  1095. <hr>
  1096. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure5.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure5.png" alt="figure5.png" style="max-width:100%;"></a></p>
  1097. <p><strong>Figure 4</strong> - What may seem as a <em>solid</em> color, really is not. Thus, we use the color <em>distance</em>.</p>
  1098. <hr>
  1099. <p>Instead of only considering as part of the solid background the pixels whose color is <strong>exactly</strong> <code>0x00FF00</code>, we measure a color's <em>distance</em> from the <em>pure</em> color. A small <em>distance</em> means that the color is <em>almost</em> a pure green. A large <em>distance</em> means that the color is very different from green. The equation for <em>distance</em> is:</p>
  1100. <p>$$distance = \sqrt{(P_R-S_R)^2+(P_G-S_G)^2+(P_B-S_B)^2},$$</p>
  1101. <p>where $$P_R$$, $$P_G$$, and $$P_B$$ are the red, green and blue components of the pixel being considered. $$S_R$$, $$S_G$$, and $$S_B$$ are the components of the solid background, e.g. in our example $$S_R=S_B=0$$ y $$S_G=255$$.</p>
  1102. <hr>
  1103. <hr>
  1104. <h2>
  1105. <a id="user-content-laboratory-session" class="anchor" href="#laboratory-session" aria-hidden="true"><span class="octicon octicon-link"></span></a>Laboratory Session</h2>
  1106. <p>In this laboratory experience, starting with an image with an object of interest over a solid color background and an image to use as a background, you will define and implement a function that creates a third merged image where the image with the object of interest will have its background color removed and will appear over the image chosen to be the background.</p>
  1107. <p>You will be working with the <code>Filter.cpp</code> file. The following is a review of the variables in this file:</p>
  1108. <ul>
  1109. <li>objectImage: reference to the object image with the solid background</li>
  1110. <li>backgroundImage: reference to the background image object</li>
  1111. <li>mergedImage: reference to the merged image</li>
  1112. <li>threshold: is a theshold value used to compare the distances between the object pixel and the solid background pixel. In the provided code, the threshold value is read from the slideBar.</li>
  1113. <li>ghost: is a boolean value used to apply ghost filter to pixels.</li>
  1114. <li>(x, y): contains the coordinate of the pixel whose color will be used as solid background. The default value is (0,0).</li>
  1115. <li>(offset_x, offset_y): the coordinate of the merged image where the upper-left corner of the objectImage should be inserted. The default value is (0,0).</li>
  1116. </ul>
  1117. <h3>
  1118. <a id="user-content-exercise-1-create-a-composite-image" class="anchor" href="#exercise-1-create-a-composite-image" aria-hidden="true"><span class="octicon octicon-link"></span></a>Exercise 1: Create a composite image</h3>
  1119. <h4>
  1120. <a id="user-content-instructions" class="anchor" href="#instructions" aria-hidden="true"><span class="octicon octicon-link"></span></a>Instructions</h4>
  1121. <ol>
  1122. <li><p>Load the Qt project called <code>GreenScreenLab</code> by double-clicking on the <code>GreenScreenLab.pro</code> file in the <code>Documents/eip/Arrays-GreenScreen</code> folder of your computer. You may also go to <code>http://bitbucket.org/eip-uprrp/arrays-greenscreen</code> to download the <code>Arrays-GreenScreen</code> folder to your computer.</p></li>
  1123. <li>
  1124. <p>Build and run the program. The provided code creates the interface shown in Figure 5. The buttons <em>Select Image</em> and <em>Select Background Image</em> have already been programmed to perform their actions.</p>
  1125. <hr>
  1126. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure6.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure6.png" alt="figure6.png" style="max-width:100%;"></a></p>
  1127. <p><strong>Figure 5.</strong>Interface for the green screen application.</p>
  1128. <hr>
  1129. </li>
  1130. <li><p>Click the <em>Select Image</em> button to load the image that contains the solid background, the click <em>Select Background Image</em> to load the image that contains the interesting background. The folders called <code>green_background</code> and <code>landscapes</code> contain some images that are suitable as the first and second images. </p></li>
  1131. <li><p>Your first task is to complete the function <code>MergeImages</code> in file <code>Filter.cpp</code>.<code>MergeImages</code> is the function that is called when the user presses the button captioned <code>Merge Images</code> or when he slides the slide bar. The function <code>MergeImages</code> receives the image with the solid background, the background image, a reference to the merged image, a threshold value, and the coordinates <code>(x,y)</code> of the pixel from which we will extract the sample <em>green</em> background color, and the coordinates <code>(offset_x, offset_y)</code> from the merged image.</p></li>
  1132. </ol>
  1133. <p>For this first exercise you can ignore the following parameters: ghost, x_offset, y_offset. Your implementation should place the <code>objectImage</code> into the <code>mergedImage</code> starting at position (0,0).</p>
  1134. <p><strong>The algorithm</strong></p>
  1135. <ol>
  1136. <li><p>Acquire the value of the solid color. The solid color will be the color of the pixel in the coordinate <code>(x,y)</code> of the object image with the solid background. The default value for <code>(x,y)</code> is <code>(0,0)</code>.</p></li>
  1137. <li><p>For every position <code>(i,j)</code>, read the color of the corresponding pixel in the objectImage. Compute the distance of the pixel colors to the solid color. If the distance between the solid color and the color of the pixel of the image is greater than the threshold, set the corresponding <code>(i,j)</code> pixel in the merged image to the objectImage pixel color. </p></li>
  1138. </ol>
  1139. <p>Test your implementation by loading object and background images and verifying the merged image.</p>
  1140. <h2>
  1141. <a id="user-content-exercise-2-creating-a-composite-image-using-a-ghost-filter" class="anchor" href="#exercise-2-creating-a-composite-image-using-a-ghost-filter" aria-hidden="true"><span class="octicon octicon-link"></span></a>Exercise 2: Creating a composite image using a ghost filter</h2>
  1142. <p>In this exercise you will modify Exercise 1 to apply a ghost filter to each of the pixels that will be composed over the background image (if the <code>ghost</code> variable is true). The filter creates a ghost like effect on the objects composed over the background image, as in Figure 6.</p>
  1143. <hr>
  1144. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure7.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure7.png" alt="figure7.png" style="max-width:100%;"></a></p>
  1145. <p><strong>Figure 6</strong> - In this example, the dog in the image with the solid background is composed in the background image with the ghost filter. </p>
  1146. <hr>
  1147. <p>The ghost effect is achieved by <em>averaging</em> the background color with the object's color (instead of simply <em>replacing</em> the background with the object's color). The average is performed for each of the components (red, green and blue). </p>
  1148. <p>$$N_R=\frac{S_R+B_R}{2}$$
  1149. $$N_G=\frac{S_G+B_G}{2}$$
  1150. $$N_B=\frac{S_B+B_B}{2},$$</p>
  1151. <p>where $$N_R$$, $$N_G$$, and $$N_B$$ are the red, green and blue components of the new ghost pixel. $$S_R$$, $$S_G$$, and $$S_B$$ are the components of the object image. $$B_R$$, $$B_G$$, $$B_B$$ are the components of the background image. </p>
  1152. <h2>
  1153. <a id="user-content-exercise-3-create-a-composite-image-placing-the-object-in-a-specified-position" class="anchor" href="#exercise-3-create-a-composite-image-placing-the-object-in-a-specified-position" aria-hidden="true"><span class="octicon octicon-link"></span></a>Exercise 3: Create a composite image placing the object in a specified position</h2>
  1154. <p>The widget that displays the background has been programmed to register the position where the user clicks. In this exercise you will program the <code>MergeImages</code> function so that the position that user clicks in the background image is used as the <em>top left</em> corner where the <em>object</em> image will be displayed in the merged image. The following figures illustrates the effect. Note the <em>Selected Coord</em> values under the images.</p>
  1155. <hr>
  1156. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure8.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure8.png" alt="figure8.png" style="max-width:100%;"></a></p>
  1157. <p><strong>Figure 7.</strong> In this example, the background image has not been clicked. Thus the "Selected Coord" is at its default value of (0,0). The dog image is inserted with its top-left corner at (0,0) in the merged image.</p>
  1158. <hr>
  1159. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure9.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure9.png" alt="figure9.png" style="max-width:100%;"></a></p>
  1160. <p><strong>Figure 8.</strong> In this example, the background image has been clicked at coordinate <code>(827,593)</code>. The dog image is inserted with its top-left corner at <code>(827,593)</code> in the merged image.</p>
  1161. <hr>
  1162. <p>In this exercise your task will be the same as in Exercise 1, but this time you will need to offset the <em>object</em> image inside the <em>merged</em> image by the amount specified in the <code>x_offset</code> and <code>y_offset</code> parameters. Please take into consideration the merged image boundaries when you are inserting the object image. The user may specify an offset where the boundaries are exceeded and the object will be cut, as in Figure 9. </p>
  1163. <hr>
  1164. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure10.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure10.png" alt="figure10.png" style="max-width:100%;"></a></p>
  1165. <p><strong>Figure 9</strong>. In this example, the user selected a position that assigned values that are too large for <code>x_offset</code> and <code>y_offset</code>; the implementation made the adjustment so part of the dog appeared in the merged image.</p>
  1166. <hr>
  1167. <p>The example in Figure 10 shows how the object image will behave when merging it with the background image. The <code>x_offset</code> and <code>y_offset</code> variables represent the point in the background image where the upper left corner of the object image will be placed. Notice that if a point too close to the image border is chosen, part of the object image will be outside of the limits of the background image. As we have seen when manipulating arrays, if one tries to access or alter elements that are outside of the size range of the array, we get a fatal compilation error. The same thing happens with the images.</p>
  1168. <p>You should make sure that your implementation takes into account the <code>x_offset</code> and <code>y_offset</code> values so the composition does not try to access or alter pixels outside of the limits of the background image. If you try to access or alter pixels outside of these limits, it will result in a fatal error.</p>
  1169. <hr>
  1170. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure11.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Arrays/GreenScreen/greenscreen-Edited-NoSolutions-July-2015/images/figure11.png" alt="figure11.png" style="max-width:100%;"></a></p>
  1171. <p><strong>Figure 10.</strong> Illustration of the object image with pixels that are outside of the background image limits. If the possibility of this happening is not taken into account in the implementation, there will be a fatal error.</p>
  1172. <hr>
  1173. <p>Validate your implementation by choosing several offsets and observing the merged image. Be sure to try cases in which you choose x and y offsets that result in the object being cropped in the merged image (as in Figure 9).</p>
  1174. <hr>
  1175. <hr>
  1176. <h3>
  1177. <a id="user-content-deliverables" class="anchor" href="#deliverables" aria-hidden="true"><span class="octicon octicon-link"></span></a>Deliverables</h3>
  1178. <p>Use "Deliverables" in Moodle to upload the <code>filter.cpp</code> file that contains the <code>MergeImages</code> function. Remember to use good programming techniques, include the names of the programmers involved, and to document your program.</p>
  1179. <hr>
  1180. <hr>
  1181. <h3>
  1182. <a id="user-content-references" class="anchor" href="#references" aria-hidden="true"><span class="octicon octicon-link"></span></a>References</h3>
  1183. <p>[1] <a href="http://en.wikipedia.org/wiki/Green_screen_(disambiguation)">http://en.wikipedia.org/wiki/Green_screen_(disambiguation)</a></p>
  1184. <p>[2] <a href="http://en.wikipedia.org/wiki/Chroma_key">http://en.wikipedia.org/wiki/Chroma_key</a></p>
  1185. <p>[3] <a href="http://doc.qt.io/qt-4.8/qimage.html">http://doc.qt.io/qt-4.8/qimage.html</a>.</p>
  1186. </article></body></html>