distance transforms
dt = bwdist(img [,algorithm])
Function bwdist computes the distance transform. For each foreground pixel (i.e. value '1') in the input image, the distance transform assigns a value that is the smallest distance between that pixel and the all the 0-pixels (you can also think of the distance to the outer boundary of the object).
Many different methods are provided for comparison purposes. If you are going to use bwdist extensively, you may test all the algorithms to find the best one for your particular type of image.
xset('auto clear', 'on'); // First, a simple example to illustrate the concept A = zeros(15,10); A(4:12,3:7)=1; A(4:5,3:4)=0 D = bwdist(A) D = sqrt(D) // Note how the values in D were calculated. // For each pixel p such that A(p)=1, D(p) is the minimum euclidean // distance of p and the 0-pixels (background). // ----------------------------------- // Now to a more interesting example // ----------------------------------- A = gray_imread(SIPDIR + 'images/escher.png'); imshow(A,2); D = bwdist(A); imshow(log(1+D),[]); // normalizes image to enhance visualization D = bwdist(A,'exact dilations'); imshow(log(1+D),[]); // To obtain an external EDT, simply invert the shape: B = 1-A; D = bwdist(B,'maurer'); imshow(log(1+D),[]); // To obtain an external+internal EDT, simply compute // the binary border of the shape and pass its negative // to bwdist: A = bwborder(A); A = 1-A; D = bwdist(A,'lotufo-zampirolli'); imshow(log(1+D),[]); // --------------------------------- // Other forms to visualize the DT // --------------------------------- // Wrapping (note the wavefronts of iso-distance) imshow(modulo(sqrt(D),10),[]) // Usual: D = bwdist(A); D = normal(sqrt(D),1000,1); imshow(D,hotcolormap(1000)); // There is also of DT application in the example for the "watershed" // function. xset('auto clear', 'off'); |
The original image and its distance map:
The distance map of the border (yielding non-zero distances inside and outside), and the propagating wavefronts:
Maurer, C.R. and R. Qi and V. Raghavan, "A Linear Time Algorithm for Computing the Euclidean Distance Transform in Arbitrary Dimensions", IEEE Transactions on Pattern Analysis and Machine Intelligence, vol. 25, no. 2, pp. 265-270, february 2003.
A. Meijster, J.B.T.M. Roerdink, and W.H. Hesselink "A General Algorithm for Computing Distance Transforms in Linear Time", proc. of 5th Int. Conf. Mathematical Morphology and its Applications to Image and Signal Processing, 2000
Cuisenaire, O and Macq, B, "Fast Euclidean Distance Transformation by Propagation Using Multiple Neighborhoods", Computer Vision and Image Understanding, no. 2, vol 76, 163--172, 76, 1999.
Chapter 3 of "Distance transformations: fast algorithms and applications to medical image processing", Olivier Cuisenaire's Ph.D. Thesis, October 1999, Université catholique de Louvain, Belgium.
"Multiscale Skeletons by Image Foresting Transform and its Application to Neuromorphometry", A.X. Falcao, L. da F. Costa, B.S. da Cunha, Pattern Recognition, 2002.
R. Lotufo and F. Zampirolli, Fastmultidimensional parallel euclidean distance transform based on mathematical morphology, in T. Wu and D. Borges, editors, Proccedings of SIBGRAPI 2001, XIV Brazilian Symposium on Computer Graphics and Image Processing, pages 100-105. IEEE Computer Society, 2001.
"Multiresolution shape representation without border shifting", L. da F. Costa, and L. F. Estrozi, Electronics Letters, no. 21, vol. 35, pp. 1829-1830, 1999.
"Shape Analysis and Classification", L. da F. Costa and R.M. Cesar Jr., CRC Press.
http://siptoolbox.sourceforge.net