What SoilHue 1.0 got wrong when turning a photo of soil into a Munsell notation, and how version 2.0 fixed it.
SoilHue came out of a conversation about soil quality for growing crops. The person I was talking to explained how soil colour is described with the Munsell system: you take a little soil, hold it next to the chips of a colour chart and look for the one that matches best. I kept thinking that a modern phone camera ought to be more than good enough to do something similar. The tricky part would be having a reference to compare against, knowing what colour is really in the photo and which chips to measure it against.
The first version came out in April 2025, eleven days after the first commit. You photographed a sample, marked an area and the app gave you its colour in Munsell notation, something like 10YR 4/3, along with an approximate soil classification. A notation like that has the air of a scientific measurement, and underneath, the app averaged the pixels the wrong way, calibrated the camera with three numbers and compared the result against eighteen reference colours typed in by hand. It always gave an answer, but nothing guaranteed it was the right one.
Shortly after it came out, and against all expectations, since I didn't think anyone would be interested, it got a couple of negative reviews. I thanked both users all the same. They complained mainly about the calibration, and they were the reason I got serious about colour handling and calibration. A year later I rewrote the whole colour engine for version 2.0.
In the field, the colour of a soil tells you about its organic matter, its iron, its drainage and its age. Munsell describes it with three dimensions: hue (for example 10YR, between yellow and red), value (how light or dark, from 0 to 10) and chroma (how intense). 10YR 4/3 is a mid-light, weakly saturated brown. With the colour chart next to the sample, the reference sits under the same light as the soil. With a camera, that reference has to be rebuilt, because the phone processes the image in its own way before the app sees it.
The colour of an area comes from averaging a lot of pixels. The values an image stores follow a curve (the sRGB gamma) that spreads the levels out to suit the human eye, so a grey that reflects half the light is stored as 188 out of 255. If you average a black pixel (0) and a white one (255) using the raw numbers, you get 127.5, which in real light is 21 %.
SoilHue 1.0 averaged the encoded numbers. In a uniform area it hardly matters, but a soil sample has grains, shadows, roots and highlights, and the result came out biased towards the dark. Version 2.0 undoes the curve for each pixel, averages in linear sRGB, which is proportional to light, and stays linear throughout.
The photo depends on the light, the white balance and the phone's processing. That's why SoilHue asks you to calibrate first with a ColorChecker card, which has 24 patches of known colour, and works out the correction that takes what the camera sees to the real colours.
Version 1 worked out three factors, one per channel. That corrects an overall tint, but a camera's channels bleed into one another, and part of what the sensor records as green corresponds to red light. Version 2.0 fits, by least squares, a 3×3 matrix with an offset term, in which each corrected channel depends on all three original channels.
With the colour corrected, what's left is finding the closest Munsell chip. Version 1 measured the distance in RGB against 18 colours picked by eye. Distance in RGB bears little resemblance to how we perceive differences in colour, and 18 references fall far short for a system with thousands of combinations.
Version 2.0 converts the colour to CIE Lab, a space designed so that distances resemble what the eye perceives, and measures the difference with the ΔE94 formula against 293 chips from the official Munsell renotation data, as distributed by aqp, the soil-science library from the US Natural Resources Conservation Service (USDA-NRCS).
The change ran so deep that calibrations made with version 1 were useless to the new engine. That's why it jumped from 1.1 to 2.0: on updating, the app discards the old calibration and asks you to calibrate again, and keeps your saved samples.
A commercial ColorChecker costs money, so SoilHue generates a card to print. The first one was an image with no colour profile, and each printer driver converted it however it liked. Now it's a PDF with the sRGB profile embedded as its output intent, which printers do respect.
The other problem was geometric. To find the card in the photo, the app looks for a rectangle with the proportions of a ColorChecker, and an A4 sheet, with its aspect ratio of 0.71, fell inside the range. If you photographed the whole sheet, the app could latch onto the edge of the paper, split it into 4×6 cells and calibrate with pieces that weren't patches, without any warning. The new card has two pages: one with only the grid, surrounded by a thick black border with L-shaped marks in the corners, and another with the instructions, so that the text doesn't form false rectangles.
Testing with real cards and samples turned up four bugs that no test had caught:
A calibration is valid for the light it was made under. If you calibrate in sunshine and photograph the sample under a light bulb, the correction no longer holds. After calibrating, the app analyses the tint of the light and warns you if it's clearly warm, cool or unusual, and the warning stays visible even if you close the app, so you remember to take your samples under the same light.
A phone is less precise than a spectrophotometer, and a card printed at home is less accurate than a laboratory ColorChecker. The soil classification shown alongside the colour is guidance: properly classifying a soil means looking at horizons, texture and chemistry. And everything happens on the phone itself, with no photo and no sample ever leaving the device.