Volume 0 (1981), Number 0 pp. 1–11 GRAPHICS forum

Fast Rendering of Image Mosaics and ASCII Art

Nenad Markuš1, Marco Fratarcangeli2, Igor S. Pandžic´1 and Jörgen Ahlberg3

1University of Zagreb, Faculty of Electrical Engineering and Computing, Unska 3, 10000 Zagreb, Croatia 2Chalmers University of Technology, Dept. of Applied IT, Kuggen, Lindholmsplatsen 1, SE-412 96 Göteborg, Sweden 3Linköping University, Dept. of Electrical Engineering, Information Coding Group, SE-581 83 Linköping, Sweden

[email protected], [email protected], [email protected], [email protected]

__/[(\;r'!IfJtLL3i}7/_\\r[((}j11](j3ltlljj{7j]_j_\3nu&j__\_!/\/_|_(_,_7&Url37r|v/=<>_ ___<|\;"__3fJtCv3C<>__<|r]c7r71]](j3jtCljjC7js_[/__7\_ __{_}="__<4@nYl03jrr><<\_\7?csC*(j33tJo~C7Cj[*C_(c/lVTfr_^^^^r_}!"__<<\)77>csC*Cj33Jjov7oCr7_^^^^~!_"~_~\4FfGvtJCr{/{/<_ss(r]vCCoLjLLjtj_j*jjscrs*jJT@j_-`:__=/\<<}],-"Ij0isc_=_jyQd _\__r"~_~\3kfLovJjr\<||>rs*_j(jv*vCjLtjtj(j7jjr]r]*jJT@j!-.-_^__\\=="_!=`(5PfJ*tj*r_|<\<7r,."YLjjr/_aED^k !_=="__="/4PfJotjvrr_x#E%k ^;"___+_r<4Pfv0tvCrvrrc<*1(_C*ijoLI9AaTazjjovj*ri}i3evTjr____~_=_\\]j3r,~`YejrjdbUU%b !_^"_____\4yfLYtllr_rrr[*7*jCjjjvLYfAaT&Ljjjji*rr*r3vefjr__;__!=_+/_*vr,``YLjrj#bUx%m _="_jr-^,\5kaf>rC}**_e_jr/rr=_^^^.`70jjjjjefuAtr?(/__=_)r**o*i*_,/`mHP%ky%yE ="_jer"-~\5yfLLojr|({)>>rrj*7Cesj>_/r_<^__^_^aYjojvz6uft/=/___=_?rj*o3**_,`_p#%wUyky# "_(yf{-^~<5EhfYtj1r(7*3vvoeJJvjjrr___;--_:7Yunj_VA$tr-=\___<7r7*17<(?,_xK#ULP%dPy `_sxf_^^-_5#@9VYCjc(s7_zafnftjYJfrcr;"~"__~-^^*&aaaTt_-^^sjr_.:<?juejYjV5YSuvt*__;_~^"^..,,*y&@ht=_"^{>rj=`-`_--_,.,7kyFt__:_!_VVtuufCVl`Cve*_sr`--_,-_,'.\%y&t__:^_sr=oBTUayTwPwt\_"- hdLEt+,__<3b@Ltjr_c}<"34nYIloC13Cj&A7",-,^`-,__,--",'/8fr___(xBgmr"^^o#yFFTkFlyt_>"__ ykdmtr,___3phLtj*jr"_,-^,_--",,^o]|(uY_,",,.'__~_=__/_~,____,j*!,=",,-,'`_c^_|"~=|\__\r_~__|~_j>_-"_,_-,__,_4yydy%f\["_==~_= %yDPfr,__<4kfJlrulvI:`!7U&\Y_>3C_)\<)/_!=_<>jc>_\__[jc{~^"_~~-""_/_=_#PDEyTr/+__,._\_ %yyyt>-___3EV0vovvv$..=jC\___=_QPyEmTr/=___^;^= p%DFtr~-_<3yutLjlv3J'`^/3$7_\C?_jr\r.<<(jj*]*]cj3tj*)="_~="""""_/>j=@#PPThr|r_~_;_+_! y%DFtr"`-\3yutoCoeIt',^=ux*__o__j*[r__+jjj*7*]c_otj*r/"_~!^"":`_7^-.<5#&uJt_vut``~_=`-^"":""^`_(eY=_WybkPC(r~~=__~_<| d%Fhtr,-,<3p&jSjvjuf``^_\j_vr/jsr(_)*Ija/3tejauyars=`-^_".""^`_jeY=~=^~~/!\/+ ZTTAt>,::_3#hzJtCvST_^`=_S\_*/_r_Vja$wphLPTy#PLr_=___,--_jet*7\=_y#ky#U@r/""^!_+/r/|< 4VThtr,`._3p@jYt*vl8,,`=_t\_*<_r_ 9OAytr,."<3#wZYv3vi3L,"`*/eafy@dFwdxwUO*"__>_r=_;__~DujJ|=_aQE%T#bPjj=-:~~_^_==\| fAUdnr,`-~3pke0ttC]73]`v_sr_+__eaf4DLfdywk8LC_~_r+,;^"""3AxjroQQbPPdyyfvr~_^~~~_r~/") f8Tdnr___~3KFe0Lli*7vl`u<_____`s fuTyf_,`'^3Ehtjr3v~r?7,=s?_j$%FEP#ywIfT@_"^<;__j*\"`,``.`3ByrudDUadEyt<"^\\\|______> nVTTfr,`.~3yftjrsrr=++|~__!,,`...~\ugj7P@fdd_F~r__^`"=7*lvojjj nV@Tfr,``^3yftji3r>=<+_\;_,``^_\jjenVt7\ zLydkr,'`<<@trr`_on#Fr_4VC+_3yd/dP/"`sLr!==?7?"\fIj,`"?7C\UyT,3F#dt7"~_=\<<_>vua*^"-~ juTd&r,'`_=*3u\8r3whAD8%~/dgr"_@Ftr>>!;-___(jzt;,`_!;.___vjvt;,_^_/____~_3LVf_,^~_<3bIdruDQr|-___\/73vYr_;=`,,, TTkWPr,,,~egr""3QQ3trr+___~_<4tjjr,:~<(WEud@^T@\"__+_>/jver__^,",,- u$TPt=,.``pr%f4Y7__mFEy3rrr___~;_/7YI*=`:_{dBPJTE,ut=_==___73jJ=_"-_:,-- uaxPj_".,^<2j"=`,<_/uH#VSAqr1r=^~\|"_,___4ppIIjq_lr!_~_),-,`<9\=(f4UU7*Yi_9\`_/\dhBPyKjjr!__^!jjjjjj___r\ByDY3TBr7\,~\!___,-,,``dmqUr_>|__?*rr7"`-_vFf0\Jt &j=7Et,',_=lQpt&yrfq$jY*__,"Lrghuqky#f___,",,,`#_q?7*j7"`._uhfYjzt gt,|___,,,',^gW___/__r_]7""``__fJ*\Vlv Rt,*r,,``_<\==,,__|iCot\3o/ gy__df;.,^_3bEfaF0@@UUujt_^r=\_Fyw#tr_3t=!_\r|_~,`^'^TttjEyyqmfr__yr~___/_Cvjsjr/||__:--'_y*^=\~|<773httjjjr|__,,,V%FPEWRRy"`"__w%UC_jCr3q #E>,3f_-,`<3@d%akF9uhwE@_`|7mwyQ#f*>|y*"=_~_>7\S3tjjvjr___-,,,#FFEWRgy"`,,_y%xC_jj=3W yfr,7f;_''|(byPUF&tfTFVnf>_7*3l0JJCvs(r_,,'_myUTTTV__xP%FCjxf=^(#y _yt`^Sr"''3TPPuVuPv8|3j8jv_vmEFt7\{"__^__=_//>r\j*330lji*}+-,,,4EfeYCv307If\awT=__wqg #yt`^fr''^3xyPafn%3f|3j5j*_aqyFt7?_^__!__r_/_>_7]*330ljcj\_",,,4pAf*CC3S7IToa@F=`_yqW

Figure 1: From left to right, the Lenna image rendered in ASCII art with the SSIM-based mapping [WBSS04] and our decision tree-based approach. Our approach reproduces the same visual results enhancing the performance of two orders of magnitude.

Abstract An image mosaic is an assembly of a large number of small images, usually called tiles, taken from a specific dictionary/codebook. When viewed as a whole, the appearance of a single large image emerges, i.e., each tile approximates a small block of pixels. ASCII art is a related (and older) graphic design technique for producing images from printable characters. Although automatic procedures for both of these visualization schemes have been studied in the past, some are computationally heavy and cannot offer real-time and interactive performance. We propose an algorithm able to reproduce the quality of existing non-photorealistic rendering techniques, in particular ASCII art and image mosaics, obtaining large performance speed-ups. The basic idea is to partition the input image into a rectangular grid and use a decision tree to assign a tile from a predetermined codebook to each cell. Our implementation can process video streams from webcams in real-time and it is suitable for modestly equipped devices. We evaluate our technique by generating the renderings of a variety of images and videos, with good results. The source code of our engine is publicly available.

Keywords: ASCII art, image mosaics, decision trees, SSIM

ACM CSS: Rendering [Computer Graphics]: Non-photorealistic rendering

1. Introduction and unrelated features of the individual tiles into a coher- ent larger framework. Besides having aesthetic value, image As pointed out by Tran [Tra99], a good image mosaic is mosaics have been investigated in the context of copyrighted striking because it cleverly puts together otherwise ordinary

c 2015 The Author(s) Computer Graphics Forum c 2015 The Eurographics Association and John Wiley & Sons Ltd. Published by John Wiley & Sons Ltd. N. Markuš, M. Fratarcangeli, I. S. Pandži´cand J. Ahlberg / Fast Rendering of Image Mosaics and ASCII Art

_,,_,_,,,______, __@*\??*@_._,?:___, ist tools which simplify the process [MJN11] or convert ^" ^^~_r\~;_\~!:;""=~rV>+>!;;^/7S~, ~_3>^__~\,_\_+/+~4==.____-_-,,&, rr>\|7vr^<<\[~+_::@r/\ _^v;!)\_|>++\_*_Chyr\_j~c*V*3_vj*7`,,'u.'"^,^--`*r/Uj*LnzTA#V_s=__-^._`"`^>cr=___;_^.~_,``^VtA&Jvj>::^~~;:/L ically generate ASCII art is to subdivide the image into a 3_/j_]zO$ynFy/^-,-""`~^``^--`>ij>__--^^"`'',(j4fG_\_=;==~~-/s, =,^vr_7la4nyao*vt,^,~`-_:.'^``^^~.'`?s_{!^_=--.^\?6rVGzV*`,,..`c"_,-_~_~_^,,,,--"",-^cj_",,`,"'\j/htr\\_~"\____. rectangular grid and replace each cell with a glyph in <3~_\_"_{;;;^^__;^,._,-^s_-:.-,-`7L*yn1_(\_^r=\,, ;++[*ijIaut_\\~~_,~"<<_!(___+^__^_~_;=-':`^;"^7r~;-,,/"^"7x@nU_Y__-;,Fj 0r_\vt8Oat~_~_^=:__r|_\)<\!^_<____+[_,~!_,7*ayuers<7l1, such a way that the average grey level stays approximately 5)jiCYVeTt_,^+='=<\rss[\r\<___)_?<{__~z%aTuznIjc?\|__"~=_,_~.,/*u<~(~jTC |Stlnv5C/v[Gr^<=_~>7\v*_oajawTThFOeeoSYTTw%%ukZvjor7n<__."__;_.-C*_["{7_J\w%konvvCzC7l\^_/77CT%dVVVtwU*C\7e,\!!""-:Ttj[(7,d, the same. A representative system that uses this technique $nhyr+~,=Vr_=_=:=\/\_-`\\YwU@fr^,-(3_-"__`.vTwjl)"|3, CYF@!=<)<*_r>**<_/_jUt3slC!+?r<<7_\/^;__~r;".-^=Ikur`",^_n|:,-""jhaA__-_s, $Dr+~~(((/:^!_(_3_LDo9<~~~~+?+s_;^~__;/e__~!;~"':/@_"`-"_0f_:'")At5fc)<(C, *r_^_\(j!=.>/\<_(oFU"^"^==?7*_a@L[>!;^,fL~cr?lsl>_^e,~-,",/r^')_C/_/OV3AC. is AAlib [aal], written in the 1990s. It relies on precom- _:-)7r(j:!;<(rj\(*`r""'"`~-`^3Ol6OL__s,Is_{C3?uYvi\3_`-'`^:3\}V]\)>\*C_ puted lookup tables and is able to produce visually appealing _[r:_,_//c>3_:_/__/3yvJ.`^`-vnI)c)s{?[_*_, ~Fm__//{\_/*7j_^_]_/P@V,`^,-_`*t//_>)/:~t, _<7SZjoocllF4,-^_7_{{>r\\m(,r---,<(9*)_-!-~",<, results in real-time. Another interesting approach has been ^Tr_==/=~_/r[cj(/I7I,._,<^,,_nn>_4&vC7OnT_^,'`+7j___/uh+_r.,`,3LS)=/'":`":~<{ l~~/+~\!crr{~\7v7d_~,,,r)I!^`v"~^"7$0j=,-^,~3_/3/@r.}'.,''A6c~"__,^^:`,_|, J_~<(_\\<*j~>j>_rjI,^_,,^ve{;,~;)"__/<~<2r_.``"-~<3F\\"^',._hur_~__-,,",,^/@ described by O’Grady and Rickard [OR08]. They treat the rj,=\r_\+(>|+\[\~//*,"7>ojc)?;/_"_/_<;_;t_?+-.,^~@r_r,,-__4fYo_/_]_'_::~.^l ^[_=~^_[_\<)~\\~;_ss0_-:^/Cvj~=!_r-^r-:=,-/>Ci__jxf`6_-_j@FC_t_r_(r_____~^^] ){,_v?^`\7\_[_,|:~cI"{'``<_]__=~-,-:""-",,'""'`vf"_t*F_TjaeYv?_+~__^!/>(_"e conversion of binary images to ASCII art as an optimization '`l\_=-_~=_\*j_>_/_cnUL,^-Vo_|_"_-^,:._"^_;._rer',8<\\Pv$Jur[r3j-:-~:_7~/cL ^t',-_!~!_r/[?<_\iv$0Uhr_lJolj_/^,^___,^__ov?"..3r'!@DOu9es/o\CYr~_~^~^_,y <7<-^_<__C{<>_~jJ=?=/rs_l factorization techniques [LS99] to solve it. The approach has /"^>_^^__il_jr!=\>=SS_r_;`.,"'.,,'`"~\,'_`,__Pt=_^^/_[sj<**_"^:"_r",',.)Te_^,7\0C~!^;"}Tt7wEEF""``"`'`" limited applications due to the considerable processing time ~_^-~"AjVL___J>~+=^_xC" needed for a single image. Inspired by the techniques for *S{_*_!;~~_r+||?/!r>/|r!^!;_^_f* :, -^^9r+-_\jL=|!__<

c 2015 The Author(s) Computer Graphics Forum c 2015 The Eurographics Association and John Wiley & Sons Ltd. N. Markuš, M. Fratarcangeli, I. S. Pandži´cand J. Ahlberg / Fast Rendering of Image Mosaics and ASCII Art

D00 D10 D11 L "5" "a" "L" "*"

Figure 3: ASCII art rendering example. The input grayscale image is partitioned into a rectangular grid (left) and each cell is passed through a decision tree (middle) in order to replace it with an ASCII glyph (right). The decisions in internal tree nodes, Di j, are obtained by comparing the intensity of a pixel at a predetermined location with a threshold.

served that the approach of Kang et al. [KSRY13] provides similar to it, as measured by the SSIM index. To obtain the the best tradeoff between image mosaic quality and speed, SSIM index between two arrays of pixels (a grid cell and a thus, we use it as a baseline for comparison. The aforemen- font glyph in our case), we first compute luminance, contrast tioned approaches require the search of the whole codebook and structure similarities: for the best matching tile, and this demands large computa- ( 1, if µ and µ are 0 tional resources (the search complexity is linear in the size 1 2 L12 = 2µ1µ2 2 2 , otherwise of the codebook). This issue has been addressed by Choi et µ1+µ2 al. [CJKK13] and Kang et al. [KSRY11]: they report real- time performance by optimizing the tile set and taking ad- ( 1, if σ1 and σ2 are 0 vantage of GPU acceleration. Another interesting approach C12 = 2σ1σ2 2 2 , otherwise to speed up the database search has been proposed by Blasi σ1+σ2 and Petralia [BP05]. The idea is to build an antipole tree ∗ ( data structure [CFP 05] prior to rendering. This enables fast 1, if σ1 is 0 or σ2 is 0 approximate nearest neighbour search in feature space ex- S12 = 2 σ12 , otherwise tracted from grid cells, which is then exploited during ren- σ1σ2 dering. We discuss the main differences with respect to our 2 where µ1 and µ2 are the pixel mean values of the arrays, σ1 approach at the end of Section 3.2. 2 2 and σ2 are their variances, and σ12 is their correlation. The SSIM index is computed as 3. Method l c s SSIM12 = L12C12S12, (1) We subdivide the image into a rectangular grid and map each where exponents l, c and s are parameters used to adjust the cell to a tile image from our codebook (a font glyph, for ex- relative importance of each component. The downside of this ample). The visual outcome of the process depends on this approach is its computational load: it requires a loop over all mapping. In the simplest case, the mapping assigns a tile 2 font glyphs for each grid cell to compute σ12. based on its mean intensity or color value. This can lead to an unnecessary loss of image detail. A more sophisticated In the case of color images, we take into account the spa- approach is to base the mapping on a correlation measure tial distribution of color to increase the sharpness of gen- that takes the spatial distribution of pixels into account (i.e., erated image mosaics. This is achieved by subdividing the the structure of the underlying region). Our method is inde- current image region into n×n subregions, calculating aver- pendent of the correlation measure and it is useful for im- age color within each of them and concatenating all values proving the speed of the process. We first describe particular into a vector. This vector serves as a region descriptor. The correlation measures which will be used in this paper (Sec- spatial color similarity (SCSIM) between an image region tion 3.1) and then introduce a machine learning technique to (represented by r) and a tile from a codebook (represented approximate them (Section 3.2). by t) is calculated as ( 1, if r and t are 0 SCSIM = 2rT t (2) 3.1. The structural similarity mapping rT r+tT t , otherwise To demonstrate our approach for ASCII rendering of We empirically found that this simple similarity measure grayscale images, we employ a measure of structural sim- gives good results in practice. In particular, the generated ilarity (SSIM) introduced by Wang et al. [WBSS04]. Each image mosaics are qualitatively similar to the ones generated region of the image is assigned a font glyph that is most with other similar methods [Tra99, ZNZ03].

c 2015 The Author(s) Computer Graphics Forum c 2015 The Eurographics Association and John Wiley & Sons Ltd. N. Markuš, M. Fratarcangeli, I. S. Pandži´cand J. Ahlberg / Fast Rendering of Image Mosaics and ASCII Art

There are a number of other similarity measures that each of these two partitions. As the set of all pixel inten- would also work, like the ones based on color correlo- sity comparisons is prohibitively large, we generate only a grams, commonly used in content-based image retrieval, small subset during optimization of each internal node by e.g., [HKM∗97]. Once the region color descriptor has been randomly selecting a number of (x,y,c,t) quadruplets. The computed, it has to be compared with all the descriptors in test that achieves the smallest entropy according to equation the database to find the best matching tile. This is computa- 3 is selected. The training data is recursively clustered in this tionally heavy and, thus, not suitable for some applications, way until at least one termination condition is met. In our like real-time rendering of image mosaics. Approximations setup, we limit the depth of the tree to reduce training time, are required to make the approach feasible. runtime processing speed and memory requirements. Each leaf node contains a tile label which was the most frequent We solve this problem by using a machine learning tech- of the ones arriving there during the learning process. nique which is specifically designed to extract correlations from large quantities of data. We treat the tile assignment For a tree of depth equal to D, the required memory is Θ(2D) step as a classification task which we solve using an opti- and the time needed to transform an image region into a tile mized binary decision tree. This was inspired by the work is Θ(D). done by Rosten et al. [RPD10] in the field of corner detec- Our approach shares some similarities with the tree- tion, which is an important problem in computer vision. structured vector quantization technique (TSVQ) [GG92]. As the main goal of TSVQ is signal compression, the code- book is not given in advance like in our case (ASCII glyphs 3.2. Approximating the mapping with a decision tree or image tiles) but is constructed during the learning pro- Decision trees are tools for function approximation cess. Another difference is in the binary tests used in inter- [HTF09]. The basic idea is to split recursively the original nal nodes of the tree. In the TSVQ case, each internal node problem into two simpler ones, each solvable by a model stores two prototype vectors with which the incoming sam- of reduced complexity. The splits are performed at internal ple is compared. The nearest (minimum distortion) one de- nodes of the tree, based on problem-specific binary tests. termines in which of the subtrees the search has to continue. Leaf nodes contain simple models that approximate the de- A similar structure known as the antipole tree [CFP∗05] sired output. We treat the tree construction process as a su- has beed used by Blasi and Petralia [BP05] to speed up pervised learning problem. We choose the binary tests in in- the database search when rendering image mosaics. This ternal nodes and output models at leaf nodes based on a finite approach and TSVQ are both based on codebook cluster- set of input-output pairs in a training set. ing while our method relies on approximating the similarity measure by learning a discriminative classifier from training In our case, the internal nodes of the tree employ simple bi- data. Thus, neither TSVQ nor [BP05] can be directly applied nary tests which are defined for an image region R as to ASCII art rendering based on the SSIM mapping (Sec- ( tion 3.1) as these methods require feature vector (descrip- 0, Rx,y,c ≤ t bintest(R;x,y,c,t) = tor) extraction from each grid cell. This gives our method 1, otherwise more flexibility, since similarity measures can be easily con- where Rx,y,c is the pixel intensity sampled from color chan- structed from feature vectors whereas the converse is not nel c at location specified by x and y, and t is the threshold true. associated with the test. Each leaf node of the tree contains a label that represents a specific tile. 4. Experimental analysis The construction of the tree is supervised. For ex- To show how our framework performs for grayscale images, ample, in the case of ASCII rendering, the training we use it to render ASCII art. We use a font with glyph size data is a set {(Rs,gs) : s = 1,2,...,S} where gs ∈ equal to 10 × 6 pixels. The implemented renderer replaces {!, ",..., a, b, c,..., A, B, C,..., ~} is the ground truth image regions with glyphs by finding the best match accord- glyph label associated with image region Rs. The binary test ing to Equation1. In our experiments, we set the exponents in each internal node of the tree is selected in a way to mini- to l = 10, c = 0.1 and s = 0.1. We experimentally found mize the average entropy obtained when the incoming train- that these adequately weight the contribution of the region ing data is split by the test. The average entropy is computed structure content when selecting an appropriate glyph and as lead to visually appealing results. To show how our frame- work works for color images, we render image mosaics us- H = p0H0 + p1H1, (3) ing 1500 flower tiles (15 × 15 resolution). Some examples where p0 and p1 are fractions of training samples for which from the flower tile codebook can be seen in Figure4. Image the results of a binary test on an associated region were 0 mosaics are generated by finding the best match for each im- and 1, respectively. Values H0 and H1 are the entropies com- age region according to Equation2. We set n = 3, i.e., our puted from the distributions of ground truth labels within renderer subdivides each region/tile into 3 × 3 blocks when

c 2015 The Author(s) Computer Graphics Forum c 2015 The Eurographics Association and John Wiley & Sons Ltd. N. Markuš, M. Fratarcangeli, I. S. Pandži´cand J. Ahlberg / Fast Rendering of Image Mosaics and ASCII Art

1.0

0.8

Figure 4: Some example tiles from the flower codebook used in our experiments. 0.6

0.4 SSIM Fraction of samples computing its descriptor. This value provides a good tradeoff Tree, d =20 between retrieval speed and spatial color matching accuracy. Tree, d =16 0.2 Tree, d =12 As we demand real-time performance on hardware with lim- Tree, d =8 ited computational resources, we use a decision tree to map a Luminance tile to each image region. Learning of the tree is described in 0.0 0.40 0.45 0.50 0.55 0.60 Section 4.1. Section 4.2 demonstrates some results on real- DSSIM world images. Section 4.3 discusses processing speed advan- tages. Figure 5: Cumulative error distributions for different meth- ods on a validation set (10 5 Mpixel images). The error is defined as DSSIM = (1 − SSIM)/2. 4.1. Learning step

To generate the training set, we render 200 5 Mpixel images 95% confidence Mean Standard of "natural" scenes (flowers, landscapes, sky, etc.) by sub- Method interval for µ score µ deviation µ − δ µ + δ dividing each of them into a rectangular grid and assigning Luminance-based 4.51 2.10 4.29 4.74 each cell a tile image by directly optimizing the criterion de- SSIM-based 5.54 2.01 5.32 5.75 fined by Equation1 or Equation2, depending on whether or Tree-based 5.61 1.95 5.40 5.82 not we are incorporating color information. This process re- Table 1: Survey statistics for ASCII art. sults in tens of millions of region-tile pairs which are then used as training samples to learn the tree. The parameters of the tree learning process have to be set in advance. We generate 1024 binary tests during the opti- the mapping. However, it is not clear how the presented nu- mization of each internal node by repeated sampling of four merical measure correlates with visual quality. In the next integers (x, y, c and t) from an appropriate distribution. The two sections we provide images and processing speed anal- thresholds t are selected uniformly from {0,1,2,...,255} as ysis, and discuss the applicability of our method. the intensity of each pixel is represented with a single byte. Channel index c is sampled from {0,1,2} (this parameter is 4.2. Rendering ignored when dealing with grayscale images). In the case of w × h pixel tiles in the codebook, x and y are chosen uni- We use the tree of depth equal to 16 to display the artwork formly from {0,1,...,w − 1} and {0,1,...,h − 1}, respec- in the rest of this paper as this has proved to be a good trade- tively. We learn trees of depths equal to 8, 12, 16 and 20 for off between memory usage, processing speed and quality. the purpose of experiments. Learning the tree of depth equal Figure6 shows the rendering of a circle in ASCII. When to 16 takes around 1 hour on a modern PC with 4 cores and comparing the produced ASCII artwork, we conclude that 8GB of RAM. The tree requires 500kB of storage. the tree-based approach manages to reduce aliasing artefacts and preserves more image details than the luminance-based To numerically investigate the accuracy of ASCII art ren- method with dithering, and the quality approaches that of dering with a decision tree, we transformed a large num- SSIM. These results are consistent with numerical measures ber of images to ASCII with different approaches and com- from Figure5. To back our claims, we also conducted a sur- pared the errors induced by the approximation. Cumulative vey in which 50 participants were invited to score the simi- error distributions are displayed in Figure5. We can see that larity between each of the six source images and their ASCII the trees outperform the luminance-based approach, which renderings obtained by three different methods: luminance-, serves as a baseline. As the depth d increases, the accuracy SSIM- and tree-based. (The possible scores were on a 10- approaches the ground truth curve obtained with SSIM. Sim- point scale; 10 being best.) The detailed results of the sur- ilar conclusions can be made when rendering image mosaics. vey are given in the supplementary material. Table1 shows We omitted these results for brevity. a short summary. We can see from the statistics that SSIM Figure5 shows that the trees indeed manage to approximate and the tree perform approximately the same while produc-

c 2015 The Author(s) Computer Graphics Forum c 2015 The Eurographics Association and John Wiley & Sons Ltd. N. Markuš, M. Fratarcangeli, I. S. Pandži´cand J. Ahlberg / Fast Rendering of Image Mosaics and ASCII Art

':::--:::" _~-^"""^~,, _.-""""^<,, `~" `~" _+" `=, _/` `*, '_ ": + -" _= `_ _^` `. ;` + _/ ^, _/ `, ! ! _U ! _U 4 ! ! < \ 7 7 '; `_ <, | ^, J ;' + V_ _= V_ _r :- '= ^, _/ ^, _3 `;:` -;" ^, _+ ^_ _/ ":--:- `=_,__~" `=.,__~" `"^^^"` `^^^^"` Figure 6: This figure visually demonstrates the advantage of taking into account the structure of the underlying image regions: A circle (left) has been rendered in ASCII using luminance information (middle left), using the SSIM-based mapping (middle right), and with the tree-based approach (right).

95% confidence - Mean Standard | _,,,.--=" Method interval for µ "~_,,,,,_,~^"``h` score µ deviation µ − δ µ + δ ~,`'```_..,-,N, ._,'_-^'`"",. n = 1 4.89 1.73 4.72 5.06 "`"`", ' `, n = 3 6.75 1.57 6.59 6.90 ^"',, ,'. .-',^_._~`, Tree-based 6.24 1.46 6.09 6.38 .--`.,'_'_'_,- `V,^.,-`~~ ~, Table 2: Survey statistics for image mosaics. `_ ` _ _' , `-` '' ,_, _,_:'`"-"..~,,, __```` `"=,, ___-`__^"~,,.,_,`_, ~^,_._~V",_`"``.-_`", n = <=,.````__`-`"-_.`>=h [KSRY13]( 3). Table2 summarizes the scores between =.:,~_,`,^'^-^, _- ~~^=3,<=-^-~ `j~ seven source images and their corresponding image mosaics _$ _"-^,~^- -, `~Y_-^ rendered with three different methods. We can see that the <,, --`,^ <--^(`_=-:_`" score of the tree-based method approaches that of its ground u,_~'|`"-, `"j`'~_, truth target (n = 3), and is higher than the average color de- ,-^"---l`__-_.-'``^-~, `"~,"^``^` `. scriptor (n = 1). This shows that the learning capacity of the tree is sufficient for our application. The rendering of the Baboon image can be seen in Figures 10. Figures 11 and 12 Figure 8: Low resolution images from [XZW10] rendered shows some failure cases. The next section discusses large in ASCII with our method. processing speed gains offered by our method.

4.3. Processing speed analysis ing visually more pleasing results than the luminance-based method with dithering. Table3 presents processing times on various devices re- quired to convert a 640×480 pixel image to ASCII. All com- Figure7 displays classical works of art in ASCII. We omit- putations were performed on a single CPU core available on ted the original images on purpose to give the article an the device although all methods can be easily parallelized. old fashioned feel. These experiments demonstrate that the This can be achieved, for example, by transforming each row tree-based approach is suitable for producing high resolu- of the image to ASCII in a separate thread. The computation tion ASCII art; the renderings are sharp and the tone is pre- times scale linearly with the number of pixels in the input served. However, as pointed out in [XZW10], rendering low image and the depth of the tree. The tree-based method out- text-resolution ASCII art is more difficult, and our method performs the standard approaches because the tree needs to does not perform well in this case. This is illustrated in Fig- analyze only a relatively small subset of pixels within each ure8, where due to the limited resolution, the depiction of image region in order to replace it with a font glyph. The very fine spatial detail is problematic. We exploit the render- method is more than two times faster than the luminance- ing speed of our method to reduce this drawback by taking based approach which serves as a baseline (represented by human perception into account, similarly to [DER∗10]: the AAlib [aal]). Takeuchi et al. [TTIN13] implemented their input is rendered and displayed multiple times each second method on a GPU and achieved real-time processing speeds. with small randomized displacements. Consequently, ASCII However, our method is around 20 times faster while run- images displayed on a computer screen look much better ning on a single core of a CPU. Furthermore, our method is than the ones on paper, as shown in the accompanying video. orders of magnitude faster than other approaches reported in Figure9 compares image mosaics generated with different the literature [XZW10,OR08]. Table4 shows the processing methods. The visual quality of the tree-based approach mo- speed required to convert a 640 × 480 pixel image into an saic is higher than that of the one generated with average image mosaic. Note that the difference in processing speed color descriptor (n = 1), and is similar to the ground truth for ASCII art and image mosaic rendering comes (partly)

c 2015 The Author(s) Computer Graphics Forum c 2015 The Eurographics Association and John Wiley & Sons Ltd. N. Markuš, M. Fratarcangeli, I. S. Pandži´cand J. Ahlberg / Fast Rendering of Image Mosaics and ASCII Art

._.,,,,,,.,,,. _,,,,,~.,'M_,,,--,,, -_,-^_,'-",,___^:*aFa,. ,_,,,!_je__^_Lo_jjj_jhr~,, _',,s^___*_yfj_PuyTxQyByef_, __s___,,,,,,,_,,,,. `7%%Ft*<3TFFy&&ya8f*",~_,,,,, '`^WqmDwyFaf4atjjj3uPt_,, _,__Coefe\<7*u8JYTF7*7*je7YjI_j7Y8%yoLj\\_\>, `wBhLrr>7*VPyyywTr``_,""/_~,,, ""#EWdWUfe4U4ejeLdg#?`` _~_~_eo*lf\=\_s~/\_jjst_Y>` <_,Eyyo__^=,____,,-. ^%gDP@Dy%yyy%PH#Fn. -___*o3Yf7uFD8faJojxYC__Vos>*7v+*e7"_^^s}?__7*r+=<_/7tjr3*j3a\=^"/~!_<<_sva&jj_4toea@YTTLweYTEYaf3xhfTI0t0jY,, ^_,__"~!:==`-=\\=_="---^``\TWggmajjjjjtj__|;_, ^,__73YTykwyymFfV0],',```,.`,`_`, ~__j3f_FfVFwyPPfsr_^=uy!=_"~_=r_j?3ar3hLLr3oe09TYTV3*vTh**l_TCS4L3j*YL`- ,,.,"-____`,`,-.^""`-""^`^`-\3FWRRUTwFDaxaejj___, ._,^=\734TTF%dqPfftr,.,-``_-^-'"=_, "884w%y&fadUTUY"_^"_j^oj**^_jxf\=_xT*3v3VVfuw` ,,,^-,~=>>"""`'.,``,,`,,__,,,,`_7*T#RgJfwF_@Thaljjuj,, ,--```"^\7SuxwxF%FfzLj_,,,,,``,,~,,-,~ '_jj_jTTYvVwyAxF"_^^=7\==7*lv*vTPEfFjI777\"""___r^aaaV_r_oel37jIjuFa"` ,_,,,,,,__,,_---``'.''`,``,"``-","_=/7YTBt_7VTVff_Lay&Oj, _,`-.'``_//7IT@%%%k&nLj___,,,``"_^___<, _<_\TTAoefuwdPId>|,, ~-,,,'`'`^=\7SuTFFFFFht*r=;__,,,`^",, `l__,,,'-``=\<7IVTTTTThtrr==__~_,,,^=v4"r ._,_**_t(jCTCY7\vr="__,,.,____|<*3JYnZOtrr______;-"~_sj`. ~,._+^_*tr____+~__j#fjr_\=^^"_~______jLh=````` _]\/_r____r_="__,-"_.-",`,"`.`?_^___,-^~_s3wejCayajrVVaaIU@yaj_,,, `7tr+__--:__r!__=^^""^=70 .^__/_<^|sv*\7r7^_j7_"<_\eeDa%j[__j___~_"_|7j4fs*vf_jjav?"` |7/!=<73eejr_=;__,-`--^-`,`',_|___"_____/jjF&audgQyj_uajun&Fya___, ufj>___-_^==tjjjj3*77*rr!/!__^"-"-,``` ,_,__,,_,__j3Y*rL_~"___<+__v*"_/r_<|____~_;,`?vJ**^=\7vYTdTf3Wr`^Tf95fUy@kYeTAFxa; V%atj__~:,```"!!=!^""____,__jjjjjjjje] ,`(Ljji\r/\73e> ``^3lLnL4VaaF`, ``YD&aPTUdqgWHHqQpmdPTY*7773YYVfS,` ,_"___"____,vr"_^"-',_yTLsr/*\/),vjLJVr_^ajs_\_8_===_3xE8v" ~___!___!<3@U3Wpwhhazr\7*0rr"_,,-~__=______|jojej; '`=^_r_j_>^\` 'EFfft=<]/j3jj"^^~_"^"^"=7=>s_^__"=~,,, <_,,',+s~__",-"^^_so_+_\?,. ___``^^"^{'_,"`-.,``"_~____,,,,,___|_sr^_<(*j` 'otv3JojjJ0v*C7?"-~-.`sLj?==\<(r\,, `^F&rjv3jj4haaT@dmj_`"^*_778j&xTDfr7gE#BpyTr,-swejj>7Y@PvmmaaeL______jjjjjj_ Mr__,`-,"!,,__,,,''`.,"_\+=~__`__<(>*73r"~_7_3, `:tCj3lvjLtllr>=__~,^-,`^"``"^^\<>_, ^@yuajja&yxykwxEWgpe_,`"==*3VwwUt_vQy_P###%ej_,`v%dyano..`"?*ahTfVww&Uhyafu=. Mnr_-,`,"|-`(j__,_,,.,,=_";_~~.=!\]r_._<\_!!_=?==\777]((/_||___\_7rYj ,(j]~__~__<,___~/^77v8jVVtjnuetLuu_eovJu&aa&x8Ar ^|r^_____~__^\/<\*j(/>(r_/_<(*vl*rr/r, ``%kAYr__9. `(l(>--_~_<,_|~\____"` <]r_~_\_+==~^^>_r"_jorr=_~_\_<^\(r- uLjr_;__<``__c_-"__",,`^j7E&_Tjj_jjj@yEbfr"'_,~_<,, `__,"-.~"<_s,, ^__,<0vtr>!!^,,,,-`,'^-^""``~'"ljTf?,.!=3.|,"`, .2_\e7_sYJuwFf7\_sr_^"^/3fv, `\r\=-"_jjuT@E#a#PfV_a*a-_PA`-u!'jxtr{ .!va@FY8i>>_j=<\____\jyhroF%r` __3zec3__c_____oaaewjapy&eYfk{~jeautr>~,,,~ `_eeej_>-,__;,-",^_^77?__jjawy8Tn@ItJ7"_^,,__=.'`,~--.~. ^\-"_7v_,"__~~~-~,^.- M_j".,___jeVdtr_,"^<(_7tJ_4VLjs_7fLJ*r?[=-_3c7v8TTUTj` `\@w&8a_j>/%_\_e&tjL0*P@Tywanyt,,==^"```=7**YJ1___at3rY0J8tj__3TTPy#&__."^_,,``~_]7\J\r__!_=?7*\C*tr|"-~"==<],` `x&j0eADAVCIC!. _'-__;7*r"7nj___EQfunujj__\__^s__+___5Wgj,^*ai_=*j)7vYFLj_=^_,-_,]/c<_<77>/____,'_=~__7lJY! '`*T#waymgQwTVujLj___yE_j_\_^__~___~joaTfeJ" ``````_"`. _kP&j>=,"~\jJ_ `7aajjr_,_,__", yh*\_&aYrsjjr\LE_yfL4_/VOyuaTww&@wyxuUauJj>7j` /9ejvr_/r\7*YtxbHWWWWWNWET8t"^~_3FaT3*dgWe, '@TUt="`",,3Vr,,_ VTTAuj______,. __DfrjjTft7jjC>TP#%W#EDFfr^j,, '3y&YAzvjj3verqWQt. ~`3_VTTT&ajLjj_,` __C*a@TdF&nua37_cwmEQpe*FEyx_OTxUxyFPT&TTTUVJr_<>/- _/r="",`"'`_xR#%mEbw@xaLjr=""\^*7CY3YIVdJ;\r,, `(fThjf0ejeeLdXHKK,,, `UanVUfTT8fjr|,, ^r*j3dR>"4j,~ -$8fTaYIeGaaURpPy#r'` `Yaue_uVu@ar_\,, _yyB#FhVfVYa7V4kFT%dFr/7j4&Ljja%#hTAn5uaYe$f*/-r__` `,`_,^_3#WNqkY*7YrjstJTPTfd#by&7L3,^s73T#g_~_` -$v3JTae_n44TRqy#k` ^`VYfLYTLVfr~^=, '7#pyfV4wGeljjA&TxTTfr_<(3UgNRffJ4u9Y8Tx&x8f*r,|=_- ',,~_~v8F##W&3ljjC73Cvv7*58FFfD_ttj_v_YTXL_`,, uTej7**CvL3ovUQqm@' `'Eaeov0lfr____, ``*P@v34LtlJvn%aL@FwLr^^<9vNRbe9zFhaaVf_8PTtr!_\_\, .aLjc]+/\\r7*5##m@` `Dy&hfzjfjr__\_, <.UttvL*\4j7$@JIuTUbr_^=*YBRLlLuf9VJYef4Tf3]~_,r!" _,`__"\v4TFFEq&jr7/^^^^\~"7*eJTT&Td&jvj7TWt,^, ^7LL4t[cjr3#t0VYTT%r~~_<<5R*4ffveoSnjjyTLjj>_,_\_', ~____^_*_Ya&j4#QQg&o__,'`^_^=/7YJY%Ffj3j7TWj_^, `T4t]>_^~__!*3Tpy%, '3D@PhOaatr__,, 4_^^"-=7SaaJ@ftj%##E##EF%j,_____~|/7T&j/3o3PQ_=_, `3@nt]>____~=73TyF` VDkhafIanojjs7j7&@#Tvvtr\_j3YYTt^svdy#t__, `^8Lejvr;=__]vxyj. `Yhe3tLZ9zltjr;, <`0YLozouf*lj9tIY45V@Vf3I#@Y*l*3oSl_uwudfof&ev!jj\s`, M^___/j_7*,^vUmyBj_"' ``, `\@Ufvj_^^\*dmh@~, ``8aeJTfftaLY,` `_3OFy#aCf49h$e$Uau#/_jufv/?*IYAamEmETTxPwyfTerfjr, `l<\^"ifr3YYwUT&zvVwht[7V_#t_<<3TtriCC=/\<_(eT@Vdy__-. .`$Tfo__!_=\_QFT&, ~`Tv_uw$f_9v; `wmpp#hJ*o$TfaYVxyY=jewfJssjlIjxPyEPPxVTAaaaajr[7r ^<=^"_/r_j/7*T%_YexFT$TtiTkj7j3xPT#gqwc7v**3YL7cr=_LeC**C3vjj|r_*trr_TAaTWf?/s+. _rci]oCjjI$Uutr;3\_ rj__gPfTtvdELCr_jj_jjwqmafetvtJLu%v5dQQgfxy@TUdBtj]o|, ~/Tat3L%Ryav-^^/lo4n, ^`Tjur\_=, ^xVLeVuFa%mY_j=="<, ^3en&f%yDyfaataVe5Sjj]jvs3vLeahyFfjuaat**r/^_., _.aTfToljjsju&efLTfTyaBNW#%L4uqqQgRRgRRgR_QQgN#F%%v*^^"_""______(_J*_r\r/C' _VrJffTQyv""^-^7dya3j,' ^yar__,-_~_, <1*C7\~=7t5f4YYjjCclvjl_JeYfayhxwPfYsjj|==^\,,, _,r7_^""^~1300V99enaaeeezf8axTFTVAfjjeS>=,``\-' .,_,,__,"==^^"".____'`,,_,,,_^:="^___-'"`_<====~_,^~__>r____r!l+\lj>3r_r\_==+=r__"~<7ov*4Y$4Tee5YVTYYYtJVVfnwfr!_,^``.` ,,_,,,--''``,__,~_<__~/<__>,_<=!~!``,,^`_""^.``-"__-_<+______<_\r_/>__73joj*rijj*r]7_\7t_, ^_tj**Cav^""^``-^=TgpeeCv,.,,..._. '`Tp@j*>_^-_-^__,, ,,,,,_____,,S_,"`,```"^:^_=~_~~_____,______QyCr__^"-__~_,, <`<~,_^^=^=/=/>>7sj_-.```_,~__,"""^^=/<=\<\r<773Y*_zxjf^"^",_-` -/j_=<>|_~<^",^^{_^"_\_*!=\-_"7r|^\,'`.`^"+,_,>;,"_,_Co3rCetYtvfJtv(_\7r3, _/\^_==|_~,",,_,,_^*===~^^/++\/77r***77777773TdWga_\;":"___|L, <-otj>___"""`""""""^~_,__!vjj^-`'-^`"^"^==^^^!====?/777```"_'`. _~?>/_>=\_^-,",-,^,="=_<~____~=_=;_`,_=.--="^~~:.`-^_rsr"7j_ojC3lts*jrscjj*jjjute\jft___````````````.```_,`_,,,,_,,,,__,,______,``'`,,,, <_._(r_\_!__>_"_"-^_=_"__^______=^_^_,~"~=-__"~":_,_/?_Ltjjj____/~~=~,,_ ^.3DFjjeTfZfvtY03tYaydyEFwtpdE#pyypT%Ar=-"______j^_____T&Lwt_y=. <`+=/=<_\79rCC3lLjTTFyFf3Yf08IV0T@&jjjdFh@&TTxF4f&FUFa@yhFwD,, `Twaej__^_"^""^-^^^^=7*%FFFF%%VYYY**7777777"7"""^^^""""^"""^"""""`"^""___,~___oaa$` ssa_s^^^!/""^^""=_^"!!^0=*v0T8*r_j]348nVA8@FT@, `TDyymDyyq%yP%kwFyhyTaaeaooooojj___j______jsjoooeexyP&ymEyyyEyydPF@FAa`

__,__<___et, `_, ._c%j7Vt(5xffYt/_ ~.,`__,_^, .)8TI7*_Ta=AeJI)jzV, -_,jlets__^~,,~ . `._t_#\"_aVv*Y7_7/{*&r_,, _~Ltefj>==7Cr~_,^, .______aF; __7__uYVL_s_="":~Jt3j7r, <_jv_oJ?/e__;`^=_<_- ,__jeFT_VaVVVYTTee="/- `<_yt_Tf_^^_(t=~-^^8Ji3C=, o**jj*=^fYt""'`^<*_` `__oFyPTVVYYC77=^\<*"__~,, 3m8*/**/"_o9r_j,,`j\_T*, '7J33_f_=_na@_^<``` -/\_rAT_TAtjj 'Mur, _Y.,.-..j3dydQgf4jY_"_jdXgR&t, ~EEp%Q%%wwuC7leC5Pt*"jTC7r!!__oTEf7^"```````?_7__, ___seypgRPLVadmg~&vJeaanjdWggg&9,,_. ^%#Q`VP%yfr(aut3YrruFt____",,`"3j_ ___t=_\r*7__~<_,,,,_*]I`7_=-__==_\_,`, .FfS4aLYj_tijj8e,._,F*7r""I\_~_=*ut"(/_,,/_yj,&,"i"j"<3/>"_"=,.^<_,|<,r,^3. 4ntj_==,:Tflr==_```'``^_jor7YT#Wgmyajj___,,_,_`",^\*j<, ~._FaYaxF@t7ovjuLVf3,_yfCrj,_r""~=<\Pr_=,3t``=y5t<,_rytajr_`____'_;"r\^M_j__=_ u&tjr_:`=^`__^lu,,]%r_.\,, yajj____Anjj______,,__=,,```,,\TrNRNgNgqyy&axa__^_,`]* ~UhTC^7777Lr_/7=_""7Yef*rsr"3rt7___ph",__\Yeo_-3uT&_v3r=-`s_^=^'_=_/7;!]e_j\_7L, Ey&aj__3w&Ltjj______<"``.,__-"_5tRWWRNRRNNNgQF&r"`=_rY ~&AC>__jjjj4jjjc__,-=5TF<, .uFfr/e*=^/70TFhj__=_^\,uQmfjj__wy6j___``,,,,.^=".",jCe-*Qph&fILLjr=`"^^^^*v, kaar"~_4@C___"````"^7YVf*vT#pwyyt`Y*^__,_~__V=,p&e"_<^rr__'`-`-__/Q7g`_^"=_j,VggQynr/%yjvj/77r__,,,,-==r7vj ``````F4Lj__,`-.`\>,,_77_<3LJ*ttt>, a3:_s<=\__, _8r7r--_3r=~__,-^<73T%fj_[5Nylr,^_~_~~:""qh*7r^7j__, _jr\7=__;^'``^, '_/j0I7*t!`-(dF_v?^J]_\*, ^vYt*r`"--$jEtr =i_4j__jY__3fr-"=0fFy\jjxNQmya~3\Ltj3j ^<~____u[_` `VNRWWQkj^5yej_=~_._)=<_^__"""3,_J7ls>+=*7THHC;"^7%pxkyTfV#&fjjT*r`,,`_=\lC=""""7~_j,(V*^/cr,```.__uyfl__,^Y[+<~]___^ `=??""`__jxKPg#_Fmnj\^"^`"`"^^771olljjjj0*?"""\~_, ._eQhTFTtr_-`.`"-__j4tr^`"`,``*7RpEEqpa]\<7\r"",,,<,\,<_="_=*TypNmwaaqD*\#*_j*o$#NQRj="-"^YWtr____xaLjuaj|____3%F7r>___jjLfjeu*h `uV"_74RXr<=-^3x%gpr_Trsj_^"-,,,,-""~__,``^==777CY8ao*^"_____,_jfIfvay7F9%8Yos____,,`.``"""""""^\=~,,"__"=_ `_jT%yufVtC7_,-```^_of*7_`,_____=,VgQydpH&aj__^r,.,"`_=^,==`___*?*d##fufj_=_#atjuawqRNRQr^-``"7&j___~^?dq_y7^====__,_,,,,,,,,,`'`"_!_7ee_^~,' _Ot74%TJC77<>_~_,__oAt!":_j(7aj__N*NgQQP%xLjr_|,,```^`'_<_/*7_.\jvFTxAfLjja@r*CYVFBRgRNy{,'`'`^ijsj3v*SIl(awFQyEymf_3J^^^^-,'``^^^=_,_"-______,`"^\\^*Vaao"` _fC?\Tvvr=_"/s_____<8Y>~=^^"^s3&jo'__BRRgmJTkoj>j^,``."'`,^*_<>_=~/*wgPfJ*0kFt__<""^7#NRgRQi,,'.`^ajudWrBDm@r_,,,^/7TfV&fVaaLUF3fLi^L` ,~"_(vqggRgvo,.,``^F&>^=7*uLeoeajLj>_,`,.```.___j_rje7___or#C4fYFY***+*~_,,___,_`,,`______ojj__,__<|^_J,,`,..`""^^_/^/7***sisjojjoc*77**=~><<*yyyj&e_t,,`. PdFTTfYYT%ajuajjj__|______suynDPPTfTj_Tfa33jffs=^,`_-'_">~"/r__;_,5fajj_^Aj______|s_j^_""`""^/^|*|`^_r``^'`^^^-_^""```""^^/=77**7**j_]___=\(jNE*dd^*Tj3'` Tfjjjjjjxy_gW#PDdyyyyyw&&&aax&yuf0r*0*>7=_""^7" ^`___<\UWWWWVr3fjj,`,``*%#_ewwi^vs/*Yajjj_jjuat_j"_,,,,_"__;lv____r,_,,__,,,__,,_,,,,,```^"""""^^*Lej__<*3,`'``` ^xyyyy#E8NWFfSr=!73TEXPPPFTTYYEuX___!>o^,_,``^,`^\j*___jV]_t3fj/Itj__^\_7>_`7ynhjxfaTsr_/YPE#Ffter_/#&j3JL___,-,__,,.`,`__j|t`(L\>{^' ^~=_^73dggg=_\_&atr,,,.,<;,',-`\, ``"??^`xAj3jjj__7YV8ajj______,'..`^_ _PTaj4ufYvvojj3%yajjjygt3rr_\YY,_v0 `<;^`. .Ef7YV@&aaLjjjajj5BgggNRr3t!;_`__\^- `<___^3m#qP,_3ruBmjxf=^/8t_,..^3vr`\V#NNRRj%Y7\*0oYuuWm&j_`_/__- ttj____,'.,`_,_,"`_od#Ea/Taj7?_*3#WRRgtr_=^~v4AdgpkLr_\_7<` `Lojjr__,`,`~___3EgNRRgNf4fjor?~`^,"jmAr\ .Fh$LIjCr>r"_\__,_yAr=7r=,=\_,``A<&,/rTgyyaLjer*4Ljr_-.,``.,<*r, _hi>~~,__=>___=Tf,``"__~<*,,`<|%j"j^@##dyautj3fejr__,,,.^<<+|_v777"~`,.^.,`"^_mhnxhdyj$aj___jvr""_j` V4hAOft3j|,^(4gRfC^^<_,,_,`~t^=>\_5EqsT_4,<&_Vu6"VWgRWr_,,;^".___uFut"_jqKTQr"`.`_,^(j?_t,`^,%r"__3jtg'_mNgP-@@",,`'_vr^/5hj_,`<,`"*v#fCJtCrsvJr,_<7, -&$rr=]__\r\3WgHRNN~f<&__`_,,-_"'^i,,`^%yTt*rr=!^^7@mpyEPFtr=__oaygggQr(,,:_=/;_3trsjudR_,_up#f~<3fe_^__\3<<(<(j^_{-__(*,_ ^tj3xfOT%Rg@f4noj__"_____jjjjaQF@fl7!\_^==\%#t3%ETPW~Rpy&aj_^,`^>|______j_jey%yydgN#*^(r,MdNRr""^_\=<3jj3j5TN&_3BKmA,_3f@j_<|]v/je8YC~s?\rc*r7_.. uTouUCJ*BRBkygfT&LjoooeaaajxPEEghhtr_~|_`"^$FC<5PtCTRRWWR&nj___`"^YTTT%EWp&VJVUfj_t7_r$r_",&j_,`',`\=yaLjs_____rlr7/C,r\, '`8__uWWW#Efr!?=\*r___-""7r,^*,- V5@$dwyf3WYhgEr3TTkFhTyyK#y%PDqNghfj_,^+,`u5&t"7UL!h*^_\It>,,,``<,%yyyyx&aaaw^j_\ru=-, 8!^\*YIpNggXgRNyvj_,,`-.3yr_<0]uBqr"3f-^D#yajjjjjayfvj>="^"/**<=*=-_.__^ar_,-,=7./<_~;\_,,-"-_^_`"`"":_,,____(r_s,, _--^_,`=_,`^_>/==^>jlcolss*___"(&fVYr""`"3j2atvfj`~4mWgr_/""\CjyR>\<3nE#fr?*YV&7*FP%waaa&j_\,. V3jWXT7??\73LeEWmpf*"^^_mWWWWWWH#EFdbjj_,,``Iy,^_!+7___,`^:__=_,"7_^*[==~__^<7r|`^3gmAt`"_a&f*7C5xj,`~_^(s____73--,,r___3xy#r="._7CJYYVfTTTTF@fTBbPntr,,`^B_`^|UdE@r,.`_],_~=<_T#gt, ^Ed##P@ndt.#U8fSr=^^,`yr___8rsTDmaV7\ -rjrr___j*_ovY7__~s*7_____+s_77lLaqNNN@\_!7r_=^>j<=__`^+=\_____^7**os__~=,-\BgQ,`_Tfjo=jugL,,`5qQpy,``'"",*VPjovBgNkjjL, 3Tj<<}7uEQfr"`_r7s*77***SVfTTf5BhUFYj,,_,3t,u73wyyj,``_|,,"_Yi_3_Tj5j_/*j?_=\s______^^"=_==^^__sjr__,,`INR;_3ywf_jf3gg,,,^y%ggk,,'```"_^7fr7Wgg&j7*T8eoj__, L%&j^=r3%Wt"__\_\<>;/s*77)_____^TWejxwY"^*etRRa,,,=~"BNNa_,,,`^^"'"."YNfl>___^*$fTU` Idmt_~>rr7_,_/+<=~=\===/777*aVr$vT_ar|,',3yj,",ydyh,.`^3,.`<,k]jc>__ax" 4yqg3aj__[>,<~<<_~"^^^"=<\/74ftjjxFt,"`'____`4j__`"^=_~;_7|**t__`\VeevtyUU A#gaF%wa%r=-^_/~""""-^-^"=<3Thhud&j_,,_`3QDj_,%qgyj.,^r,,_<,4l*DA VqyhnId ^Th&t3TE,_xRf*3rfr!j_!>(_ ..^MEEdk&xxaTTIYlovr//*lsr_~+?777**s_Tf/_,,___7L_>_, (mqx%UTEp&j,`_!_;-,-^'`".-=<(3Twft3_^,_3RRbBn_\3T*4_..,`_=or3l*xQ 7mfY*3E_ ^`w&t*3{uqFrs_utr__~==!\*j73wymBNNN##WQj____/Yd%j_-,-.,'`"7vaeaaa&j<suJ_rr\,^.,@g#%TBajc._i_?>~__/r~Tr/%X. ^IytCrr3k` `xajj3,ugt=3r<_!!j_}=[, <5DhTf@eYYV0*s*r77l_v8P#PFwfvr\rtlCtj="^":,`___(3Vj_rs=__-`d#C_jVabaL_^r**<3j_ee@_<%#ej____,7y&jr>*T, `hnj_l,_<+*r<<***vewQPxvr_Ar__3/3r-"\Y*IyL____J_jfjTaL&FTUTVTfY,7yt__\39, *&Lr7f<#:`J,/j_rt<|-|, <7&kaYto___jj7jzveno___7*?__r+__<(*vv*****77r7?/77777?/7="!7\="/~~//=/+=_r7777777*t*oC*C>?|+~"____<>*>____/_=iv77*C*777?^77=_=3YYYY**szvtojs3V_____,, 3l(r77r=\l__^-_-,"~`~==_^,`'```\4kPD@_EL__oa_&__~|j_3Eyye_o*_**Yt<+~``"""""^\/@Lj~^^3a ~mfj^44f"_j_Ir3rt3!<\, <0Vh7777(jojLjrr=\_/""==\/=~|-_____}(sjscij3r7**ijCLl, j\=\!==_!jxyyxPFTTS?3m__7j3YYoeaLj5myt{>*jr*=""`',..`._*kt___~",_"_____,,--```--^^,,_=_*_>r_rr7}*7?<777\?\_7_(____*v*ljjr_C33jjll,,.. j______a______,_i3Dmwwx&ujojaWyLje??7*=_7TajT3_jjjjj______,_,-Yf___~*VA, 7n_,`<,_.,,, ^jfG0***vve*Aj*C**7r\_==>^^=^==^=^^^"==!^7^^??777\^???^/"=~`_\_<_\~_""""-"""""=^V&jr__3jen_^_@t"'~#taf_G]srs0Yj`` _,___>_IYjjjiiuteejzT__l&&&w@@888TTFPTTTVVTTTfC3ZfI0l7J*>7****>****+************ssvvvvv*v>>**>>>0l_/r=r__"!==!^;_"^"""^`""""`'`,,---"-"_~_=_-";~____<^=^;,,",,^-,"u,,QzcvlvG**\_fl_j/__r_jYrj\j/sT5 -.___jj&LaaTy&&aT8FTTTIf3vv****???^^""``````````"`^!"^\_-_"`"_````",,__,,:-`^_--.^,--`',`",<`"=_-~",,,,`.~___,,_~~~~~_;"^,_"":--__c~<_,"^==_|_\/_\77l77C7CYY0YeeaZTTT@%mpa,- tr/\=/___=/1r__^^"^^=~-^^"-,^,`""`-"."^--"^^"__^"~""_~rr(_?s+sssjj+ss>><>>voo<>v*jrCrr7CC__77_7___777___(l_7Crl____l_____*YYYY***7r7*******>**r*77]777>**777*****r7***j, -fjjjamWgXggNNBNPFTFflLoovezzCIIllloos<*<****vYYYY*3YY3777777777777777777777=7=7==777777=r=?=7??77?===????7======?7?7777777777YY*YYYYTTTTT@PF%EEHQgqpmQQHWQhTT0", __al7*7jl>+jjs*=7s7*7777777]_r/<>*>>v?!"_\=>//-""_/_~~<=/7""^""^^^=^=~;~~==""____/_~~=!^^"^^\/_P&, .auaEpgWWFTfvajE$o***7777""""`"=.^!,^^^,"`""^=~\/===!^^^""""""``,.,,``_!_``._,,,,,,__r",-;<;,-,,,^__,,,`_,`_-_,_,~__,,_-^,_,,"____,_/-/___^"^"^/\/=_""__<@dwD6<="__<;;~___==""_="~--^___,,~,,~_,^!!>--^",`-^~"`""~"-:-^``,~<@hTj, '^^*F#T_ae4Y7Cj_~__?____=~!;`",~_~_:-"```````=_^""=~=^",_","`^""``",,^""'``,".,,__="=-,~______,",-"=_-____~=^-^_=_!___=-.-_,""^_"-^_;___~____~\____=/77rrrr/\77Vr`' _IRNW@s__s+/="`__~=!^_,^__/rr__l___"""|^_r~=____j/r!_!-^",-```,-,_~~______>r~---:^="^",:-^^_"",_,,-^-,--_,"__,"-:,``',_,,,"-""""\V8TT$_ `^VVC*?\_"]_=__j____==~-'-_,_=`______~~_<<sss><>oosoooos++~++*ejoooseossoo**oooossssssjjjssoosss|_sjjjj_jj_j__/<|rr|_\(rj-. _BWWWWP//"_,-__~_~"="```_^(==^""""-r^^===!~~7\Yr^"__,.-;__^-_;_s/_?\__!~=<_^_`_.---,_.`---^~~~>^-,,_-__~~-___-`'.'`--"^-______<__>><______`""^77^*+*<0YYfTdxFj, <*>*rc>~__~_~~>_<__==_>~___==\rrr>\rr*jr<<>r__<__^^____//j777r7_ij___rjj______j______jjjjjjjjjjj `aFTaVTTjfjLLae4yBdTTTTT_Tjaxwa&njj_Vj777eOn_z4evCjj3@qQP4ayfAY5efvj*ijjeefYL_aFTaYldytLYoJooGt4ffjTyTkjaS*9TafjTTTaw@tlj333Ya&Ajua8v4%mm_TfunVATee>j_=Y"`` ^eeaeeeeeeeeeeeeeeeeaeeenejnaea@j8jjxuujxyTwTTFTTT______T___L_LQ_Q_y____j_y__yyyyyy&&a&aaaaa&aaaaa&&&&a&wwa&www&aw&waaaaaaaaaaaaaaxxxxwxww%yr `7LaxET_uxw&UybQbDyyU$T&P8wyb%UAjjz4h_\vJ4Lu3eLtotu**3S"3wF&fea4uafoa%uTEfax@%dTtea_mvvtt739fj&&ffLAtzJTt4e0LY@PhhaGvvaoCLfaTTfffUavTdyPy0tY4LfTf%hyyn'. `^TTTTTTVYYTVTTTTTTTTTVYTTVVVYYYYYYYYYYYTTYjYVVVjTTjjjjj_Y*jjjjj____jjjjj_jTTT_TIjjjjjLIILLLLlllllLlllLIlIIILLLLLLLeaaeoaeeoeeeeaeeeeaaeaaa"` ~uTyBy@#myPwmBEVfTTTTymyadyyxwhTVuVa"aauanLrjLj\^~_==_/^!_~_;_~_>_/__=^==-"_"_"__`,,_``____=~=^__^__=^__"^^_"-=-"""______~~_____ r_jj_j_j_j_jjrjjjjjjjj__j_jj___jjjjjjjjjjjjjLjLLLjjjjjjjjjjjjjjjjajoeaaeeeeaeeeeoeeeeeeeaeeeoaaaaaa&a&w&xwxwwxwxxwwwwwwwwwwwwxWqqA^""`

Figure 7: Famous masterpieces of sculpture rendered in ASCII. Original images are provided in supplementary material.

c 2015 The Author(s) Computer Graphics Forum c 2015 The Eurographics Association and John Wiley & Sons Ltd. N. Markuš, M. Fratarcangeli, I. S. Pandži´cand J. Ahlberg / Fast Rendering of Image Mosaics and ASCII Art

Figure 9: An image of flowers (upper left) rendered with flower tile codebook by setting n = 1 (upper right), n = 3 (lower left) and the decision tree-based approach (lower right).

Figure 10: The Baboon image (left), ground truth rendering with n = 3 (middle), and the tree-based one (right).

c 2015 The Author(s) Computer Graphics Forum c 2015 The Eurographics Association and John Wiley & Sons Ltd. N. Markuš, M. Fratarcangeli, I. S. Pandži´cand J. Ahlberg / Fast Rendering of Image Mosaics and ASCII Art

Figure 11: Rough color transitions may occur due to the limited codebook size.

Time [ms] Device CPU Luminance-based SSIM-based Tree-based Laptop 2.4GHz Core i7-4700MQ 1.34 93.07 0.55 iPhone 5 1.3GHz Apple A6 7.24 342.12 1.42 iPad 2 1GHz ARM Cortex-A9 19.84 484.28 2.54 iPhone 4S 800MHz ARM Cortex-A9 24.76 605.71 3.15 Table 3: Average times required to transform a 640 × 480 greyscale image into ASCII art using a single core available on the device.

Time [ms] Device n=1 n=3 Tree-based Laptop 7.42 31.90 0.25 iPhone 5 33.36 252.43 0.58 iPad 2 88.32 679.12 1.01 iPhone 4S 118.12 913.94 1.21 Table 4: Average times required to transform a 640 × 480 color image into an image mosaic using a single core avail- able on the device.

from the different tile size. Our method is more than 100 times faster than other approaches [KSRY13,Tra99,ZNZ03] that utilize only the CPU.

5. Possible extensions When the codebook is very large and high accuracy is needed, a potential strategy to increase the approximation accuracy of our approach is to learn multiple trees with low correlation between them (i.e., a random forest [Bre01]). For example, this can be achieved by learning each tree on a sep- arate training set. During the rendering of a grid cell, each tree outputs a candidate tile from the codebook. Then, these tiles are ranked according to their similarity with the grid cell (using equation1 or2), and the best candidate is picked. This procedure is repeated for each cell in the image. The computation time scales linearly with the number of trees. Figure 12: The depiction of fine details is reduced due to However, we did not find this procedure necessary, as was the limited resolution and codebook size. also suggested by the surveys in tables1 and2. As noted by Tran [Tra99], a low tile variety within a local region makes a mosaic monotonous. This issue is clearly seen in Figure 11 in which neighboring tiles are usually the

c 2015 The Author(s) Computer Graphics Forum c 2015 The Eurographics Association and John Wiley & Sons Ltd. N. Markuš, M. Fratarcangeli, I. S. Pandži´cand J. Ahlberg / Fast Rendering of Image Mosaics and ASCII Art same. In case of video streams coming from webcams, this is cation and Sports of the Republic of Croatia, and by the hardly noticeable because the video frames are noisy and this European Union through ACROSS project, 285939 FP7- results in a low probability of two neighbouring tiles being REGPOT-2011-1. the same. In the general case, this issue can be improved by learning two decision trees on separate codebooks in a pre- References processing step. During rendering, each grid cell in the input image is assigned a black or white label in a checkerboard [aal] Aa-lib. http://aa-project.sourceforge.net/ pattern style (inspired by the duplicate reduction procedure aalib/. Accessed on March 2014.2,6 from [KSRY11]). Cells labeled as black are processed with [BBFG07]B ATTIATO S.,BLASI G.D.,FARINELLA G.M., the first tree and cells labeled as white are processed with GALLO G.: Digital mosaic frameworks – an overview. Com- puter Graphics Forum (2007).2 the second tree. In this way, neighbouring cells always have different tiles assigned to them (provided that the trees were [BG03]B LUNDO C.,GLANDI C.: Hiding information in image mosaics. Computer Journal (2003).2 learned on disjoint codebooks), while the computation time remains the same. Another possibility is to use a single tree [BG08]B LUNDO C.,GLANDI C.: Creating image mosaics with a surrounding matching scheme. Optical Engineering (2008).2 that keeps two labels in its nodes (the best and the second best one, assigned in the training process), and alter- [BP05]B LASI G.D.,PETRALIA M.: Fast photomosaic. In Poster proceedings of ACM/WSCG2005 (2005).3,4 nate between them during rendering. This procedure greatly reduces the probability of having same neighbouring tiles, as [Bre01]B REIMAN L.: Random forests. Machine Learning (2001).9 illustrated in Figure 13. Of course, modifications are possi- [CFP∗05]C ANTONE D.,FERRO A.,PULVIRENTI A.,REFOR- GIATO D.,SHASHA D.: Antipole tree indexing to support range search and k-nearest neighbor search in metric spaces. IEEE Transactions on Knowledge and Data Engineering (2005).3, 4 [CJKK13]C HOI Y.-S., JUNG S.,KIM J. W., KOO B.-K.: Real- time video photomosaics with optimized image set and gpu. Journal of Real-Time Image Processing (2013).3 [DER∗10]D IDYK P., EISEMANN E.,RITSCHEL T., MYSZKOWSKI K.,SEIDEL H.-P.: Apparent display res- olution enhancement for moving images. Transactions on Graphics (Proc. SIGGRAPH 2010) (2010).6 Figure 13: A modified duplicate reduction procedure from [FR98]F INKELSTEIN A.,RANGE M.: Image mosaics. In [KSRY11] ensures low probability of same neighbouring Electronic Publishing, Artistic Imaging, and Digital Typography, Lecture Notes in Computer Science. 1998.2 tiles in a 4-connected neighbourhood. This ensures greater diversity when the mosaic is seen from a short distance. [GG92]G ERSHO A.,GRAY R.M.: Vector Quantization and Sig- nal Compression. Kluwer Academic Publishers, 1992.4 [HKM∗97]H UANG J.,KUMAR S.R.,MITRA M.,ZHU W.-J., ble which would ensure even greater tile diversity. ZABIH R.: Image indexing using color correlograms. In CVPR (1997).3 6. Conclusions [HTF09]H ASTIE T., TIBSHIRANI R.,FRIEDMAN J.: The Ele- ments of Statistical Learning: Data Mining, Inference and Pre- The main contribution of our work is a simple and ele- diction. Springer New York Inc., 2009.4 gant method for rendering ASCII art and image mosaics [KGFC02]K LEIN A. W., GRANT T., FINKELSTEIN A.,CO- at very high speed. The method can be easily extended to HEN M. F.: Video mosaics. In Proceedings of the 2nd Inter- include other similarity mappings and other tile codebooks national Symposium on Non-photorealistic Animation and Ren- dering (2002).2 than the ones used in this paper. The implemented engine can achieve real-time frame rates on mobile devices. To [KP02]K IM J.,PELLACINI F.: Jigsaw image mosaics. Transac- tions on Graphics (Proc. SIGGRAPH 2002) (2002).2 the best of our knowledge, this has not been achieved be- fore. Our framework can be used as a non-photorealistic [KSRY11]K ANG D.,SEO S.,RYOO S.,YOON K.: A parallel framework for fast photomosaics. IEICE Transactions (2011).3, rendering method for computer games or as a video dis- 10 play technique on without a graphical user in- [KSRY13]K ANG D.,SEO S.,RYOO S.,YOON K.: A study terface. We have made the source code publicly available: on stackable mosaic generation for mobile devices. Multimedia https://github.com/nenadmarkus/n3ar. Tools and Applications (2013).2,6 [LS99]L EE D.D.,SEUNG H. S.: Learning the parts of objects Acknowledgements by non-negative matrix factorization. Nature (1999).2 [MJN11]M IYAKE K.,JOHAN H.,NISHITA T.: An interactive This research is partially supported by Visage Technologies system for structure-based art creation. In Proc. NICO- AB, Linköping, Sweden, by the Ministry of Science, Edu- GRAPH International 2011 (2011).2

c 2015 The Author(s) Computer Graphics Forum c 2015 The Eurographics Association and John Wiley & Sons Ltd. N. Markuš, M. Fratarcangeli, I. S. Pandži´cand J. Ahlberg / Fast Rendering of Image Mosaics and ASCII Art

[OK08]O RCHARD J.,KAPLAN C. S.: Cut-out image mosaics. In Proceedings of the 6th International Symposium on Non- photorealistic Animation and Rendering (2008).2 [OR08]O’G RADY P. D., RICKARD S. T.: Automatic ascii art conversion of binary images using non-negative constraints. In Proc. Irish Signals and Systems Conference (2008).2,6 [PQW∗08]P ANG W.-M., QU Y., WONG T.-T., COHEN-OR D., HENG P.-A.: Structure-aware halftoning. ACM Transactions on Graphics (Proc. SIGGRAPH 2008) (2008).2 [RPD10]R OSTEN E.,PORTER R.,DRUMMOND T.: Faster and better: A machine learning approach to corner detection. IEEE Transactions on Pattern Analysis and Machine Intelligence (2010).4 [Sil97]S ILVERS R. S.: Digital composition of a mosaic image, 1997. US Patent 6,137,498. URL: http://www.google. com/patents/US6137498.2 [Tra99]T RAN N.: Generating photomosaics: an empirical study. In ACM symposium on Applied computing (1999).1,2,3,6,9 [TTIN13]T AKEUCHI Y., TAKAFUJI D.,ITO Y., NAKANO K.: Ascii art generation using the local exhaustive search on the gpu. In 2013 First International Symposium on Computing and Net- working (2013).2,6 [WBSS04]W ANG Z.,BOVIK A.C.,SHEIKH H.R.,SIMON- CELLI E. P.: Image quality assessment: From error visibility to structural similarity. IEEE Transactions on Image Processing (2004).1,3 [XZW10]X U X.,ZHANG L.,WONG T.-T.: Structure-based ascii art. Transactions on Graphics (Proc. SIGGRAPH 2010) (2010).2,6 [ZNZ03]Z HANG Y., NASCIMENTO M.A.,ZAIANE O.R.: Building image mosaics: an application of content-based image retrieval. In International Conference on Multimedia and Expo (2003).2,3,6

c 2015 The Author(s) Computer Graphics Forum c 2015 The Eurographics Association and John Wiley & Sons Ltd.