Photo-Sieve Grain Size Distribution Calculator
Particle-size distribution from a top-down photograph of a gravel bar, riverbed, or armor layer. Returns D₁₆, D₅₀, D₈₄, D₉₀, area-weighted mean, Folk-Ward sorting σ, Wentworth class breakdown, cumulative grain-size curve, and phi histogram. Watershed segmentation runs entirely in your browser via OpenCV.js — your photo never leaves your device.
How the algorithm works
The tool implements classical photo-sieving (Graham, Reid & Rice, 2005) with a watershed step to separate touching grains, all running in WebAssembly via OpenCV.js. Steps:
- CLAHE local contrast. Contrast-limited adaptive histogram equalization (clipLimit = 2.0, 8×8 tile) flattens uneven lighting before thresholding. Critical for field photos shot under non-uniform sun.
- Otsu threshold. Automatic global threshold separates stones (bright) from inter-grain shadow (dark).
- Morphological cleanup. Open-then-close with a 3×3 kernel removes salt-and-pepper noise and fills small holes inside grain footprints.
- Distance transform. A Euclidean distance map of the stone mask: every foreground pixel gets the distance to the nearest background pixel.
- Sure-foreground markers. Threshold the distance map at 45% of its peak; what remains is the centers of grains, even when their edges touch their neighbors'. Background markers come from a 3-iteration dilation of the cleaned mask.
- Watershed. OpenCV's marker-based watershed treats each marker as a basin and grows them outward until they collide. The collision lines are the grain boundaries.
- b-axis from minimum-area bounding rectangle. For each segmented grain, fit the smallest rectangle that contains its contour; the shorter side of that rectangle is the b-axis. This matches the convention used in mechanical sieving (a particle passes a square-mesh sieve when its b-axis < mesh opening).
- Area-weighted percentiles. Sort grains by b-axis; accumulate area; report the b-axis at which cumulative area reaches each target percentile. Equivalent to a mass-percentile sieve curve under the assumption of constant density.
Wentworth scale — full reference
The Wentworth (1922) classification is the de-facto sediment size scale in geology, sedimentology, and gravel-bed hydraulics. Boundaries are at whole-φ values; each class spans one phi unit (factor of 2 in millimeters).
| Class | Sub-class | d (mm) | φ |
|---|---|---|---|
| Clay | Fine clay | < 0.0020 | > 9 |
| Coarse clay | 0.0020 – 0.0039 | 9 – 8 | |
| Silt | Fine silt | 0.0039 – 0.0156 | 8 – 6 |
| Medium silt | 0.0156 – 0.0312 | 6 – 5 | |
| Coarse silt | 0.0312 – 0.0625 | 5 – 4 | |
| Sand | Very fine sand | 0.0625 – 0.125 | 4 – 3 |
| Fine sand | 0.125 – 0.250 | 3 – 2 | |
| Medium sand | 0.250 – 0.500 | 2 – 1 | |
| Coarse sand | 0.500 – 1.00 | 1 – 0 | |
| Very coarse sand | 1.00 – 2.00 | 0 – −1 | |
| Granule | — | 2.00 – 4.00 | −1 – −2 |
| Pebble | Fine / medium pebble | 4.00 – 16.0 | −2 – −4 |
| Coarse / very coarse pebble | 16.0 – 64.0 | −4 – −6 | |
| Cobble | — | 64 – 256 | −6 – −8 |
| Boulder | — | > 256 | < −8 |
Source: Wentworth, C.K. (1922). "A scale of grade and class terms for clastic sediments." Journal of Geology 30(5): 377–392.
Folk-Ward sorting — verbal scale
The inclusive graphic standard deviation σ_I summarizes the spread of the distribution. The ratio of φ₈₄−φ₁₆ (the central 68%) to φ₉₅−φ₅ (the central 90%) catches both the body and the tails. Note: in PE-Calc and most computational implementations, percentiles are stored by SIZE (D₁₆ < D₈₄), so the equivalent expression is σ_I = (φ_{D16} − φ_{D84})/4 + (φ_{D5} − φ_{D95})/6.6 — both forms give the same positive value.
| σ_I (φ) | Verbal description | Typical environment |
|---|---|---|
| < 0.35 | Very well sorted | Beach swash zone, eolian dune crest |
| 0.35 – 0.50 | Well sorted | Mature beach, well-developed eolian sand |
| 0.50 – 0.71 | Moderately well sorted | Foreshore, lower-energy eolian |
| 0.71 – 1.00 | Moderately sorted | Fluvial sands, mixed-energy beach |
| 1.00 – 2.00 | Poorly sorted | Gravel-bed rivers, fluvioglacial |
| 2.00 – 4.00 | Very poorly sorted | Glacial till, debris flow, alluvial fan |
| > 4.00 | Extremely poorly sorted | Mass-flow / colluvial deposits |
Source: Folk, R.L., & Ward, W.C. (1957). "Brazos River bar: a study in the significance of grain size parameters." Journal of Sedimentary Petrology 27(1): 3–26.
Worked examples
Example 1 — Riprap D₅₀ check from a constructed slope
Example 2 — Bedload competence in a gravel-bed stream
When NOT to use this tool
- Subsurface gradation. Photo-sieving captures the visible top layer only. For bulk sediment supply, scour computations, or filter-criteria checks involving the full gradation, run a bulk sample through mechanical sieves.
- Heavily sand-dominated samples. If most particles are below ~0.3 mm and your phone lens can't resolve individual grains, the segmentation will smear them into clumps. Use a macro lens or fall back to a standard sieve set (No. 4 to No. 200).
- Wet, glistening surfaces. Specular highlights on waterlogged stones look like miniature grains to the segmenter. Wait for surface-dry conditions or shoot with a polarizer.
- Oblique photographs. Perspective foreshortening biases all measured sizes. Shoot top-down (camera axis vertical, ±5°). For unavoidable oblique photos, use the FieldHydro full app — the upcoming version corrects perspective via a four-corner reference.
- Imbricated coarse bed. When pebbles overlap heavily and the visible footprint is mostly the a-c face, the inferred b-axis is biased low. This is a known photo-sieving limitation — Graham et al. (2005) document a +5–10% correction is sometimes warranted for strongly imbricated beds.
Privacy & security
This tool is engineered around a single principle: your photo never leaves your device. The image is decoded into an HTMLCanvas in your browser, processed by OpenCV.js (a WebAssembly build of OpenCV running in your browser's sandbox), and the results are rendered back into the same page. There is no upload endpoint to compromise, no cloud queue holding your photos, no cookie tying analyses to a user. You can verify by opening DevTools → Network and running an analysis: zero outbound bytes from the photograph.
Other hardening: file inputs are MIME-restricted to JPEG/PNG/WebP, file size capped at 10 MB, and the browser canvas decode strips EXIF metadata as a side effect of redrawing pixels. Every tool page on PE-Calc serves a strict Content-Security-Policy meta header so injected scripts and exfiltration channels are blocked at the browser level.
Apps for offline field use in development
Native iOS and Android apps with offline OpenCV are in development for high-throughput field surveys (sealed-bid quantity verification, post-storm bed armor surveys, Wolman-grid-equivalent reach inventories). Sign up to be notified at launch, or follow these store placeholders:
Primary references: Graham, D.J., Reid, I., & Rice, S.P. (2005). "Automated sizing of coarse-grained sediments: image-processing procedures." Mathematical Geology 37(1): 1–28. · Detert, M., & Weitbrecht, V. (2012). "Automatic object detection to analyze the geometry of gravel grains — a free stand-alone tool." River Flow 2012: 595–600. · Wentworth, C.K. (1922). "A scale of grade and class terms for clastic sediments." Journal of Geology 30(5): 377–392. · Folk, R.L., & Ward, W.C. (1957). "Brazos River bar: a study in the significance of grain size parameters." J. Sedimentary Petrology 27(1): 3–26.
Related tools
- Sample analysis — coarse-sand photograph (D₅₀ = 1.68 mm, 113 grains)
- Settling velocity — Stokes / Newton for sediment particles
- Manning's equation — channel roughness from D₈₄ via Limerinos
- Terzaghi bearing capacity — granular soil φ' from gradation