This post originated from an RSS feed registered with Java Buzz
by Wolf Paulus.
Original Post: Unit Testing Pt.2
Feed Title: Wolf's Web Journal
Feed URL: http://wolfpaulus.com/feed/
Feed Description: Journal - dedicated to excellence, and motivated by enthusiasm to trying new things
Before writing code accessing the camera, it's a good idea to know a little bit more about how the toy cameras works. The CMOS image sensor produces a digital output representing each pixel. An analog-to-digital converter turns each pixel's value into a digital value and thus digitizes your image.
Light hits the sensor when the camera's shutter opens and each pixel on the sensor records the light that falls on it by accumulating electrical charges of the various intensities. Since pixels on CMOS sensor are color blind, the light needs to pass a filters composed of the three primary colors red, green and blue recording only the intensity of the light that hits them and not the color of your image. Because the human eyes are most sensitive to green light, twice as many green pixels are recorded in what's referred to as the Bayer Pattern.
Bayer Pattern
The camara records 164 x 124 pixels per image. However, for every pixel there is only one color component stored (red, green or blue).
To make things even more complicated, the pixel read-out is shuffled to avoid crosstalk between the color channels. The read-out order is all the odd column pixels followed by all the even column pixels.
Shuffled Readout
Crosstalk:
Parasitic capacitance between PCB tracks can cause the fast edges of high-speed logic to propagate from one signal line to another. This crosstalk can have catastrophic effects, producing glitches large enough to cross logic thresholds.
Like mentioned before, the low-cost digital camera does not provide any image processing and therefore, after a photo has been taken, about 20 Kbytes uncompressed, raw image sensor data, has to be off-loaded and processed elsewhere.
Now that we know what the raw data looks like, we know the talk at hand: Reshuffle the column data and interpolate the missing color information: