€cdocutils.nodes document q)q}q(U nametypesq}q(Xoriginal implementationqNXgil implementationqNXtutorial: histogramqNUcontentsq NuUsubstitution_defsq }q Uparse_messagesq ]q Ucurrent_sourceqNU decorationqNUautofootnote_startqKUnameidsq}q(hUoriginal-implementationqhUgil-implementationqhUtutorial-histogramqh UcontentsquUchildrenq]qcdocutils.nodes section q)q}q(U rawsourceqUUparentqhUsourceqX1/root/project/libs/gil/doc/tutorial/histogram.rstqUtagnameq Usectionq!U attributesq"}q#(Udupnamesq$]Uclassesq%]Ubackrefsq&]Uidsq']q(haUnamesq)]q*hauUlineq+KUdocumentq,hh]q-(cdocutils.nodes title q.)q/}q0(hXTutorial: Histogramq1hhhhh Utitleq2h"}q3(h$]h%]h&]h']h)]uh+Kh,hh]q4cdocutils.nodes Text q5XTutorial: Histogramq6…q7}q8(hh1hh/ubaubcdocutils.nodes topic q9)q:}q;(hUhhhhh Utopicq(Ucontentsq?Ulocalq@eh&]h']qAhah)]qBh auh+Kh,hh]qCcdocutils.nodes bullet_list qD)qE}qF(hUhh:hNh U bullet_listqGh"}qH(h$]h%]h&]h']h)]uh+Nh,hh]qI(cdocutils.nodes list_item qJ)qK}qL(hUh"}qM(h$]h%]h&]h']h)]uhhEh]qNcdocutils.nodes paragraph qO)qP}qQ(hUh"}qR(h$]h%]h&]h']h)]uhhKh]qScdocutils.nodes reference qT)qU}qV(hUh"}qW(h']qXUid1qYah&]h$]h%]h)]UrefidhuhhPh]qZh5XOriginal implementationq[…q\}q](hXOriginal implementationq^hhUubah U referenceq_ubah U paragraphq`ubah U list_itemqaubhJ)qb}qc(hUh"}qd(h$]h%]h&]h']h)]uhhEh]qehO)qf}qg(hUh"}qh(h$]h%]h&]h']h)]uhhbh]qihT)qj}qk(hUh"}ql(h']qmUid2qnah&]h$]h%]h)]Urefidhuhhfh]qoh5XGIL implementationqp…qq}qr(hXGIL implementationqshhjubah h_ubah h`ubah haubeubaubhO)qt}qu(hXÂThis is a short tutorial presenting an example of a very simple sample of code from an existing code base that calculates histogram of an image. Next, the program is rewritten using GIL featres.qvhhhhh h`h"}qw(h$]h%]h&]h']h)]uh+Kh,hh]qxh5XÂThis is a short tutorial presenting an example of a very simple sample of code from an existing code base that calculates histogram of an image. Next, the program is rewritten using GIL featres.qy…qz}q{(hhvhhtubaubh)q|}q}(hUhhhhh h!h"}q~(h$]h%]h&]h']qhah)]q€hauh+K h,hh]q(h.)q‚}qƒ(hh^hh|hhh h2h"}q„(h']h&]h$]h%]h)]Urefidq…hYuh+K h,hh]q†h5XOriginal implementationq‡…qˆ}q‰(hh^hh‚ubaubhO)qŠ}q‹(hX•Actual code from a commercial software product that computes the luminosity histogram (variable names have been changed and unrelated parts removed):qŒhh|hhh h`h"}q(h$]h%]h&]h']h)]uh+Kh,hh]qŽh5X•Actual code from a commercial software product that computes the luminosity histogram (variable names have been changed and unrelated parts removed):q…q}q‘(hhŒhhŠubaubcdocutils.nodes literal_block q’)q“}q”(hXºvoid luminosity_hist( std::uint8_t const* r, std::uint8_t const* g, std::uint8_t const* b, int rows, int cols, int sRowBytes, Histogram* hist) { for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { int v = RGBToGray(r[c], g[c], b[c]); // call internal function or macro (*hist)[v]++; } r += sRowBytes; g += sRowBytes; b += sRowBytes; } }hh|hhh U literal_blockq•h"}q–(Ulinenosq—‰Ulanguageq˜XcppU xml:spaceq™Upreserveqšh']h&]h$]Uhighlight_argsq›}h%]h)]uh+Kh,hh]qœh5Xºvoid luminosity_hist( std::uint8_t const* r, std::uint8_t const* g, std::uint8_t const* b, int rows, int cols, int sRowBytes, Histogram* hist) { for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { int v = RGBToGray(r[c], g[c], b[c]); // call internal function or macro (*hist)[v]++; } r += sRowBytes; g += sRowBytes; b += sRowBytes; } }q…qž}qŸ(hUhh“ubaubhO)q }q¡(hX@Let's consider the following issues of the implementation above:q¢hh|hhh h`h"}q£(h$]h%]h&]h']h)]uh+K%h,hh]q¤h5X@Let's consider the following issues of the implementation above:q¥…q¦}q§(hh¢hh ubaubhD)q¨}q©(hUhh|hhh hGh"}qª(Ubulletq«X-h']h&]h$]h%]h)]uh+K'h,hh]q¬(hJ)q­}q®(hXDWorks only for RGB (duplicate versions exist for other color spaces)q¯hh¨hhh hah"}q°(h$]h%]h&]h']h)]uh+Nh,hh]q±hO)q²}q³(hh¯hh­hhh h`h"}q´(h$]h%]h&]h']h)]uh+K'h]qµh5XDWorks only for RGB (duplicate versions exist for other color spaces)q¶…q·}q¸(hh¯hh²ubaubaubhJ)q¹}qº(hX6Works only for 8-bit images (duplicate versions exist)q»hh¨hhh hah"}q¼(h$]h%]h&]h']h)]uh+Nh,hh]q½hO)q¾}q¿(hh»hh¹hhh h`h"}qÀ(h$]h%]h&]h']h)]uh+K(h]qÁh5X6Works only for 8-bit images (duplicate versions exist)qÂ…qÃ}qÄ(hh»hh¾ubaubaubhJ)qÅ}qÆ(hXWorks only for planar images hh¨hhh hah"}qÇ(h$]h%]h&]h']h)]uh+Nh,hh]qÈhO)qÉ}qÊ(hXWorks only for planar imagesqËhhÅhhh h`h"}qÌ(h$]h%]h&]h']h)]uh+K)h]qÍh5XWorks only for planar imagesqÎ…qÏ}qÐ(hhËhhÉubaubaubeubeubh)qÑ}qÒ(hUhhhhh h!h"}qÓ(h$]h%]h&]h']qÔhah)]qÕhauh+K,h,hh]qÖ(h.)q×}qØ(hhshhÑhhh h2h"}qÙ(h']h&]h$]h%]h)]h…hnuh+K,h,hh]qÚh5XGIL implementationqÛ…qÜ}qÝ(hhshh×ubaubh’)qÞ}qß(hX[template void grayimage_histogram(GrayView& img, R& hist) { for (typename GrayView::iterator it=img.begin(); it!=img.end(); ++it) ++hist[*it]; } template void luminosity8bit_hist(View& img, R& hist) { grayimage_histogram(color_converted_view(img),hist); }hhÑhhh h•h"}qà(h—‰h˜Xcpph™hšh']h&]h$]h›}h%]h)]uh+K.h,hh]qáh5X[template void grayimage_histogram(GrayView& img, R& hist) { for (typename GrayView::iterator it=img.begin(); it!=img.end(); ++it) ++hist[*it]; } template void luminosity8bit_hist(View& img, R& hist) { grayimage_histogram(color_converted_view(img),hist); }qâ…qã}qä(hUhhÞubaubhO)qå}qæ(hXVUsing the Boost.Lambda library (or C++11 lambda) features it can written even simpler:qçhhÑhhh h`h"}qè(h$]h%]h&]h']h)]uh+K=h,hh]qéh5XVUsing the Boost.Lambda library (or C++11 lambda) features it can written even simpler:qê…që}qì(hhçhhåubaubh’)qí}qî(hXusing boost::lambda; template void grayimage_histogram(GrayView& img, R& hist) { for_each_pixel(img, ++var(hist)[_1]); }hhÑhhh h•h"}qï(h—‰h˜Xcpph™hšh']h&]h$]h›}h%]h)]uh+K@h,hh]qðh5Xusing boost::lambda; template void grayimage_histogram(GrayView& img, R& hist) { for_each_pixel(img, ++var(hist)[_1]); }qñ…qò}qó(hUhhíubaubhO)qô}qõ(hX;Let's consider the following advantages of the GIL version:qöhhÑhhh h`h"}q÷(h$]h%]h&]h']h)]uh+KJh,hh]qøh5X;Let's consider the following advantages of the GIL version:qù…qú}qû(hhöhhôubaubhD)qü}qý(hUhhÑhhh hGh"}qþ(h«X-h']h&]h$]h%]h)]uh+KLh,hh]qÿ(hJ)r}r(hXmWorks with any supported channel depth, color space, channel ordering (RGB vs BGR), and row alignment policy.hhühhh hah"}r(h$]h%]h&]h']h)]uh+Nh,hh]rhO)r}r(hXmWorks with any supported channel depth, color space, channel ordering (RGB vs BGR), and row alignment policy.rhjhhh h`h"}r(h$]h%]h&]h']h)]uh+KLh]rh5XmWorks with any supported channel depth, color space, channel ordering (RGB vs BGR), and row alignment policy.r …r }r (hjhjubaubaubhJ)r }r (hX-Works for both planar and interleaved images.rhhühhh hah"}r(h$]h%]h&]h']h)]uh+Nh,hh]rhO)r}r(hjhj hhh h`h"}r(h$]h%]h&]h']h)]uh+KNh]rh5X-Works for both planar and interleaved images.r…r}r(hjhjubaubaubhJ)r}r(hXlWorks with new color spaces, channel depths and image types that can be provided in future extensions of GILhhühhh hah"}r(h$]h%]h&]h']h)]uh+Nh,hh]rhO)r}r(hXlWorks with new color spaces, channel depths and image types that can be provided in future extensions of GILrhjhhh h`h"}r(h$]h%]h&]h']h)]uh+KOh]r h5XlWorks with new color spaces, channel depths and image types that can be provided in future extensions of GILr!…r"}r#(hjhjubaubaubhJ)r$}r%(hX=The second version is as efficient as the hand-coded version hhühhh hah"}r&(h$]h%]h&]h']h)]uh+Nh,hh]r'hO)r(}r)(hX<The second version is as efficient as the hand-coded versionr*hj$hhh h`h"}r+(h$]h%]h&]h']h)]uh+KQh]r,h5X<The second version is as efficient as the hand-coded versionr-…r.}r/(hj*hj(ubaubaubeubhO)r0}r1(hX"Shortly, it is also very flexible.r2hhÑhhh h`h"}r3(h$]h%]h&]h']h)]uh+KSh,hh]r4h5X"Shortly, it is also very flexible.r5…r6}r7(hj2hj0ubaubhO)r8}r9(hX‹For example, to compute the histogram of the second channel of the top left quadrant of the image, taking every other row and column, call:r:hhÑhhh h`h"}r;(h$]h%]h&]h']h)]uh+KUh,hh]r<h5X‹For example, to compute the histogram of the second channel of the top left quadrant of the image, taking every other row and column, call:r=…r>}r?(hj:hj8ubaubh’)r@}rA(hXxgrayimage_histogram( nth_channel_view( subsampled_view( subimage_view(img, 0,0, img.width() / 2, img.height() / 2), // upper left quadrant 2, 2 // skip every other row and column ), 1 // index of the second channel (for example, green for RGB) ), hist );hhÑhhh h•h"}rB(h—‰h˜Xcpph™hšh']h&]h$]h›}h%]h)]uh+KXh,hh]rCh5Xxgrayimage_histogram( nth_channel_view( subsampled_view( subimage_view(img, 0,0, img.width() / 2, img.height() / 2), // upper left quadrant 2, 2 // skip every other row and column ), 1 // index of the second channel (for example, green for RGB) ), hist );rD…rE}rF(hUhj@ubaubhO)rG}rH(hXzSince GIL operates on the source pixels of ``img`` object directly, no extra memory is allocated and no images are copied.hhÑhhh h`h"}rI(h$]h%]h&]h']h)]uh+Kfh,hh]rJ(h5X+Since GIL operates on the source pixels of rK…rL}rM(hX+Since GIL operates on the source pixels of hjGubcdocutils.nodes literal rN)rO}rP(hX``img``h"}rQ(h$]h%]h&]h']h)]uhjGh]rRh5XimgrS…rT}rU(hUhjOubah UliteralrVubh5XH object directly, no extra memory is allocated and no images are copied.rW…rX}rY(hXH object directly, no extra memory is allocated and no images are copied.hjGubeubeubeubahUU transformerrZNU footnote_refsr[}r\Urefnamesr]}r^Usymbol_footnotesr_]r`Uautofootnote_refsra]rbUsymbol_footnote_refsrc]rdU citationsre]rfh,hU current_linergNUtransform_messagesrh]riUreporterrjNUid_startrkKU autofootnotesrl]rmU citation_refsrn}roUindirect_targetsrp]rqUsettingsrr(cdocutils.frontend Values rsort}ru(Ufootnote_backlinksrvKUrecord_dependenciesrwNU rfc_base_urlrxUhttps://tools.ietf.org/html/ryU tracebackrzˆUpep_referencesr{NUstrip_commentsr|NU toc_backlinksr}Uentryr~U language_coderUenr€U datestamprNU report_levelr‚KU _destinationrƒNU halt_levelr„KU strip_classesr…Nh2NUerror_encoding_error_handlerr†Ubackslashreplacer‡UdebugrˆNUembed_stylesheetr‰‰Uoutput_encoding_error_handlerrŠUstrictr‹U sectnum_xformrŒKUdump_transformsrNU docinfo_xformrŽKUwarning_streamrNUpep_file_url_templaterUpep-%04dr‘Uexit_status_levelr’KUconfigr“NUstrict_visitorr”NUcloak_email_addressesr•ˆUtrim_footnote_reference_spacer–‰Uenvr—NUdump_pseudo_xmlr˜NUexpose_internalsr™NUsectsubtitle_xformrš‰U source_linkr›NUrfc_referencesrœNUoutput_encodingrUutf-8ržU source_urlrŸNUinput_encodingr U utf-8-sigr¡U_disable_configr¢NU id_prefixr£UU tab_widthr¤KUerror_encodingr¥Uasciir¦U_sourcer§hUgettext_compactr¨ˆU generatorr©NUdump_internalsrªNU smart_quotesr«‰U pep_base_urlr¬U https://www.python.org/dev/peps/r­Usyntax_highlightr®Ulongr¯Uinput_encoding_error_handlerr°j‹Uauto_id_prefixr±Uidr²Udoctitle_xformr³‰Ustrip_elements_with_classesr´NU _config_filesrµ]Ufile_insertion_enabledr¶ˆU raw_enabledr·KU dump_settingsr¸NubUsymbol_footnote_startr¹KUidsrº}r»(hhhnhjhYhUhh|hhÑhh:uUsubstitution_namesr¼}r½h h,h"}r¾(h$]h']h&]Usourcehh%]h)]uU footnotesr¿]rÀUrefidsrÁ}rÂub.