00 th Intenational Wokshop on Cellula Nanoscale Netwoks and thei Applications (CNNA) Appoximating Euclidean Distance Tansfom with Simple Opeations in Cellula Pocesso Aas Samad Razmjooei and Piot Dudek School of Electical and Electonic Engineeing The Univesit of Mancheste Mancheste, UK Email: samad.azmjooei@postgad.mancheste.ac.uk, p.dudek@mancheste.ac.uk Abstact This pape pesents a new algoithm fo computing a distance tansfom, paticulal suitable fo massivel paallel cellula pocesso aas. The poposed Enhanced Cit Block Distance Tansfom (ECBDT) achieves good appoximation to Euclidean distances, opeating with incement and minimum opeations onl, and equiing onl local 4-neighbou communication. The distance values ae calculated in a wavepopagating manne, and ae suitable fo implementation on asnchonous pocesso aas. The pefomance of the algoithm is adjustable though paametes. Pesented simulation esults illustate the opeation of the algoithm, and discuss the accuac of the distance appoximation that is achieved in compaison to Euclidean, Cit Block, Chessboad and Chamfe distance tansfoms. I. INTRODUCTION In digital image pocessing, a map of distances is often equied in which all non-featue pixels ae assigned distance values to thei neaest featue pixels. The map is called the Distance Tansfom (DT). The exact distance between two points with coodinates of (x, ) and (x, ) can be calculated fom the Euclidean Distance fomula: D = ( x x ) + ( ) () Eu Calculating the Euclidean Distance Tansfom (EDT) is a global opeation, as fo each non-featue pixel a neaest featue pixel must be found and a distance calculated accoding to (). Theefoe the algoithms to geneate such distance map ae computationall intensive. Futhemoe, calculation of distances in pesence of obstacles is poblematic. To ovecome these poblems, othe distance metics such as Cit Block (Manhattan), Chessboad o Chamfe have been poposed to calculate the distance consideing onl small neighbouhoods []-[]. The tansfoms that appl these metics could be consideed as giving an appoximation to Euclidean distance with consideabl less complex algoithms [3]. In paticula, the ae suitable fo paallel implementation on cellula pocesso aas, such as [4]-[8]. In the paallel DT algoithms, global distances ae calculated b popagating local distance values. Among the poposed distance tansfoms algoithms, Cit Block Distance Tansfom (CBDT) is the simplest and fastest to be implemented. It equies onl incement and minimum opeations on a 4-connected neighbouhood. Howeve, the obtained distances diffe lagel fom Euclidean distances. This ma be undesiable in man applications. Chessboad DT is simila in this espect. Chamfe DT is a bette appoximation to Euclidean distance, but it equies a geate numbe of moe complex opeations (including multiplication and usuall lage neighbouhoods) to calculate the distances []-[]. In this pape, a paallel DT algoithm is poposed that etains the simplicit of CBDT, but gives a consideabl bette appoximation to EDT. The algoithm can be executed iteativel on snchonous Single Instuction Multiple Data (SIMD) fine-gain pocesso aas; it can also take advantage of asnchonous wave-popagating opeations available on some cellula pocesso aa hadwae [4]. In the next section, the paallel implementation of CBDT is oveviewed. In Section III, the poposed Enhanced Cit Block DT (ECBDT) is intoduced and the methods of evaluating the esults ae pesented. The expeimental esults ae discussed in Section IV and conclusions ae in Section V. The algoithm is designed fo massivel paallel cellula pocesso aas, howeve the expeiments and simulations pesented in this pape have been conducted in MATLAB. II. CITY BLOCK DISTANCE TRANSFORM The CBDT measues the distance between the pixels based on the fou diect neighbous (Noth, East, West, and South). The local distance value between a pixel and its diect neighbou is equal to one. The Cit Block distance between pixels with coodinates of (x, ) and (x, ) is calculated b: D = x x + () CB To calculate the CBDT of a bina image, initiall the values of all the non-featue pixels ae changed to infinit (o a suitabl lage numbe) and the featue pixels ae set to zeo []. The distance map is deived though iteations. In each iteation the distance values of diect neighbous ae incemented b one: P = min( P, P +, P +, P +, P + ) (3) n n n n n n + x, x+, n whee P is the distance value of the pixel in position ( ) at iteation n. This pocess is epeated until convegence. The 978--444-6678-8/0/$6.00 00 IEEE
If ( ) is a MC P = min( P, P, P, P, P ) (5) n n n n n n + x, x+, Fo example, conside the aa shown in Fig. 3, with one featue pixel in the cente. Some of the cells ae maked as MCs. Regula backgound pixels have thei DT values incemented with espect to thei smallest diect neighbous, while the DT values of MCs ae equal to thei smallest neighbous. Figue. Popagation of local distances in distance map. distance values ae popagated fom the bounda of the featue pixels to the neighbous until the distances fo all the pixels ae calculated. Fig. illustates an example of the popagation of CBDT fo a bina image which consists of one featue pixel in the cente. The distance values in the DT matix ae shown using a ga-level scale. It should be noted that the discete-time iteations in (3) can be eplaced b a continuous-time pocess, whee the update equation is constantl evaluated. Pocessos such as ASPA [4] ae capable of pefoming such opeations and consequentl the popagation of distances, as illustated in Fig., is asnchonous. The sstem alwas conveges to the same solution, iespective of popagation speed. As compaed with Euclidean distance, CBDT oveestimates the distances fo pixels located diagonall fom thei neaest featue pixels. This can be cleal seen in Fig. (b) as a distotion fom the ideal isotopic distance map shown in Fig (a). Hee we popose Enhanced Cit Block Distance Tansfom (ECBDT), which opeates with + and minimum opeations onl, simila to CBDT, but povides a much bette appoximation to the Euclidean DT (see Fig. (c)). (a) (b) (c) (d) Figue. Distance Tansfoms of a bina image of 5x5 with one simple featue pixel in the cente. (a) Euclidean Distance. (b) CBDT. (c) ECBDT (Scaled). (d) The ga-level ba epesents the distance values. Given that the distance values ae calculated in an iteative manne b popagating the local distances, a MC can impact all the cells that have thei DT value depending on it. Fig. 4 illustates how the DT esult can be andoml distoted as the numbe and location of the MCs in the matix is vaied. Figue 3. The effect of MCs on the DT. Fou pixels ae maked as MCs. III. ENHANCED CITY BLOCK DISTANCE TRANSFORM A. Masked-Cells The Masked-Cells (MCs) in the calculation of a DT ae defined hee as cells that have thei DT values equal to the minimum value of thei diect neighbous. When calculating thei modified CBDT, the MC update does not equie an incement. Equations (4) and (5) ae thus used to update the DT values in iteation n, depending on whethe the pixel is a MC o not: If ( ) is not a MC: P = min( P, P +, P +, P +, P + ) (4) n n n n n n + x, x+, (a) (b) (c) (d) Figue 4. The effect of MC on matix of x with one featue pixel in the cente. (a) CBDT with no MCs. (b) 0% of MCs. (c) 0% MCs; (d) The galevel ba epesents the distance values. B. ECBDT Algoithm To compute the ECBDT we use numbe of andom pattens (k) of specific densit of MCs (p), and appl the modified CBDT fo each patten, iteating equations (4) and (5) until
convegence. As andom MC locations lead to andom distotions of the modified CBDTs matix fo each patten, we finall aveage the esults to educe the eo. The pseudo-code implementing this algoithm is shown in Fig. 5. Povided the pocessing hadwae is capable of fast popagation of distance values, calculating multiple modified CBDTs can be easil pefomed, within a easonable execution time. Fig. (c) illustates the DT esults when ECBDT has been pefomed fo p=50% of MCs on k=00 andoml selected pattens. As it can be seen in Fig., the esult of ECBDT appeas qualitativel close to the EDT than the CBDT esult. In the following sections we quantif this, and analse the eo with espect to ECBDT paametes such as MCs densit and numbe of aveages. ECBDTs applied to a mati when two diffeent sets of paametes have been used. Distances to a cente pixel ae calculated. The esulting equidistant pixels fo distances of 0, 0 and 30 (solid contous) and Euclidean equidistant pixels (dashed contous) ae shown on both DTs fo compaison. It can be seen that the absolute eo of DT shown in Fig.6(a) is smalle than that of DT shown in Fig.6(b). Howeve, distances in the hoizontal diection ae undeestimated while those calculated diagonall ae oveestimated. On the othe hand, the esult in Fig.6(b) has a lage oveall absolute eo. Howeve, it has a desiable popet that equidistant pixels ae foming contous much close in shape to the ideal cicles of EDT. SumDT=0 Fo to k do // matix accumulating the DT esults // k is numbe of aveages G=Geneate Random Patten ( p) //p is densit of MCs D = DT(Input, G) //Find the DT accoding to (4),(5) SumDT= SumDT + D Next //Accumulate esults ECBDT(k, p) = SumDT / k //Calculate aveage Figue 5. The pseudo-code to compute the ECBDT. C. Eo Calculation Two methods ae intoduced to calculate the eo: ) Absolute Eo: To quantif the absolute eo ε abs between ECBDT and EDT, the RMS eo is calculated acoss the DT matix. ε (6) n m ' abs = ( αabspx, Px, ) n m x= = whee n, m ae numbe of ows and columns of the bina image espectivel; P and P ae esult of EDT and ECBDT, espectivel, at position ( ). Since the intoduction of MCs leads to a sstematic undeestimate of the distance values in the DT mati an absolute scaling facto α abs is intoduced. The value of α abs is defined as the optimal value that compensates the gain eo in the DT calculation, i.e. the value that minimizes the absolute eo (ε abs ) given b (6). ) Relative Eo: The absolute eo gives a good indication of the oveall diffeence between EDT and ECBDT. Howeve in man applications the absolute eo is less impotant than the unifomit of the DT esult acoss oientations, i.e. a elative eo between equidistant pixels (in a Euclidean sense) and the DT esult. Fig. 6 illustates two (a) Figue 6. Compaing the equidistant pixels between scaled ECBDT (solid) and EDT (dashed); Diffeent ECBDT paametes ae used in two cases: (a) k=500, p=5%, esults in ε abs=.6; (b) k=500, p=50%, esults in ε abs =.3. To quantif the elative eo we use the following method. Distance tansfoms (ECBDT and EDT) ae calculated fo an image with a single featue pixel in the cente. A numbe (M) of concentic cicles, centeed on the featue pixel, ae selected. In the expeiments the adius of the cicles is chosen with step s=5 pixels i.e. 5, 0, 5 etc (see Fig. 7). Fo each cicle, a elative scaling facto α is calculated: α = C x, C P Whee () C ae a set of N points ling on a cicle C with adius s, (see Fig. 7); Px, and P x, ae the calculated ECBDT and EDT values, espectivel, at position ( ). Fo each cicle, the vaiance is then calculated accoding to (8) and finall the elative eo ε el is calculated consideing all cicles, accoding to (9). P N C (b) (7) = ( α P P ) (8) M ε el = (9) M =
5 4 3 Figue 7. Calculating the vaiance. ECBDT shown on the left and EDT shown on the ight. In this example, i.e. M=5, s=5 and =,, 3, 4, 5. IV. EXPERIMENTAL RESULTS All numeical expeiments epoted in this section, have been pefomed on a bina image of 0x0 having one featue pixel in its cente. The ECBDT esult depends on two paametes, the densit of MCs, p, and the numbe of aveages, k. Fig. 8 illustates how the ECBDT esult changes with these paametes. A lage k esults in smooth equidistant contous, while lage p impoves thei ciculait. Fo smalle p, the contous have distoted shapes (esembling CBDT). The become moe cicula, but moe nois, as p is inceased. The execution time of the algoithm will be diectl popotional to k, and independent of p. To investigate which p and k might be most optimal, the eos have been calculated b sweeping these paametes, as shown in Fig. 9. Since the esult of ECBDT is nondeteministic, the plots in Fig. 9 ae based on the mean values of the eos, aveaged acoss man tials. In case of a small numbe of aveages, the eo values calculated using (6) and (9) exhibit lage standad deviation, as shown in the example in Fig. 0. Fom the plot of εabs in Fig. 9 it can be seen that depending on k, about 0-5% of MCs esults in lowe absolute eo and consequentl gives a close oveall appoximation to EDT. When we conside the elative eo, it can be seen that Figue 9. Absolute eo (ε abs) and elative eo (ε el) vs. densit of MC (p) fo diffeent numbe of aveages (k). the optimal densit of MCs becomes lage as the numbe of aveages inceases. Fig. 9 can be used as a guide to select the appopiate paametes in pactical applications. Fig. illustates how the absolute scaling facto changes against the densit of MCs. As we ae inceasing p the scaling facto inceases. The gaphs in Fig. show elative scaling facto against distance values in ECBDT, fo diffeent p. Aveaging has been pefomed ove k=500 andom pattens. As the numbe of MCs is inceased, the distances calculated using ECBDT become moe nonlinea with espect to EDT. The nonlineait of distance values in ECBDT can be obseved in Fig. 6 (b); while the inne contou is smalle than its EDT countepat, the oute contous is bigge. The plot in Fig. can be used to compensate the non-lineait, fo example using a look-up table, if equied b the application. p=5% p=0% p=40% p=65% k=3 k=00 Figue 8. ECBDT esult fo diffeent paametes. k is numbe of aveages and p is densit of MCs. Equidistant contous ae shown. Fo small p the DT is simila to CBDT. As p is inceased, it is possible to achive a DT ve close to EDT in tems of ciculait. Inceasing k educes the noise.
Figue 0. Absolute eo fo small numbe of aveages, k=3. Dashed lines follow eo bas showing standad deviation of the value calculated using (6) acoss man uns of the ECBDT. V. COMPARISONS AND CONCLUSION Table shows a compaison of the pefomance of seveal DTs. The second and thid columns compae the absolute eo and the elative eo fo diffeent tpes of DTs. The ECBDT gives a clea impovement in the qualit of appoximation to EDT, in compaison to CBDT and Chessboad DT. Chamfe DTs can give a bette appoximation but equie moe complex opeations. The advantage of ECBDT is in that it can achieve a ve good appoximation to EDT using onl a simple set of aithmetic opeations on neaest neighbous and using limited hadwae esouces. In paticula, all steps of the algoithm (geneation of a andom map, calculation of a modified CBDT, aveaging of esults) can be caied out using onl a few memo elements pe pixel, which makes the algoithm suitable fo execution on pixel-level cellula pocesso aas. The ECBDT is flexible in the sense that depending on the application, the pecision of the output DT and the speed of the algoithm can be defined b the densit of MCs and numbe of aveages. If an application equies speed, then appoximatel 0% of MCs and a low numbe of aveages (e.g. k=3 o k=5) can be applied, with good esults. If the elative distances ae a matte of inteest in an application, then a lage numbe of aveages and MCs should be used. The execution speed of ECBDT depends on the actual implementation. When implemented on cellula pocesso aas which ae capable of apidl iteating equations (4) and (5), especiall on pocessos that suppot asnchonous data popagations involving min and + opeations, the ECBDT can povide a bette pefomance than othe methods of appoximating Euclidean distance tansfom. Figue. Absolute scaling facto (a abs ) vs. densit of Masked-Cells (p). REFERENCES Figue. Relative scaling facto (a ) vs. distance value fom cente fo diffeent densit of MCs Table. Compaing the DTs to ECBDT DT ε ε abs el Speed Cit Block DT(CBDT) 7.7 6.0 Ve fast Chessboad DT 3.8 5.9 Ve fast Chamfe DT (3-4) 3.0.7 Fast Chamfe DT (5-7-) 0.8 0.6 Slow ECBDT (k=5, p=0%) ±0.5 0.46±0. Fast ECBDT (k =50, p =35%).8±0. 0.5±0. Slow ECBDT (k =00, p =40%). 0.8 Slow [] G. Bogefos, Distance tansfom in digital image, Compute Vision, Gaphics and Image Pocessing. 34, pp. 344-37, Feb. 986 [] A. Rosenfield and J. L. Pfaltz, Distance function on digital pictues, Patten Recognition, Pegamon Pess 968, Vol., pp. 33-6, Oct. 967 [3] Pe-Eik Danielsson, Euclidean distance mapping, Compute Gaphics and Image Pocessin 4,, pp. 7-48, Feb. 980 [4] A. Lopich and P. Dudek, ASPA: Focal Plane Digital Pocesso Aa with Asnghonous Pocessing Capabilities, ISCAS 008, pp 59-596, Ma 008. [5] P.Dudek and P.J.Hicks, "A Geneal-Pupose Pocesso-pe-Pixel Analog SIMD Vision Chip," IEEE Tansactions on Cicuits and Sstems - I, vol. 5, no., pp. 3-0, Janua 005 [6] G. Linan, R. Dominguez-Casto, S. Espejo and A. Rodiguez-Vazquez, ACE6k: a pogammable focal plane vision pocesso with 8x8 esolution, ECCTD 00, pp 345-348, August 00. [7] T. Komuo, S. Kagami, I. Ishii and M. Ishikawa, Device and Sstem Development of Geneal Pupose Digital Vision Chip, Jounal of Robotics and Mechatonics, Vol., No.5, pp.55-50 (000) [8] J. Flak, M. Laiho, A.Paasio, K. Halonen, Dense CMOS implementation of a bina-pogammable cellula neual netwok. Int. Jounal of Cicuit Theo and Applications, 006. 34(4): p. 49-443.