Original discussion: https://www.magiclantern.fm/forum/index.php?topic=25781.msg209998#msg209998
Let's try a simulation of these LiveView binning modes.
%%shell
wget -c -q http://a1ex.magiclantern.fm/bleeding-edge/lv-binning/stedda-1080p/19020007.DNG
# read the image and crop some interesting area
pkg load image
a = read_raw('19020007.DNG');
a = a(end/2:end, end/2:end);
a = a(:, round(end/4):round(end*3/4));
% showing the red Bayer channel only, to keep things simple
imshow(a(1:2:end, 1:2:end),[])
# 1x3 column binning simulation
# (showing the red Bayer channel only)
bin1x3 = imfilter(a, [1 0 1 0 1] / 3)(:, 3:3:end);
imshow(bin1x3(1:2:end,1:2:end), [])
# 3x1 line skipping simulation
# (showing the red Bayer channel only)
skip3x1 = a(3:3:end, :);
imshow(skip3x1(1:2:end,1:2:end), [])
# 3x3 line skipping simulation, i.e. what most Canon DIGIC 4/5 DSLRs do
# (showing the red Bayer channel only)
lineskip3x3 = imfilter(a, [1 0 1 0 1] / 3)(3:3:end, 3:3:end);
imshow(lineskip3x3(1:2:end,1:2:end), [])
# 3x3 binning simulation, i.e. what what 5D3 does
# (showing the red Bayer channel only)
bin3x3 = imfilter(a, [1 0 1 0 1;
0 0 0 0 0;
1 0 1 0 1;
0 0 0 0 0;
1 0 1 0 1] / 9)(3:3:end, 3:3:end);
imshow(bin3x3(1:2:end,1:2:end), [])
# function to render the above Bayer images with dcraw
function im = render(bayer)
imwrite(uint16(bayer), "test.pgm");
# pgm2dng: http://a1ex.magiclantern.fm/bleeding-edge/pgm2dng.c
# note: pgm2dng hardcodes a black level of 2048 and a white level of 16382
system("pgm2dng test.pgm > /dev/null");
system("dcraw -a test.DNG");
im = im2double(imread('test.ppm'));
end
# render our test images
a_r = render(a);
bin1x3_r = render(bin1x3);
skip3x1_r = render(skip3x1);
lineskip3x3_r = render(lineskip3x3);
bin3x3_r = render(bin3x3);
# original (1:1 readout)
imshow(a_r)
# 1x3 column binning
imshow(bin1x3_r)
# 3x1 line skipping
imshow(skip3x1_r)
# 3x3 line skipping
imshow(lineskip3x3_r)
# 3x3 binning (a la 5D3)
imshow(bin3x3_r)
# try to recover the original full-res image from binned versions
# TODO: use some smarter interpolation algorithms for this, possibly before the debayering step
from_bin1x3 = imresize(bin1x3_r, size(a_r)(1:2));
from_skip3x1 = imresize(skip3x1_r, size(a_r)(1:2));
from_lineskip3x3 = imresize(lineskip3x3_r, size(a_r)(1:2));
from_bin3x3 = imresize(bin3x3_r, size(a_r)(1:2));
# recovered from 1x3 column binning
imshow(from_bin1x3)
# recovered from 3x1 line skipping
imshow(from_skip3x1)
# recovered from 3x3 line skipping
imshow(from_lineskip3x3)
# recovered from 3x3 binning
imshow(from_bin3x3)
Happy pixel peeping!