Context

I recently bought a used DSLR camera, specifically the Canon Rebel t6i. It’s a great camera and I’ve had a lot of fun learning how to use it (it’s my first DSLR). There is only one problem with it. Soon after I started using it, I found that the sensor is broken.

Untitled

Untitled

Untitled

I thought that, being only two lines, and always, it was worth trying to fix it digitally (since I’m better working with software than with hardware)

First Attempt

At first I figured that I was better off taking RAW photos with the camera since I would be able to keep more of the information (also I prefer to edit my photos afterwards and keep as much flexibility as possible)

I used the library rawpy to open the .CR2 file (Canon’s raw format). To work easily with the file, I transformed the data into an RGB array of pixels, then I just interpolated the pixels in the line based on the surrounding pixels, here I found the first problem. The lines, that seemed to be of one pixel width in the .CR2 file were now of 3 pixels width (later I found it was because of the demosaicing algorithm), I did the filter to fix the 3 pixel width lines and the result was fairly good, it was almost imposible to spot the lines if you didn’t look the photo with great amounts of zoom. The biggest problem was that now I had a RGB array of pixels and the library rawpy couldn’t store this back into a .CR2 file, so my only option was to store it into another file format such as .tiff . This resulting file didn’t have nearly as much data as I originally had and furthermore, it changes the colors of the original image. It wasn’t a good enough solution for me.

Untitled

Untitled

Untitled

Untitled

Second Attempt

I figured that with the rawpy library I could access the raw data registered by the sensor, before it was converted to RGB, there I learned that each pixel of the sensor didn’t capture an RGB value but a single value that just represented roughly how many photons hit that pixel in particular. To understand color, the sensors uses an array of filters on top of the pixels that allows only certain wave lengths to hit certain pixels. something like the following image. It’s called a Bayer pattern.

Bayer pattern of a the array of filters

Bayer pattern of a the array of filters

When reading the raw data, I found a monochrome version of the image, where each pixel has a value roughly between 0 an 16000.

Untitled

If I zoom on this pic I could see a weird pattern that I hadn’t seen before

Untitled

Untitled