grayscale
result = grayscale(img)
Input: img · Output: result
What it is
img is an Image of any size. Converts RGB → luma via ITU-R BT.601 weights (matches plotting.rs's contrast_text_color).
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = grayscale(img) | img Imagenot documented yet | result Image | Returns a new Image, same width/height as img, with R=G=B at every pixel — still a full 3-channel RGB image, not a separate 1-channel type. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
img = load_image("sample.bmp")
edges = edge_detect(grayscale(img))
imshow(edges)
from images
# A gradient with a bright bar in it, so the rotation below is visible:
# a symmetric test image would look identical afterwards.
n = 48
g = zeros(n, n)
for i in 0 to n - 1
for j in 0 to n - 1
g[i, j] = 40 + 3 * j
if i > 10 and i < 22 and j > 6 and j < 30
g[i, j] = 240
end if
end for
end for
save_image("sample.bmp", image_from_matrix(g))
img = load_image("sample.bmp")
gray = grayscale(img)
imshow(gray)
from images
How it works
grayscale(img) — RGB -> luma via ITU-R BT.601 weights (see image::Image::to_grayscale's doc comment for why BT.601 over contrast_text_color, which already uses these exact weights). Returns a full RGB image with R=G=B, not a separate 1-channel type.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.