From stripes to codes
With one light plane per frame, there is never a doubt which plane lit a pixel, but planes need frames. Projecting all of them at once is fast, but then the stripes can no longer be told apart. Coded patterns sit in between: number the projector stripes and project one bit of that number per frame. Pattern is bright on all stripes whose code word has bit set. A pixel that sees bright, dark, bright, … over the frames has read the code word of its stripe:
Eight patterns tell 256 stripes apart. Once the stripe is known, its light plane is known, and the depth follows by intersecting the camera ray with it, as in the light-plane demo.
Reading a bit
Whether a pixel is "bright" depends on the surface: a dark object under the projector can be darker than a white one without it, and surfaces at a grazing angle get little light. A fixed threshold fails there. Two extra frames fix it: one with the projector fully on, , and one with it off, . A pixel reads 1 if
and pixels where is tiny are in a shadow of the projector and get no stripe at all. Another common choice is to project every pattern together with its inverse and compare the two.
Errors at stripe borders
A pixel that covers a stripe border sees a mix of both stripes, and with blur and noise each bit can come out either way. In the binary code several bits change at some borders: between stripes 31 and 32 of a 6-bit code, 011111 turns into 100000, and all six bits flip. A pixel there can read any mix, such as 111111 = 63 or 000000 = 0, far from both true stripes.
The Gray code orders the code words so that neighboring stripes differ in exactly one bit. A pixel on a border can then only be uncertain about that one bit, and reads either of the two neighboring stripes: the error is at most one stripe. Decoding converts the Gray code back with and . The finest pattern has the most borders; when its stripes become narrower than a camera pixel, it can no longer be read, which limits the useful .
Try this
- Press Play and watch the decoded regions split in two with every pattern, from 2 regions to .
- Compare the two decoded images: the binary code has red pixels scattered along many stripe borders, the Gray code almost only at the edges of objects and shadows. The table below the images counts them.
- Click a red pixel in the binary image and read its bits in the values below: the pixel is on a border where many bits change at once.
- Raise the blur and the noise: both codes get more pixels off by one stripe, but only the binary code gets large errors.
- Increase the number of patterns to 8 and 9: the finest stripes are narrower than a camera pixel, and many pixels can no longer be decoded exactly.
- Switch to a fixed threshold. With little ambient light, the dark box stays below it even where it is lit; with a lot, the bright surfaces stay above it even where the pattern is dark. Either way, whole surfaces decode wrong, whatever the code. The white/black threshold copes with both.