1x3 "column binning" vs 3x1 "line skipping" vs 3x3 binning/skipping¶

Let's try a simulation of these LiveView binning modes.

In [1]:
%%shell
wget -c -q http://a1ex.magiclantern.fm/bleeding-edge/lv-binning/stedda-1080p/19020007.DNG
In [2]:
# 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));
In [3]:
% showing the red Bayer channel only, to keep things simple
imshow(a(1:2:end, 1:2:end),[])
In [4]:
# 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), [])
In [5]:
# 3x1 line skipping simulation
# (showing the red Bayer channel only)
skip3x1 = a(3:3:end, :);
imshow(skip3x1(1:2:end,1:2:end), [])
In [6]:
# 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), [])
In [7]:
# 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), [])
In [8]:
# 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
In [9]:
# render our test images
a_r = render(a);
bin1x3_r = render(bin1x3);
skip3x1_r = render(skip3x1);
lineskip3x3_r = render(lineskip3x3);
bin3x3_r = render(bin3x3);
In [10]:
# original (1:1 readout)
imshow(a_r)
In [11]:
# 1x3 column binning
imshow(bin1x3_r)
In [12]:
# 3x1 line skipping
imshow(skip3x1_r)
In [13]:
# 3x3 line skipping
imshow(lineskip3x3_r)
In [14]:
# 3x3 binning (a la 5D3)
imshow(bin3x3_r)
In [15]:
# 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));
In [16]:
# recovered from 1x3 column binning
imshow(from_bin1x3)
In [17]:
# recovered from 3x1 line skipping
imshow(from_skip3x1)
In [18]:
# recovered from 3x3 line skipping
imshow(from_lineskip3x3)
In [19]:
# recovered from 3x3 binning
imshow(from_bin3x3)

Happy pixel peeping!