## Documentation Center |

Distance transform of binary image

`D = bwdist(BW)[D,IDX] = bwdist(BW)[D,IDX] = bwdist(BW,`

`D = bwdist(BW)` computes
the Euclidean distance transform of the binary image `BW`.
For each pixel in `BW`, the distance transform assigns
a number that is the distance between that pixel and the nearest nonzero
pixel of `BW`. `bwdist` uses the
Euclidean distance metric by default. `BW` can have
any dimension. `D` is the same size as `BW`.

`[D,IDX] = bwdist(BW)` also
computes the closest-pixel map in the form of an index array, `IDX`.
(The closest-pixel map is also called the feature map, feature transform,
or nearest-neighbor transform.) `IDX` has the same
size as `BW` and `D`. Each element
of `IDX` contains the linear index of the nearest
nonzero pixel of `BW`.

`[D,IDX] = bwdist(BW,method)` computes
the distance transform, where

`[gpuarrayD, gpuarrayIDX]= bwdist(gpuarrayBW)` computes
the Euclidean distance transform of the binary image `gpuarrayBW`,
performing the operation on a GPU. The images must be 2-D and have
less than 2^{32-1} elements. In addition,
you can only compute the Euclidean distance metric. This syntax requires
the Parallel Computing Toolbox™.

`BW` can be numeric or logical, and it must
be nonsparse. `D` is a single matrix with the same
size as `BW`. The class of `IDX` depends
on the number of elements in the input image, and is determined using
the following table.

Class | Range |
---|---|

'uint32' | numel(BW) <= 2^{32} −
1 |

'uint64' | numel(BW) >= 2^{32} |

`gpuarrayBW` can be a 2-D gpuArray of type `uint8`, `uint16`, `uint32`, `int8`, `int16`, `int32`, `single`, `double` or `logical`. `gpuarrayD` is
a gpuArray with the same size as `gpuarrayBW` and
underlying class `single`. `gpuarrayIDX` is
a gpuArray with the same size as `gpuarrayBW` and
underlying class `uint32`.

Was this topic helpful?