All examplesImages Install Aner
Keep image coordinates and units
Retain calibrated pixel coordinates and distinguish pixel area from physical measurements.
// Calibration labels do not perform conversion; attach known coordinate units explicitly.
import aner.image
import aner.tensor
import aner.units
let work = image.context(workers: 1, memory_mb: 32)
let samples: Tensor = [[0.0, 2.0, 2.0, 0.0], [0.0, 2.0, 2.0, 0.0]]
let source = image.from_tensor(work, samples)
.calibrate(spacing_x: 0.5, spacing_y: 0.25, units: "mm")
let regions = source.threshold(cutoff: 1.0).components(connectivity: 4).regions(source)
let x = source.physical_x(regions.centroid_x(0), regions.centroid_y(0))
let position = units.quantity(x, "mm")
print(position.to("m"))
print(regions.area(0))
// Raw area is in square millimeters. The scalar registry has no area descriptor.
print(regions.physical_area(0))
let view = source.crop(x: 1, y: 0, width: 2, height: 2)
print(view.physical_x(0.0, 0.0))
print(view.units())
Make it your experiment.
Use Aner 0.1.0 or newer. Save this program as examples/image_physical_units.aner inside a folder for your experiment. Open a terminal in that folder, then check and run the program.
aner check examples/image_physical_units.aner
aner run examples/image_physical_units.anerThe 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.
aner check examples/image_physical_units.aner
aner run examples/image_physical_units.anerBundled datasets retain their own source attribution and license notices. Example outcomes are not comparative benchmarks or evidence of clinical validity.
Dataset sources & attribution