lm3_mp_conversion_factor__sqrt_fit
One-parameter model predicting a herbarium sheet image's pixel-per-centimeter conversion factor from its size in megapixels. Default mp_conversion_factor model in LeafMachine3 >= 3.0.0.
LM3 metadata
| Field | Value |
|---|---|
| LM3 action | mp_conversion_factor |
| LM3_default_model | true |
| LM3_version | 3.0.0 (minimum supported; later releases remain compatible) |
| Model key | sqrt_fit |
| Form | , (in code: cf_px_per_cm = k * sqrt(megapixels)) |
| Input | megapixels of the image, , in the frame being measured |
| Output | pixels per cm in that same frame |
| Parameters | 1 |
| Fitted | 2026-08-12 |
The form is exact under uniform resize. Scaling both sides of an image by scales its megapixels by , so
and the prediction on the resized image is the original prediction times the resize factor. The model can therefore be evaluated in any frame.
Files
| Folder | File | Use |
|---|---|---|
json/ |
model.json |
LM3 runtime artifact (k, fit metrics, ranges) |
fit/ |
fit_mp_cf.py, fit_data.csv |
reproduces model.json with numpy |
docs/ |
fit_708_sheets_light.png, fit_708_sheets_dark.png |
the fit figure, one per theme |
SHA-256 of every file is in manifest.json.
Training data
708 human ruler measurements on 549 herbarium sheets from 48 herbaria (US 318, NY 106, O 45, BR 39, NCU 22, others 178). Ground truth is the manually measured length of 1 cm on each sheet's ruler (cm_1_avg) from the LeafMachine2 ruler quality-control set; image dimensions come from the same set; rows kept where 20 < cf < 400. Megapixels 14.6 to 36.2, conversion factor 88.8 to 172.5 px/cm. All rows are used for the fit; there is no train/val/test split. The table ships as fit/fit_data.csv (filename, herbarium code, width, height, megapixels, cf); specimen images are not distributed.
Fit
Least squares through the origin:
Unconstrained checks on the same rows agree with the form: fitting gives (theory 0.5), and fitting gives px/cm (theory 0).
Evaluation
| Data | n | RMSE (px/cm) | RΒ² | Mean abs. error | p95 | Max |
|---|---|---|---|---|---|---|
| fit rows (in-sample) | 708 | 4.53 | 0.905 | 2.3% | 7.5% | 32.2% |
| 20 independently hand-labeled sheets, each resized across 1 to 38.6 MP | 480 | 3.7% | 10.9% | 13.0% |
The second row's error is the same inside and outside the fitted 14.6 to 36.2 MP range. A two-parameter linear fit on the same 708 rows reaches RMSE 4.37 inside the range and is wrong by up to 193% outside it.
Figure
The 708 measurements and the fitted curve. The shaded band is the fitted megapixel range.
Use in LeafMachine3
Stage mp_conversion_factor, the first pipeline stage (no dependencies, CPU only, no image decode). It evaluates the model on the working image's megapixels and stores specimen.cf_px_per_cm_predicted_by_mp. ruler_cf uses that value as the megapixel anchor: a conversion factor measured from a ruler is published only if it agrees with the anchor within anchor_tol (default 0.25) or rests on enough ruler length to outvote it.
import json, math
from huggingface_hub import hf_hub_download
m = json.load(open(hf_hub_download("phyloforfun/lm3_mp_conversion_factor__sqrt_fit", "json/model.json")))
cf_px_per_cm = m["k"] * math.sqrt(width * height / 1e6)
Citation
Weaver, W. N. (2026) LeafMachine3. https://leafmachine.org