Skip to content

Discretization of disk footprints (also ellipse, ball) #5470

@grlee77

Description

@grlee77

Description

When constructing footprints (structuring elements) corresponding to a disk, the following code is currently used:

L = np.arange(-radius, radius + 1)
X, Y = np.meshgrid(L, L)
return np.array((X ** 2 + Y ** 2) <= radius ** 2, dtype=dtype)

A second possibility is the following:

return np.array((X ** 2 + Y ** 2) <= (radius + 0.5) ** 2, dtype=dtype)

where the radius has been extended by 0.5 voxels. Practially the former means the edge of the disk falls at the voxel center a distance radius away, while for the later, the disk extends to the outer edge of that same voxel. A concrete illustration of this is given for radius = 3 (vs. 3.5) below:

morphology_discrete_illustration_sm

Below is an illustration where the top row are the currently returned footprints for skimage.morphology.disk and the bottom row are the footprints with the proposed modification.

morphology_disks

I don't know that the existing behavior is technically a bug, but it is more a matter of what convention is chosen. To me, the lower row look visually more disk-like (although radius=1 is too coarse to resemble a disk in either case).

If this change is made for disk, the same convention should be used for ball and ellipse as well.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions