Previous topic

medpy.metric.binary.hd

Next topic

medpy.metric.binary.assd

This Page

medpy.metric.binary.asd

medpy.metric.binary.asd(result, reference, voxelspacing=None, connectivity=1)[source]

Average surface distance metric.

Computes the average surface distance (ASD) between the binary objects in two images.

Parameters:

result : array_like

Input data containing objects. Can be any type but will be converted into binary: background where 0, object everywhere else.

reference : array_like

Input data containing objects. Can be any type but will be converted into binary: background where 0, object everywhere else.

voxelspacing : float or sequence of floats, optional

The voxelspacing in a distance unit i.e. spacing of elements along each dimension. If a sequence, must be of length equal to the input rank; if a single number, this is used for all axes. If not specified, a grid spacing of unity is implied.

connectivity : int

The neighbourhood/connectivity considered when determining the surface of the binary objects. This value is passed to scipy.ndimage.morphology.generate_binary_structure and should usually be \(> 1\). The decision on the connectivity is important, as it can influence the results strongly. If in doubt, leave it as it is.

Returns:

asd : float

The average surface distance between the object(s) in result and the object(s) in reference. The distance unit is the same as for the spacing of elements along each dimension, which is usually given in mm.

See also

assd, hd

Notes

This is not a real metric, as it is directed. See assd for a real metric of this.

The method is implemented making use of distance images and simple binary morphology to achieve high computational speed.

Examples

The connectivity determines what pixels/voxels are considered the surface of a binary object. Take the following binary image showing a cross

>>> from scipy.ndimage.morphology import generate_binary_structure
>>> cross = generate_binary_structure(2, 1)
array([[0, 1, 0],
       [1, 1, 1],
       [0, 1, 0]])

With connectivity set to 1 a 4-neighbourhood is considered when determining the object surface, resulting in the surface

array([[0, 1, 0],
       [1, 0, 1],
       [0, 1, 0]])

Changing connectivity to 2, a 8-neighbourhood is considered and we get:

array([[0, 1, 0],
       [1, 1, 1],
       [0, 1, 0]])

, as a diagonal connection does no longer qualifies as valid object surface.

This influences the results asd returns. Imagine we want to compute the surface distance of our cross to a cube-like object:

>>> cube = generate_binary_structure(2, 1)
array([[1, 1, 1],
       [1, 1, 1],
       [1, 1, 1]])

, which surface is, independent of the connectivity value set, always

array([[1, 1, 1],
       [1, 0, 1],
       [1, 1, 1]])

Using a connectivity of 1 we get

>>> asd(cross, cube, connectivity=1)
0.0

while a value of 2 returns us

>>> asd(cross, cube, connectivity=2)
0.20000000000000001

due to the center of the cross being considered surface as well.