How the scanner works
The rice.ag scanner does not ask an AI model to "look at the photo and guess". It measures. Every result comes from counting and measuring pixels with well-understood image-processing steps, so the same photo always gives the same answer, and you can see exactly which kernel was put in which class.
The pipeline
- Resize and read. Photos are scaled to at most 2,400 px on the long side and read into memory in your browser. Nothing is uploaded.
- Background correction. The scanner estimates the background brightness across the photo in two passes — a rough estimate, then a refined one using only pixels that are not grains — and subtracts it, so uneven light doesn't make grains on one side look different.
- Separating grains from background. Otsu's method picks the threshold that best splits grains from background. Small specks are removed and holes inside grains are filled. In lightbox mode a three-class split is used so translucent and chalky parts of a kernel both count as grain. A second, lower threshold catches objects much darker than rice — such as stones or soil on a black background — which would otherwise disappear.
- Finding objects. Connected pixels are grouped into objects. Objects touching the photo edge are excluded.
- Measuring. For each object the scanner finds its principal axis and projects every pixel onto it: length is the extent along that axis, width across it. It also records area, convexity (solidity), and average colour in CIELAB, taken from the kernel's interior so edge blur doesn't tint it.
- Scale. If you choose a coin, the largest round, solid object is treated as the coin and its diameter converts pixels to millimetres.
- Touching grains and foreign objects. Objects much wider than a typical grain, with low convexity, or much longer than a whole kernel are marked as touching grains and excluded from the percentages. Large, round, solid objects are treated as suspect foreign objects.
- Classification. The average whole-kernel length of the sample is estimated from its longer kernels (or taken from the length you enter), and every kernel is classified by its length relative to it (table below).
- Flags. Kernels whose colour or shape is far from the sample's typical kernel are flagged for review: dark, yellowed, red/brown, round, thin slivers, irregular or oversize.
Classes
Length classes follow ISO 7301 (whole kernel ≥ 9/10 of the average length; head rice ≥ 3/4) and the broken-kernel sizes in Codex Standard 198 (large, medium and small broken; chips pass a 1.4 mm round-hole sieve).
| Class | Rule (length ÷ average whole-kernel length) |
|---|---|
| Whole | ≥ 0.90 |
| Head piece | 0.75 – 0.90 (counts as head rice) |
| Large broken | 0.50 – 0.75 |
| Medium broken | 0.25 – 0.50 |
| Small broken | < 0.25 |
| Chip | narrower than 1.4 mm and shorter than half a kernel (needs a coin) |
By weight vs. by count. Trade specifications give broken percentages by weight. A photo can't weigh grains, so the scanner estimates each piece's share of weight from its projected area. This works well because broken pieces keep roughly the full width and thickness of a kernel; it becomes less exact for very small fragments. Count-based percentages are shown too.
Size classes use IRRI's milled-rice scales: length extra long (> 7.5 mm), long (6.61–7.5), medium (5.51–6.6), short (≤ 5.5); shape by length/width ratio slender (> 3.0), medium (2.1–3.0), bold (1.1–2.0), round (< 1.1).
Chalkiness (lightbox mode only) counts interior kernel pixels that transmit less than a set fraction of the local background light. A kernel is reported as chalky when at least three-quarters of it is opaque, matching the Codex definition of a chalky kernel.
How accurate is it?
We test every version against computer-generated sample photos where the true answer is known — randomised grain sizes, broken pieces, lighting gradients, blur, camera noise, JPEG compression, touching grains and planted contaminants. For version 1.0, across 10 such images and 1,705 kernels:
| Measure | Result |
|---|---|
| Kernels placed in the correct length class | 99.5% |
| Average whole-kernel length error | 0.05 mm (worst image 0.08 mm) |
| Broken % by weight, error | 0.8 points on average (worst image 1.9) |
| Touching grain pairs detected and excluded | 21 of 22 |
| Planted dark stones, yellow kernels, paddy and husk flagged | 38 of 40 |
Known limits
- Moisture cannot be measured from a photo. Use a calibrated meter; see the moisture calculator.
- Rice-coloured stones and glass can look exactly like grains. A clean result does not prove a sample is stone-free.
- Fissures (cracks) inside whole kernels are not detected yet.
- Very broken samples (mostly brokens, few whole kernels) make the average whole-kernel length hard to estimate. Enter the variety's known length under Advanced for these.
- Colour depends on camera and light; compare only samples shot with the same setup.
- Paddy and brown rice work for size and broken counts, but colour flags are tuned for milled rice.
Privacy
The page loads the scanner code once; after that your photo is processed by JavaScript on your own device. No photo, measurement or result is sent to rice.ag or anyone else. Exports (image, CSV) are generated locally.
Changelog
- 1.0 (September 2026) — first public release.