Image Processing Toolbox User's Guide |
Distance Transform
The distance transform provides a metric or measure of the separation of points in the image. The Image Processing Toolbox provides a function, bwdist
, that calculates the distance between each pixel that is set to off
(0
) and the nearest nonzero pixel for binary images.
The bwdist
function supports several distance metrics, listed in the following table.
This example creates a binary image containing two intersecting circular objects.
center1 = -10; center2 = -center1; dist = sqrt(2*(2*center1)^2); radius = dist/2 * 1.4; lims = [floor(center1-1.2*radius) ceil(center2+1.2*radius)]; [x,y] = meshgrid(lims(1):lims(2)); bw1 = sqrt((x-center1).^2 + (y-center1).^2) <= radius; bw2 = sqrt((x-center2).^2 + (y-center2).^2) <= radius; bw = bw1 | bw2; figure, imshow(bw), title('bw')
To compute the distance transform of the complement of the binary image, use the bwdist
function. In the image of the distance transform, note how the centers of the two circular areas are white.
Finding Peaks and Valleys | Objects, Regions, and Feature Measurement |
© 1994-2005 The MathWorks, Inc.