PIXELBANKv9.1.0
Menu

Gray Code Pattern Decoding

Decode Gray code binary patterns to get projector column index.

Structured light scanning projects binary patterns onto objects. Gray code is preferred over standard binary because adjacent columns differ by only one bit, making it robust to slight misalignments.

For N patterns, decode to column index: col=∑i=0N−1bi⋅2N−1−icol = \sum_{i=0}^{N-1} b_i \cdot 2^{N-1-i}

This treats the pattern bits as a binary number with the first pattern as the most significant bit. The resulting value indexes into the projector's column space.

Example:

Input:
decode_gray([1, 0, 1, 0])
Output:
10
Reasoning:

Decoding 4-bit pattern [1, 0, 1, 0]: bit 0 (MSB): 1 × 2³ = 8 bit 1: 0 × 2² = 0 bit 2: 1 × 2¹ = 2 bit 3 (LSB): 0 × 2⁰ = 0

  • Total: 8 + 0 + 2 + 0 = 10

Constraints:

  • patterns: list of binary values [b0, b1, ..., bN-1]
  • Return decoded column index (integer)
solution.py

Test Results

0/0
Run code to see test results.