# How to find the color channel shifting of an RGB image that was supposed to be greyscale?

I am using a recording device that seems to shift the colors horizontally and I would like to find the amount of unshifting I have to do on 2/3 of the channels in order to obtain an image with minimal color distortion.

You can see here that in the original image at least the blue channel was shifted back with ~1.0 pixel.

The question is how can I detect the optimal unshift values, I'm sure they are not integers.

• Which of these images is the images recorded from your device ?
– Sasha
Commented Nov 23, 2011 at 19:28

It seems like conceptually you're nearly there:

• Take one of the three colour channels as reference (for example: red)
• Match the green against the red
• Match the blue against the red

The problem then is the matching with sub-pixel accuracy. To get meaningfull numbers is a bit tricky, since the interpolation errors any method will make have an impact on the accuracy.

There are two useable image registration methods I can think of:

1. Lucas-Kanade image registration. Using linear interpolation might not give you accurate enough results, so consider bicubic or other methods. Neil Dodgson has one made a nice overview. It's important that different sub-pixel shifts of the interpolation kernel have a similar frequency transfer. For the cubic family, the approximating b-spline is far better than cattmull-rom, in this case.

2. First upscale the image, then do pixel-precise image registration using your favorite technique. (cross-correlation in the Fourier domain should do). This only works if upscaling is done carefully. Bilinear or bicubic will most likely not give you enough accuracy. I can think of three ways:

a. Yen-interpolation. See equation 11 of his paper. Really slow, but optimal. Although you seem to have some alias in the signal so the 'bandlimited' assumption Yen makes might not hold.

b. Calculate FFT of the image, zero pad the high frequencies, inverse FFT.

c. Non-linear upscaling. Since the edges are quite sharp, the image is not properly bandlimited, that might be the main limitation of the previous methods. Edge Dependent Directional Interpolation might be better in this case.

Once you have the sub-pixel translation between the two, the correction to the green and blue channel is already solved, no matter which method you choose.