1
\$\begingroup\$

I want to load a raw Bayer format image and convert it to RGB using OpenGL.

So far I have played around with glTexImage2D() and loaded a Bayer image as a monochrome texture. My question is: how can I do per-pixel operations on this texture so that I can convert it to an RGB image?

\$\endgroup\$
5
  • \$\begingroup\$ Are you asking how to load some specific file formats or asking how to provide non-RGB data to OpenGL? \$\endgroup\$
    – msell
    Commented Dec 19, 2014 at 8:30
  • \$\begingroup\$ Yes I'm asking is it possible to load Non-RGB i.e Raw Bayer as Textures? & Can we able to do some Interpolation in that? just like doing some processing in a Monochrome image! \$\endgroup\$
    – Balaji R
    Commented Dec 19, 2014 at 9:31
  • \$\begingroup\$ Which file format? \$\endgroup\$
    – msell
    Commented Dec 19, 2014 at 10:22
  • 1
    \$\begingroup\$ What are "Raw Bayer" images? \$\endgroup\$ Commented Dec 19, 2014 at 12:58
  • 1
    \$\begingroup\$ @SurvivalMachine: en.wikipedia.org/wiki/Bayer_filter \$\endgroup\$ Commented Dec 19, 2014 at 14:50

1 Answer 1

2
\$\begingroup\$

This isn't a trivial task for someone new to graphics programming, I'm assuming you know how to write fragment shaders and sample textures.

To convert the Bayer image to an RGB texture you'll want to point sample the monochrome Bayer image, and do the interpolation in the fragment shader.

For each destination pixel, you'll know the value of one channel - the one for the colour of the filter over that pixel. For the other two channels you'll need to sample some of the surrounding pixels and interpolate. This gets more complicated for edge pixels, and for that reason the easy option is to throw away a pixel or two along each edge of the result.

Let's say the filter looks like this, where R, G and B represent the colour of the filter over the pixel:

RGRGRGRG
GBGBGBGB
RGRGRGRG
GBGBGBGB

For each R pixel, one way to calculate the G value is to take the average of the four pixels each side of it, as they all have a green filter. To calculate the B value you can do the same thing diagonally.

In pseudocode a basic conversion to RGB would look something like this:

if (x % 2 == 0 && y % 2 == 0)
{
  // Red pixel in filter
  result.r = bayer[x,y];
  result.g = (bayer[x+1,y] + bayer[x-1,y] + bayer[x,y+1] + bayer[x,y-1]) * 0.25;
  result.b = (bayer[x+1,y+1] + bayer[x+1,y-1] + bayer[x-1,y+1] + bayer[x-1,y-1]) * 0.25;
}
else
// TODO: Handle the other cases
\$\endgroup\$
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .