VLFeat implements the fast image distance transform
algorithm from [1]. The distance transform of an
image image
is defined as
dt(u,v) = min image(u',v') + alpha (u'-u-u0)^2 + beta (v'-v'-v0)^2 u'v'
Usually, image
is the response of a feature
detector. In this case, the distance transforms propagates the
response to nearby pixels, weighted by the distance. The distance
transform is used, for example, in the flexible parts model to quickly
determine the optimal configuration of a tree-like model by dynamic
programming. In this tutorial, the distance transform is used to
compute the distance of each pixel to the nearest edge.
As test data consider the edge map extracted by the MATLAB Canny edge detector on one of VLFeat test images:
im = imread(fullfile(vl_root, 'data', 'a.jpg')) ; im = im(1:100,1:100,:) ; imSize = [size(im,1) size(im,2)] ; edges = zeros(imSize) + inf; edges(edge(rgb2gray(im), 'canny')) = 0 ;
vl_demo_imdisttf
.
The image has been cropped for ease of visualization; the image
distance transform itself is quite fast. Note that the edge map
has value zero where edges are present, and inf
for
the other pixels. In this case, the image distance transform
computes the closest edge point to each pixel, and its distance:
[distanceTransform, neighbors] = vl_imdisttf(single(edges)) ;
distanceTransform
contains the distance from each
pixel to the nearest edge element, and neighbors
its
index. Note that, by default, alpha=beta=1
and u0=v0=0
.
vl_demo_imdisttf
.
[1] P. F. Felzenszwalb and D. P. Huttenlocher. Distance transforms of sampled functions. Technical report, Cornell University, 2004.