Abstract
In this note, we introduce a function for calculating Euclidean distance transform in large binary images of dimension three or higher in Matlab. This function uses transparent and fast line-scan algorithm that can be efficiently implemented on vector processing architectures such as Matlab and significantly outperforms the Matlab’s standard distance transform function “bwdist” both in terms of the computation time and the possible data sizes. The described function also can be used to calculate the distance transform of the data with anisotropic voxel aspect ratios. These advantages make this function especially useful for high-performance scientific and engineering applications that require distance transform calculations for large multidimensional and/or anisotropic datasets in Matlab. The described function is publicly available from the Matlab Central website under the name “bwdistsc”, “Euclidean Distance Transform for Variable Data Aspect Ratio”.




Similar content being viewed by others
Notes
To see this latter point, assume that an ”on” point \(\mathbf{x}=(x,y,z)\) in \(\mathcal{I }\) is the closest to \(\mathbf{x}^*=(x^*,y^*,z^*)\). Clearly, then, \(\Vert \mathbf{x}^*-\mathbf{x}\Vert ^2_2=(z^*-z)^2 + \Vert (x^*,y^*)-(x,y)\Vert ^2_2\), and it is only necessary to make sure that \((x,y)\) is the point closest to \((x^*,y^*)\) in \(\mathcal{I }\) in the respective slice \(z\), so that \(\Vert (x^*,y^*)-(x,y)\Vert ^2_2\equiv D(x^*,y^*;z)^2\). Indeed, if this was not the case and there was another point \((x^{\prime },y^{\prime })\) in \(\mathcal{I }\) in slice \(z\) that was yet closer to \((x^*,y^*)\), then \((x^{\prime },y^{\prime },z)\) would also have to be closer to \((x^*,y^*,z^*)\) in 3D, and we have a contradiction.
References
Paglieroni, D.: Distance transforms : properties and machine vision applications, graphical models and image processing. CVGIP Graph. Model Image Process. 54, 56–74 (1992)
Baggett, D., Nakaya, M., McAuliffe, M., et al.: Whole cell segmentation in solid tissue sections. Cytometry Part A 67, 137–143 (2005)
Rosenfeld, A., Pfaltz, J.: Sequential operations in digital picture processing. J ACM 13, 471–494 (1966)
Rousson, M., Paragios, N., Deriche, R.: Implicit active shape models for 3D segmentation in MR imaging. MICCAI 3216, 209–216 (2004)
Town, C., Sinclair, D.: Content based image retrieval using semantic visual categories. Technical report (2001)
Gavrila, D.M.: Pedestrian detection from a moving vehicle. In: Vernon, D. (ed.) Computer Vission—ECCV 2000, pp. 37–49. Springer, Berlin (2000)
Breu, H., Gil, J., Kirkpatrick, D., Werman, M.: Linear time Euclidean distance transform algorithms. IEEE Trans. Pattern Anal. 17, 529–533 (1995)
Maurer, C., Qi, R., Raghavan, V.: A linear time algorithm for computing exact Euclidean distance transforms of binary images in arbitrary dimensions. IEEE Trans. Pattern Anal. 25, 265–270 (2003)
Tustison, N.J., Siqueira, M., Gee, J.C.: N-D linear time exact signed euclidean distance transform. Insight J. (2006) http://hdl.handle.net/1926/171
Guan, W., Ma, S.: A list-processing approach to compute Voronoi diagrams and the Euclidean distance transform. IEEE Trans. Pattern Anal. 20, 757–761 (1998)
Meijster, A., Roerdink, J.B.T.M., Hesselink, W.H.: A general algorithm for computing distance transforms in linear time. Comput. Imaging Vis. 18, 331–340 (2000)
Fabbri, R., da Fontoura Costa, L., Torelli, J.C., Bruno, O.M.: 2d Euclidean distance transform algorithms: a comparative survey. ACM Comput. Surv. 40 (2008)
Cuisenaire, O.: Distance transforms: fast algorithms and applications to medical imaging. Ph.D. Dissertation, Louvain-la-Neuve, Belgium (1999)
Verwer, B.J., Verbeek, P.W., Dekker, S.T.: An efficient uniform cost algorithm applied to distance transforms. IEEE Trans. Pattern Anal. 11, 425–429 (1989)
Ragnemalm, I.: Neighborhoods for distance transformations using ordered propagation. CVGIP Image Underst. 56, 399–409 (1992)
Eggers, H.: Two fast Euclidean distance transformations in \(z^2\) based on sufficient propagation. Comput. Vis. Image Underst. 69, 106–116 (1998)
Cuisenaire, O., Macq, B.M.: Fast Euclidean distance transformation by propagation using multiple neighborhoods. Comput. Vis. Umage Underst. 76, 163–172 (1999)
Falcao, A.X., Stolfi, J., de Alencar, S.: The image foresting transform intelligence theory, algorithms, and applications. IEEE Trans. Pattern Anal. 26, 19–29 (2004)
Porikli, F., Kocak, T.: Fast distance transform computation using dual scan line propagation. In: SPIE Conference Real-Time Image Processing, vol. 6496, February (2007)
Danielsson, P.-E.: Euclidean distance mapping. Comput. Vis. Graph. 14, 227–248 (1980)
Borgefors, G.: Distance transformations in arbitrary dimensions. Comput. Vis. Graph. 27, 321–345 (1984)
Svensson, S., Borgefors, G.: Distance transforms in 3d using four different weights. Pattern Recogn. Lett. 23, 1407–1418 (2002)
Strand, R., Borgefors, G.: Distance transforms for three-dimensional grids with non-cubic voxels. Comput. Vis. Image Underst. 100, 294–311 (2005)
Sethian, J.A.: A fast marching level set method for monotonically advancing fronts. Proc. Natl. Acad. Sci. 93, 1591–1595 (1996)
Watson, D.F.: Computing the n-dimensional Delaunay tessellation with application to Voronoi polytopes. Comput. J. 24, 167–172 (1981)
Aurenhammer, F.: Voronoi diagrams—a survey of a fundamental geometric data structure. ACM Comput. Surv. 22, 345–405 (1991)
Fortune, S.: A sweepline algorithm for Voronoi diagrams. Algorithmica 2, 153–174
Ogniewicz, R.L., Kubler, O.: Voronoi tessellation of points with integer coordinates time efficient implementation and online edge-list generation. Pattern Recogn. 28, 1839–1844 (1995)
Gavrilova, M.L., Alsuwaiyel, M.H.: Two algorithms for computing the Euclidean distance transform, IJIG, pp. 635–645 (2001)
Paglieroni, D.W.: A unified distance transform algorithm and architecture. Mach. Vis. Appl 5, 47–55 (1992)
Kolountzakis, M.N., Kutulakos, K.N.: Fast computation of the euclidean distance maps for binary images. Inform. Process. Lett. 43, 181–184 (1992)
Chen, L., Chuang, H.Y.H.: A fast algorithm for Euclidean distance maps of a 2-d binary image. Inform. Process. Lett. 51, 25–29 (1994)
Saito, T., Ichiro, Toriwaki J.: New algorithms for Euclidean distance transformation of an n-dimensional digitized picture with applications. Pattern Recogn. 27, 1551–1565 (1994)
Hirata, T.: A unified linear-time algorithm for computing distance maps. Inform. Process. Lett. 58, 129–133 (1996)
Felzenszwalb, P.F., Huttenlocher, D.P.: Distance transforms of sampled functions. Cornell Computing and Information Science. Technical report, September (2004)
Mishchenko, Y., Hu, T., Spacek, J., et al.: Ultrastructural analysis of hippocampal neuropil from the connectomics perspective. Neuron 67, 1009–1020 (2010)
Schena, G., Favretto, S.: Pore space network characterization with sub-voxel definition. Transp. Porous Med 70, 181–190 (2007)
Dima, T., Domingo, J., Dura, E.: A local level set method for liver segmentation in functional MR imaging. In: Proceedings of Nuclear Science Symposium and Medical Imaging Conference (NSS/MIC), pp. 3158–3161 (2011)
Kroon, D.-J.: Accurate Fast Marching, Toolbox, Matlab Central website, 23 June 2009
Kennedy, R.: Generalized distance transform, Toolbox, Matlab Central website, 26 May 2011
Author information
Authors and Affiliations
Corresponding author
Appendix: Proof of Lemma 1
Appendix: Proof of Lemma 1
Here, we present a formal proof of Lemma 1, namely that for a family of one-dimensional parabolas \(\mathcal F =\{F_{y}(x)=|x-y|^2 + g(y) \}\) and an arbitrary parabola \(f(x)=x^2 + b\) there can exist at most a single interval \((x_1,x_2)\) such that \(f(x)<\mathcal G (x)\), where \(\mathcal G (x)\) is the lower envelop of the parabolas in the family \(\mathcal F \).
We begin by noting that, in general, three possibilities can exist above: \(f(x)>\mathcal G (x)\) everywhere on \(x\); \(f(x)<\mathcal G (x)\) everywhere on \(x\); and \(f(x)<\mathcal G (x)\) at some points and \(f(x)>\mathcal G (x)\) at other points. The first two possibilities are obviously accommodated by assuming \((x_1,x_2)=\emptyset \) and \((x_1,x_2)=(-\infty ,\infty )\), respectively.
For the third case, taking into account continuity of \(\mathcal G (x)\) and\(f(x)\), there should exist at least one crossing point such that \(\mathcal G (x)=f(x)\). Let \(x_1\) be such a crossing point, \(\mathcal G (x_1)=f(x_1)\), and let \(F_{y_1}(x)\) be the parabola in \(\mathcal F \) such that \(\mathcal G (x)=F_{y}(x)\) at \(x=x_1\). We shall dismiss the trivial case \(F_{y_1}(x)\equiv f(x)\), in which case \(\mathcal G (x) = f(x)\) for the entire interval where \(\mathcal G (x)=F_{y_1}(x)\) and, thus, \(x_1\) cannot be a crossing point since \(\mathcal G (x) > f(x)\) nowhere in that entire interval. For a real crossing point, therefore, \(F_{y_1}(x) \not \equiv f(x)\) should hold. Then, by an obvious property of the intersection of the parabolas of the form given above, \(f(x)>F_{y_1}(x)\) necessarily on a single semi-interval \((-\infty ,x_1)\) or \((x_1,\infty )\), and therefore \(f(x)>F_{y_1}(x)\ge \mathcal G (x)\) on the same semi-interval. Without loss of generality we shall assume now that \(f(x)>\mathcal G (x)\) on the semi-interval \((-\infty ,x_1)\).
Let us now assume that \(x_2\) is another crossing point \(\mathcal G (x_2)=f(x_2)\), and \(F_{y_2}(x)\) is the parabola in \(\mathcal F \) such that \(\mathcal G (x)=F_{y}(x)\) at \(x=x_2\). In that case, by the same obvious property of the intersection of the parabolas in \(\mathcal F \) and \(f(x)\), \(f(x)>\mathcal G (x)\) necessarily on a single semi-interval \((-\infty ,x_2)\) or \((x_2,\infty )\). Since we already have that \(f(x)>\mathcal G (x)\) in \((-\infty ,x_1)\) while \(f(x_1)=\mathcal G (x_1)\), the only self-consistent possibility for \(x_2\) to be a crossing point is \(f(x)>\mathcal G (x)\) on \((x_2,\infty )\) while \(x_1<x_2\).
Note that it is impossible to self-consistently add a third crossing point \(x_3\), since that would imply that \(f(x)>\mathcal G (x)\) on either \((-\infty ,x_3)\) or \((x_3,\infty )\), and that would necessarily violate either \(f(x_1)=\mathcal G (x_1)\) or \(f(x_2)=\mathcal G (x_2)\), or \(f(x_3)=\mathcal G (x_3)\).
Therefore, there can be at most two crossing points for \(f(x)\) and \(\mathcal G (x)\), \(x_1\) and \(x_2\), and \(f(x)<\mathcal G (x)\) can be achieved on at most a single interval \((x_1,x_2)\), respectively.
Rights and permissions
About this article
Cite this article
Mishchenko, Y. A fast algorithm for computation of discrete Euclidean distance transform in three or more dimensions on vector processing architectures. SIViP 9, 19–27 (2015). https://doi.org/10.1007/s11760-012-0419-9
Received:
Revised:
Accepted:
Published:
Issue Date:
DOI: https://doi.org/10.1007/s11760-012-0419-9