Qu

label_blobs

Builtin index · Images

result = label_blobs(img)

Input: img · Output: result

What it is

img is a binary Image. Connected-component labelling: every separate region gets its own integer (identical operation to bwlabel above).

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = label_blobs(img)
img Imagenot documented yet
Model —kind "blobs"
Returns a Model (kind "blobs") with .labels, .count, .width, .height fields.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

m = [255, 255, 0, 0, 0, 0; 255, 255, 0, 255, 0, 0; 0, 0, 0, 0, 0, 0; 0, 255, 0, 0, 0, 0; 0, 0, 0, 0, 255, 255; 0, 0, 0, 0, 255, 255]
binary = image_from_matrix(m)

cleaned = remove_small_blobs(binary, 3)     # drop the two 1-pixel specks

imshow(cleaned)
labeled = label_blobs(cleaned)
stats = blob_stats(labeled)

for i = 1 to labeled.count
    r = stats[i - 1]
    print(r.label, r.area, r.centroid_x, r.centroid_y)
end for
output
1 4 0.5 0.5
2 4 4.5 4.5
a synthetic field with one bright patch

from images

How it works

label_blobs(binary_img, [connectivity=8]) (alias bwlabel) — connected-component labeling (see image::Image::label_components's doc comment for the flood-fill algorithm). Returns a Value::Model (kind "blobs", the multi-result-in-one-handle protocol this codebase's model values already use) rather than a tuple: .labels (a Value::Mat of integer label ids, background = 0), .count (blob count), plus .width/.height (the source image's own dimensions).

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.