disk
result = disk(radius)
Input: radius · Output: result
What it is
radius is a non-negative integer. Builds a disk-shaped structuring-element mask Image: a (2*radius+1) x (2*radius+1) binary mask, foreground wherever dx*dx + dy*dy <= radius*radius relative to its own center pixel. Unlike the radius-implied square, a disk excludes the four corner directions — disk(1) is a 5-pixel plus shape, not the full 3x3 block.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = disk(radius) | radius Imagenot documented yet | result Image | Returns a new binary Image. Added in v0.4.0. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
# disk(1) is a plus shape, not a 3x3 square: eroding a 1-pixel-wide plus
# with the radius-implied square wipes it out completely, but a disk SE
# of the same radius exactly matches the plus's own footprint and leaves
# its center pixel standing.
plus = image_from_matrix([0,0,0,0,0; 0,0,255,0,0; 0,255,255,255,0; 0,0,255,0,0; 0,0,0,0,0])
square_eroded = imerode(plus, 1)
print(imhist(square_eroded, n_bins=2)) # [25, 0] -- wiped out entirely
se = disk(1)
disk_eroded = imerode(plus, se=se)
print(imhist(disk_eroded, n_bins=2)) # [24, 1] -- only the center pixel survives
# hit_miss isolating the top-left corner of a solid 3x3 square: fg
# requires self/east/south/south-east foreground, bg requires
# west/north/north-west background -- true only at the one corner pixel.
sq = image_from_matrix([0,0,0,0,0; 0,255,255,255,0; 0,255,255,255,0; 0,255,255,255,0; 0,0,0,0,0])
fg = image_from_matrix([0,0,0; 0,255,255; 0,255,255])
bg = image_from_matrix([255,255,0; 255,0,0; 0,0,0])
corner = hit_miss(sq, fg, bg)
print(imhist(corner, n_bins=2)) # [24, 1] -- exactly one corner pixel found
[25, 0] [24, 1] [24, 1]
from images
How it works
disk(radius) / line(length, angle_degrees) — structuring- element constructors (§ SE/hit-miss/watershed pass, 2026-09-25). Neither takes an image at all: both build a small binary-mask Image (the same "a mask is just a bool image" convention docs/design/toolkit-image.md §2 uses) a script can imshow directly, or pass as se=/se_fg/ se_bg to the morphology builtins above. See image::Image::disk_offsets/line_offsets's own doc comments for the exact shape each produces.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.