### Author Topic: Understanding bayer, pixel res, and debayering.  (Read 7243 times)

#### ItsMeLenny

• Hero Member
• Posts: 930
• 550D
##### Understanding bayer, pixel res, and debayering.
« on: June 01, 2014, 07:02:09 AM »
Whilst I do have some knowledge on the subject, I am just trying to wrap my head around some last bits of understanding for that ahhhh moment.

Here is my example bayer pattern:
RGRGRG
GBGBGB
RGRGRG
GBGBGB

I'll get back to it.
When a sensor (such as 550D) is said to have a resolution of 5184×3456, is this the amount of pixels of different colours?
As a resolution that size does result in jpeg images that size, or is this all due to the way it debayers.

So would the above bayer pattern have a resolution of:
A) 6x4
B) 3x2 (grouping in 4s)
C) 5x3 (weird debayering which I think is happening)

Weird debayering example:
 RGGB GRBG RGGB GRBG RGGB GBRG BGGR GBRG BGGR GBRG RGGB GRBG RGGB GRBG RGGB
(Grouping of 'sensels' from my example bayer pattern above.)

Resulting in one less pixel each way because of the half a pixel on each end.

Or am I totally confused on everything.

The reason I ask also is to do with raw video; when recording 960x540 I was originally under the impression it would record 1920x1080 pixels (black and white of each bayered colour - if you get what I mean).

#### chmee

• Contributor
• Hero Member
• Posts: 1031
• raw2cdng
##### Re: Understanding bayer, pixel res, and debayering.
« Reply #1 on: June 01, 2014, 07:49:41 AM »
lets name the parts differently one part of the sensor is a sensel, a piece of a picture is a pixel. indeed every sensel ends as a pixel in the picture, but their values are 66% synthetic. look on the first sensel in the first row. its only red, therefore green and blue are recreated from neighbouring senselvalues. this mathematical technique is named demosaicing or debayering. thats the typical behaviour, yes.

your "weird" sensor example will end as a 10x6 pixel picture. your first example is a 6x4 picture (a).
if you record 1920x1080 (sensels), it will result in a 1920x1080 picture

#### ItsMeLenny

• Hero Member
• Posts: 930
• 550D
##### Re: Understanding bayer, pixel res, and debayering.
« Reply #2 on: June 01, 2014, 07:54:38 AM »
Sorry, my weird debayering example is the grouping of 'sensels',
so it related to the first picture, but i've grouped the sensels into pixels.

#### ItsMeLenny

• Hero Member
• Posts: 930
• 550D
##### Re: Understanding bayer, pixel res, and debayering.
« Reply #3 on: June 01, 2014, 07:58:42 AM »
if you record 1920x1080 (sensels), it will result in a 1920x1080 picture

Which is 960x540 red, 960x540 blue, and 960x1080 green?

#### chmee

• Contributor
• Hero Member
• Posts: 1031
• raw2cdng
##### Re: Understanding bayer, pixel res, and debayering.
« Reply #4 on: June 01, 2014, 08:15:40 AM »
if you wouldnt do a demosaicing, you would get this, yes. so, finally you can say, every bayer-based picture is 1/3 native, 2/3 synthetic.

#### a1ex

• Hero Member
• Posts: 12564
##### Re: Understanding bayer, pixel res, and debayering.
« Reply #5 on: June 01, 2014, 08:18:09 AM »
In this example, after debayering, you have 960x540 of real red data, and the rest is interpolated (guessed). Same for blue. Green has twice as much real resolution, so half of the green pixels are real, half interpolated.

The color resolution in a debayered image is usually lower, but most algorithms are able to reconstruct full-resolution luma by exploiting inter-channel correlation.

Check resolution with "dcraw -i -v". For example, on 5D3 photo:

Code: [Select]
`Thumb size:  5760 x 3840Full size:   5920 x 3950`
The small one is called "active area", and it has valid pixel data. The rest is called "optical black", and it's used by the electronics for black level clamping, and then by software for estimating noise level, fine-tuning black level and so on.

Canon JPEG is a little smaller: the JPEG size is 36 pixels smaller than the active area IIRC. With dcraw, you can squeeze a few more pixels (it's in the dcraw FAQ), but it may still throw away a tiny number of border pixels.

With raw video, the active area sizes (rounded a bit) is here: http://www.magiclantern.fm/forum/index.php?topic=6215

The exact sizes can be found from a silent picture (DNG), because they also include the optical black areas. Raw video does not record these, for speed reasons.

On 5D3, the full raw size is 2080x1318 (exact), active area is 1934x1290 (maybe 2-3 pixels more) , and the YUV buffer size is 1904x1274.

If you develop with "dcraw -h", you will skip the debayer process and get a half-resolution image, with no interpolated values. If you downsample it from a full-res debayered image, you should get better results (you can run some comparisons), so the guesswork from the debayering algorithms is usually pretty good.

Some good info: http://pixinsight.com/doc/tools/Debayer/Debayer.html

#### ItsMeLenny

• Hero Member
• Posts: 930
• 550D
##### Re: Understanding bayer, pixel res, and debayering.
« Reply #6 on: June 01, 2014, 11:15:34 AM »
Ok, I think I get it. Or at least I get it enough for me to be satisfied. I probably don't fully understand it from the perspective of someone who does
Thanks very much chmee and a1ex.

#### chmee

• Contributor
• Hero Member
• Posts: 1031
• raw2cdng
##### Re: Understanding bayer, pixel res, and debayering.
« Reply #7 on: June 01, 2014, 01:35:18 PM »
maybe this picture can help a little bit.

regards chmee