Distance and nearest neighbor transforms on gray-level surfaces Leena Ikonen * , Pekka Toivanen Lappeenranta University of Technology, Department of Information Technology, Laboratory of Information Processing, P.O. Box 20, 53851 Lappeenranta, Finland Received 7 September 2005; received in revised form 27 July 2006 Available online 8 December 2006 Communicated by G. Borgefors Abstract This article presents an efficient priority pixel queue algorithm for calculating the distance transform on curved space (DTOCS), the corresponding nearest neighbor transform, and the new projection DTOCS (PDTOCS). The transforms provide tools for approximating distances and finding shortest paths on gray-level surfaces. Surface variation, or roughness, can also be measured. Ó 2006 Elsevier B.V. All rights reserved. Keywords: Distance transforms; Gray-level distance transforms; Nearest neighbor transforms; Geodesic distances; Minimal geodesics; Surface roughness 1. Introduction The distance transform on curved space (DTOCS) cal- culates distances along a gray-level surface. The shortest paths found resemble geographical minimal geodesics, as paths are constrained to the top surface of the gray-level height map, like geodesics are constrained to the surface of the earth. The path between two proximate pixels can be long, if there is a high ridge or deep valley in the gray- level ‘‘terrain’’ between them. The DTOCS fits well into the definition of a geodesic distance given by Soille (2003): ‘‘In image analysis, geodesic distances are used wherever paths linking image pixels are constrained to remain within a subset of the image plane’’. The con- strained distance transform of binary images discussed by Piper and Granum (1987) can be viewed as a special case of geodesic distance transforms. The background is restricted, and the foreground is the so called geodesic mask, which defines the areas, in which the paths must remain. In this work, the gray-level surface acts as the geo- desic mask, constraining the paths to remain at certain heights in the 3D scene represented as a gray-level height map, or range image. The binary image, which defines the feature or reference pixels, from which distances are calculated, is transformed into the distance image. Gray-level distance transforms typically compute mini- mal cost paths, where the gray-value of a pixel represents the cost of traversing the pixel. In the geodesic time dis- tance transform by Soille (1994), the local distance between neighbor pixels is defined as the average of their gray-val- ues. Thus, the geodesic time between consecutive pixels p i and p i1 on a digital path is d ðp i ; p i1 Þ¼ 1 2 ðGðp i Þþ Gðp i1 ÞÞtðp i ; p i1 Þ; ð1Þ where GðpÞ is the gray-value of pixel p, and t(p i , p i1 ) = 1. The same equation applies to the gray-weighted distance by Levi and Montanari (1970) in the 8-neighborhood, but with t(p i , p i1 ) = 1, when pixels p i and p i1 are horizon- tal or vertical neighbors, and tðp i ; p i1 Þ¼ ffiffi 2 p for diagonal neighbors. Thus, the Euclidean distance between the pixel centers is included in the gray-weighted distance in addi- tion to the gray-values. In both transforms, the gray-level image constrains the distances to follow as low-lying paths as possible. The fuzzy geodesic distance by Bloch (2000) follows as high-lying paths as possible on a surface, where 0167-8655/$ - see front matter Ó 2006 Elsevier B.V. All rights reserved. doi:10.1016/j.patrec.2006.10.010 * Corresponding author. E-mail address: leena.ikonen@lut.fi (L. Ikonen). www.elsevier.com/locate/patrec Pattern Recognition Letters 28 (2007) 604–612