regionprops
result =regionprops(labeled)(alias ofblob_stats)
Input: labeled · Output: result
What it is
labeled is a Model produced by bwlabel/label_blobs. Takes that result and returns a List of one Record per blob, in label-id order, each with fields: label (integer id), area (pixel count), centroid_x, centroid_y (real pixel-coordinate means, not bbox-center approximations), bbox_x, bbox_y, bbox_width, bbox_height (tightest axis-aligned rectangle) — all numbers.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = regionprops(labeled) (alias of blob_stats) | labeled Model, List, Record, or numbernot documented yet | result List or Record | Returns a List with one Record per blob, in label-id order — empty when labeled found none. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
# Three bright discs on a dark field, written out and read back. The blob
# count printed below is then checkable against an image the reader can
# see being built, rather than asserted about a file nobody has.
n = 60
field = zeros(n, n)
centres = [15, 15; 42, 20; 30, 45]
for i in 0 to n - 1
for j in 0 to n - 1
for k in 0 to 2
dy = i - centres[k, 0]
dx = j - centres[k, 1]
if dy * dy + dx * dx < 64
field[i, j] = 230
end if
end for
end for
end for
save_image("cells.bmp", image_from_matrix(field))
img = load_image("cells.bmp")
level = otsu_threshold(img)
mask = threshold(img, level)
clean = bwareaopen(mask, 20) # drop specks smaller than 20 px
imshow(clean)
labeled = bwlabel(clean)
print(labeled.count) # number of detected blobs
stats = regionprops(labeled)
for i = 1 to labeled.count
r = stats[i - 1]
print(r.label, r.area, r.centroid_x, r.centroid_y)
end for
3 1 193 15 15 2 193 45 30 3 193 20 42
from images
How it works
blob_stats(labeled) (alias regionprops) — per-blob geometry from a label_blobs/bwlabel result: a Value::List of one Value::Record per blob (label, area, centroid_x, centroid_y, bbox_x, bbox_y, bbox_width, bbox_height), in label-id order. centroid_x/centroid_y are the real arithmetic mean of that blob's own pixel coordinates (not a bounding-box-center approximation); bbox_* is the tightest axis-aligned rectangle containing every one of that blob's pixels.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.