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.

cfpx/cmβ€…β€Š=β€…β€Šk MP,k=27.112084,MP=wβ‹…h106 \mathrm{cf}_{\mathrm{px/cm}} \;=\; k\,\sqrt{\mathrm{MP}}, \qquad k = 27.112084, \qquad \mathrm{MP} = \frac{w \cdot h}{10^{6}}

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 cf=kMP \mathrm{cf} = k\sqrt{\mathrm{MP}} , k=27.112084 k = 27.112084 (in code: cf_px_per_cm = k * sqrt(megapixels))
Input megapixels of the image, MP=wβ‹…h/106 \mathrm{MP} = w \cdot h / 10^{6} , 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 s s scales its megapixels by s2 s^{2} , so

k s2 MPβ€…β€Š=β€…β€Šsβ‹…k MP k\,\sqrt{s^{2}\,\mathrm{MP}} \;=\; s \cdot k\,\sqrt{\mathrm{MP}}

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:

kβ€…β€Š=β€…β€Šβˆ‘iMPiβ€…β€Šcfiβˆ‘iMPi k \;=\; \frac{\sum_i \sqrt{\mathrm{MP}_i}\;\mathrm{cf}_i}{\sum_i \mathrm{MP}_i}

Unconstrained checks on the same rows agree with the form: fitting cf=a MPb \mathrm{cf} = a\,\mathrm{MP}^{b} gives b=0.4904 b = 0.4904 (theory 0.5), and fitting cf=kMP+c \mathrm{cf} = k\sqrt{\mathrm{MP}} + c gives c=0.64 c = 0.64 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.

Scatter of 708 measured conversion factors against megapixels with the fitted curve cf = 27.11 times the square root of megapixels

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

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support