All examples
Images

Measure image masks and regions

Threshold an image, label connected pixels and inspect deterministic region measurements.

image_masks_regions.aner
// Measure the original image, not a display raster or filtered substitute.
import aner.image
import aner.tensor

let work = image.context(workers: 1, memory_mb: 32)
let samples: Tensor = [[0.0, 4.0, 4.0, 0.0, 8.0, 8.0, 0.0],
    [0.0, 4.0, 4.0, 0.0, 8.0, 8.0, 0.0],
    [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]]
let source = image.from_tensor(work, samples)
let mask = source.threshold(cutoff: 1.0)
let labels = mask.components(connectivity: 4)
let regions = labels.regions(source)
print(labels.count())
print(regions.area(0))
print(regions.intensity_mean(0))
print(regions.intensity_mean(1))
print(source.masked_stats(mask).mean())
print(tensor.cols(regions.features()))
print(tensor.rows(labels.values()))
print(mask.dilate(radius: 1).summary())

Make it your experiment.

Use Aner 0.1.0 or newer. Save this program as examples/image_masks_regions.aner inside a folder for your experiment. Open a terminal in that folder, then check and run the program.

Terminal
aner check examples/image_masks_regions.aner
aner run examples/image_masks_regions.aner

The aner command must be on your PATH. Follow the installation guide if your terminal cannot find it.

Requires Aner 0.1.0 or newer. CPU image analysis and binary PNM work without optional image codecs. PNG, JPEG and TIFF require their compiled capabilities. Use a fresh writable directory for outputs.

Credential setup
aner check examples/image_masks_regions.aner
aner run examples/image_masks_regions.aner

Bundled datasets retain their own source attribution and license notices. Example outcomes are not comparative benchmarks or evidence of clinical validity.

Dataset sources & attribution
Install Aner