1. A method of generating a digital representation of a scene, the method comprising: receiving at a sensor a structured light image of a plurality of encoded codewords, the plurality of encoded codewords including an invalid codeword; detecting, using a processor, the invalid codeword by determining whether each encoded codeword in the structured light image corresponds to a code in a codebook stored in memory, the codebook comprising a list of valid codes; generating, using the processor, candidate codewords based on the invalid codeword; selecting, using the processor, one of the candidate codewords to replace the invalid codeword, wherein said selecting one of the candidate codewords comprises selecting from the generated candidate codewords a subset of candidate codewords, each candidate codeword in the subset being the same as one of the plurality of encoded codewords, determining a similarity between each candidate codeword in the subset and codewords within a local neighborhood around the invalid codeword; and selecting the candidate codeword in the subset most similar to the local neighborhood to replace the invalid codeword; generating, using the processor, a depth map for an image of the scene based on the selected candidate codeword; generating, using the processor, a digital representation of a scene based on the depth map; and outputting the digital representation of the scene to an output device.