Qu

remove_small_blobs

Builtin index · Images

result = remove_small_blobs(img, min_area)

Input: img, min_area · Output: result

What it is

img is a binary Image; min_area is a number, the minimum pixel area a connected component must have to survive. Drop connected components below that area, after labelling internally (identical operation to bwareaopen above). The cheap alternative to tuning a filter.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = remove_small_blobs(img, min_area)
img Imageimg is a binary Image.
min_area numbermin_area is a number, the minimum pixel area a connected component must have to survive.
result Image
Returns a new binary Image, same dimensions as img.

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

remove_small_blobs(binary_img, min_area) (alias bwareaopen) — labels internally (no separate label_blobs call needed), zeroes out every blob whose pixel count is below min_area, and returns a cleaned binary image in the same 0/255 mask convention (always 8-connectivity, matching MATLAB's own bwareaopen default).

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