An nteractve system for structure-based ASCII art creaton Katsunor Myake Henry Johan Tomoyuk Nshta The Unversty of Tokyo Nanyang Technologcal Unversty Abstract Non-Photorealstc Renderng (NPR), whose am s to create artstc style mages, s one of the mportant research topcs n computer graphcs. One example of NPR s an art form called ASCII art whch represents pctures usng character strngs. ASCII art s commonly used n meda that cannot dsplay mages or manly use text, such as e-mal and bulletn board system. ASCII art can be categorzed nto two styles, tone-based style and structure-based style. The structurebased style can represent content by usng less number of ASCII characters compared to the tone-based style. However, n general, t takes begnners a long tme to create structurebased ASCII art. As such, an automatc method that creates structure-based ASCII art s requred to reduce the tasks of ASCII art creaton. In ths paper, we propose an nteractve system whch creates structure-based ASCII art. We provde four matchng metrcs for convertng an mage nto an ASCII art.based on expermental results, we found that the sutable matchng metrcs to produce vsually pleasant ASCII art mages depend on the type of the nput mages. Snce our system can produce ASCII art mages n a few seconds, users can create several ASCII art mages usng dfferent matchng metrcs, then select the one they lke the most. 1 Introducton ASCII art s one type of artstc style mages. It represents vsual nformaton usng character strngs whch consst of 95 ASCII prntable characters. ASCII s a character-encodng scheme, and s the acronym of Amercan Standard Code for Informaton Interchange. ASCII art does not focus on photorealsm. ASCII art s a popular art n cyberspace. We can see many ASCII art n varous meda whch manly use text, such as emal and BBS on the Web. In Japanese BBS, we can see many ASCII art that represent outlne of anmaton characters. ASCII art can be categorzed nto two styles, tone-based style and structure-based style (Fgure 1). Tone-based ASCII art uses the densty of glyph to represent the ntensty dstrbuton of content. Structure-based ASCII art uses the lne of glyph to represent the lne structure of content, and can represent content by usng less number of ASCII characters than tone-based ASCII art. As a result, structure-based ASCII art s often used n emal and BBS. Most of these ASCII art are made manually. However, t s dffcult for begnners to create structure-based ASCII art. As such, we propose an nteractve system for creatng structure-based ASCII art. (a) Tone-based style (b) Structure-based style Fgure 1: Examples of two styles. Our ASCII art creaton framework conssts of a preprocessng step and an ASCII art creaton step. In the preprocessng step, we prepare glyph mages of ASCII prntable characters by rasterzng an outlne font. The glyph mages are of the same sze. For ASCII art creaton, the nput mages of our system are black-and-whte mages where the background s whte and the content s black. Our system also allows users to perform drawng. To create the ASCII art mage of an nput mage, we frst dvde the nput mage nto grds whch are of the same sze as the glyph mages. We call these grds as blocks. Then, we perform glyph matchng whch s a process of calculatng the smlarty between the blocks of the nput mage and glyph mages. For each block, we put the best matchng glyph n t. We perform ths process for every block of the nput mage. For block and glyph matchng, we apply four matchng metrcs. The frst one s template matchng where we calculate the dfference between the values of same poston pxels n the block and glyph mage, then we calculate the dssmlarty by usng the Sum of Absolute Dfference. The second metrc s normalzed cross-correlaton where we calculate the smlarty between the hstograms of the dstrbuton of black pxels. The thrd one s Hstogram of Orented Gradents (HOG) where we frst determne HOG by calculatng the gradent at each pxel, then we calculate dfference between two HOGs. The last metrc s dstance transformaton where we calculate the dstance transformaton mage of the block and measure the dstance of the glyph mage to the dstance transformed mage. Results of template matchng and NCC are good f lnes of nput mages are thck. Results of HOG can represent lne drectons. Results of dstance transformaton can represent lne postons.
2 Related Work There are some exstng software programs for generatng ASCII art, such as AA-lb [1]. Most of these programs create the tone-based ASCII art usng a half-tonng method. Ths method represents nput mages usng the lne densty pattern of glyphs. Results of AA-lb are smlar to half-tonng results. However, AA-lb uses varyng brghtness font. O Grady and Rckard [2] proposed a method to convert bnary mages nto tone-based ASCII art usng Non-negatve Matrx Factorzaton. Ths method whch uses Non-negatve Matrx Factorzaton mnmzes the dfference between nput mages and glyphs n a pxel-by-pxel manner. The computatonal cost of ths method s hgh. Xu et al. [3] presented a method to create structure-based ASCII art. Ths method uses algnment-nsenstve shape smlarty metrc whch s smlar to shape context, and uses deformaton by adjustng the vertex postons of mage polylnes. To tolerate msalgnment, ths method used a hstogram of a log-polar dagram. However, t s hgh computatonal cost to optmze polylnes of nput mage. 3 User Interface A purpose of our system s the creaton of ASCII art from nput mages or drawn mages by users n real-tme. Users draw an llustraton n the left area (Fgure 2). Then, our system shows the result of ASCII art as text data n the rght area. Users can also change the glyph of the results by choosng from dsplayed canddates. Fgure 2: The user nterface of the proposed system. The left area s the drawng area. The rght area dsplays the result of ASCII art. between the nput mage and glyph mages at each block. We set the glyph whch s consdered the best glyph by matchng a block as one glyph of ASCII art strng. We execute ths process for every block. We descrbe four methods whch are used n the matchng process n the followng sectons. 4.1 Template Matchng We apply template matchng to our method for calculatng dssmlarly measure between a block of an nput mage and glyph mages. Ths method consders pxel postons of mages, whle half-tonng method consders the average value of brghtness per block. Therefore, template matchng s consdered as a method that can represent the lne feature of nput mage. We calculate dssmlarly measure by usng Sum of Absolute Dfference (SAD). SAD between a block and a glyph, f dff s calculated usng the followng equaton. f dff = heght j wdth I(, j) G(, j), (1) where I and G are the brghtness values of a block of an nput mage and a glyph mage, and j are the coordnates of pxel poston. heght and wdth are the szes of blocks. We calculate f dff usng every glyph mages at the block. The glyph whose value of SAD s the lowest n glyph s set as a glyph of ASCII art strng. 4.2 NCC wth Hstogram of Image Grd Template matchng usng SAD s nfluenced by the dfference between an nput mage and glyph mages n lne wdth. In ths secton, we ntroduce a method mnmzng the nfluences of dfference n lne wdth. We also descrbe Normalzed Cross-Correlaton (NCC) whch calculates smlarty measure, whle SAD represents dssmlarly measure. To mnmze the nfluence of the dfference of the lne wdth, we make a hstogram of an mage block. Ths hstogram represents the number of black pxels n a block. To make a hstogram of an mage block, we dvde the block usng small grds (Fgure 3). In each grd, we count the number of black pxels, and set the number n the same grd of the hstogram. 4 Matchng Method We descrbe the outlne of glyph matchng. Glyph matchng s the process of matchng whch compares an nput mage wth glyph mages. The nput of our method s a raster mage. Frst, the nput mage s subdvded nto grds whch are of the same sze as the glyph mages. In ths paper, these grds are called blocks. Second, we execute glyph matchng whch calculates smlarty measure or dssmlarly measure Fgure 3: Image block: Black grds are pxels, and red grds are clusters of pxels for hstogram countng.
NCC [4] s a method that calculates smlarty measure. NCC between a block and a glyph mage, f sm s calculated usng the followng equaton. f sm = grds grds H block ()H glyph () grds H block () 2 H glyph () 2, (2) where H block and H glyph are the hstograms of a block of an nput mage and a glyph mage. grds represent the set of grds n a block. Calculatng the NCC value of every glyph mage, the glyph whose f sm s the hghest s regarded as the best matchng grd for the block. The closer f sm s to 1, the more smlar are the two hstograms. 4.3 Hstogram of Orented Gradents In ths secton, we ntroduce the computaton of Hstogram of Orented Gradents (HOG) [5], and descrbe a matchng method usng HOG. Frst, we calculate gradent magntude, m(, j) and orentaton, θ(, j) at each pxel of mages usng the followng equatons. m(, j) = f x (, j) 2 + f y (, j) 2, (3) ( ) θ(, j) = tan 1 fy (, j), f x (, j) (4) where f x and f y are the frst order dervatves of horzontal and vertcal drectons. After calculaton, we dvde mages by 5x5 pxels grd called cell. We create an orentaton hstogram whch conssts of nne cells. We make an orentaton vector by usng HOG blocks whch consst of 3x3 cells (Fgure 4), and we normalze the vector. D HOG = Dmenson (H H g ) 2, (5) where H and H g are HOGs of block of an nput mage and a glyph mage. We set the glyph whch has the smallest mean square error as a glyph of ASCII art. 4.4 Dstance Transformaton In ths secton, we descrbe a matchng method usng dstance transform. Dstance transformaton s a method whch creates the dstance map from nput mages (Fgure 5). The pxel value n a dstance map s defned as the dstance between the pxel and the nearest pxel of 0 value n the nput mage. We calculate the dstance between a block of nput mage and glyph mages usng dstance transformaton. We calculate the dstance between a block and glyph mage, D g usng the followng equatons. D g = heght j wdth I DT (, j)g(, j), (6) where I DT s the value of the dstance map of the block, and G s the brghtness value of glyph mage. We defne the glyph whose dstance s the smallest n glyphs as the glyph of ASCII art. (a) Input mage (b) Dstance map Fgure 5: Examples of dstance transformaton. 5 Results Fgure 4: HOG block conssts of 3x3 cells. For calculatng an orentaton hstogram at each HOG block, the center cell of HOG block s movng to the next cell n the drecton of the arrows. We make a feature vector from all HOG blocks. If there s n HOG blocks n an mage, the feature vector of HOG has 9n dmensons. The dfference between HOGs, D HOG s calculated usng the followng equaton. We show the results of our system. Our system s mplemented usng the C language and usng the OpenCV lbrary [6]. The experments shown n ths paper were conducted usng a PC wth an Intel Core 2 Duo 2.0 GHz CPU wth 2.0GB man memory, and an NVIDIA GeForce 9400M GPU. We show the nput mages and the results usng the matchng methods n Fgures 6 to 10. The resoluton of the Bear mage s 720x960 pxels. The resoluton of the Shapes mage s 512x528pxels. The szes of the glyphs are 16x32pxel.
(a) Bear (b) Shapes Fgure 7: The results of template matchng. Fgure 6: Input mages.
Fgure 8: The results of NCC. Fgure 9: The results of HOG.
Our method s faster compared to the method proposed by Xu et al. [3] whch takes about 10 mnutes (Table 1). As the result, our system allows users to nteractvely create ASCII art mages. Table 1: Computatonal tme usng the four matchng metrcs. Computatonal tme (sec) Bear Shapes Template matchng 0.43 0.15 NCC 0.41 0.12 HOG 1.56 0.49 Dstance Transformaton 0.36 0.12 6 Conclusons and Future Work In ths paper, we have proposed an nteractve system whch creates structure-based ASCII art n a few seconds from mages or llustratons whch are drawn by users usng mage gradent and dstance transformaton. In our system, users can see the results mmedately. Our system allows users to also edt the glyphs of the results by choosng from dsplayed canddates. Based on expermental results, we found that the sutable matchng metrcs to produce vsually pleasant ASCII art mages depend on the type of the nput mages. Therefore, we need to have objectve evaluatons by user test. We wll have users choose the best results for nput mages. We would lke to create ASCII art whch conssts of proportonal font. The glyphs of proportonal font are of dfferent wdth sze. ASCII art of proportonal font are often used n Japanese bulletn board system, such as 2channel. References [1] Jan Hubcka. AA-lb. http://aa-project.sourceforge.net/aalb/. [2] Paul D. O Grady and Scott T. Rckard. Automatc asc art converson of bnary mages usng non-negatve constrants. In Proceedngs of the Irsh Sgnal and Systems Conference, pages 186 191, 2008. [3] Xuemao Xu, Lnlng Zhang, and Ten-Tsn Wong. Structure-based asc art. ACM Transactons on Graphcs (SIGGRAPH 2010 ssue), 29(4):52:1 52:9, July 2010. Fgure 10: The results of dstance transformaton. [4] Ka Brechle and Uwe D. Hanebeck. Template matchng usng fast normalzed cross correlaton. In Proceedngs of SPIE, volume 4387, page 95, 2001. [5] Navneet Dalal and Bll Trggs. Hstograms of orented gradents for human detecton. In IEEE Conference Computer Vson and Pattern Recognton, pages 886 893, 2005. [6] Intel Corporaton and Wllow Garage. OpenCV. http://opencv.wllowgarage.com/.