In [1]:
import canont3i
r_cfa = canont3i.read_CR2_as_CFA('data/red.CR2')
g_cfa = canont3i.read_CR2_as_CFA('data/green.CR2')
b_cfa = canont3i.read_CR2_as_CFA('data/blue.CR2')

In [2]:
import numpy as np
y, x = np.mgrid[0:r_cfa.shape[0], 0:r_cfa.shape[1]]
pix00 = (np.mod(y, 2) == 0) & (np.mod(x, 2) == 0)
pix10 = (np.mod(y, 2) == 1) & (np.mod(x, 2) == 0)
pix01 = (np.mod(y, 2) == 0) & (np.mod(x, 2) == 1)
pix11 = (np.mod(y, 2) == 1) & (np.mod(x, 2) == 1)

In [3]:
rstats = [float(r_cfa[pix].sum())/r_cfa.sum() for pix in (pix00, pix10, pix01, pix11)]
gstats = [float(g_cfa[pix].sum())/g_cfa.sum() for pix in (pix00, pix10, pix01, pix11)]
bstats = [float(b_cfa[pix].sum())/b_cfa.sum() for pix in (pix00, pix10, pix01, pix11)]

In [4]:
rstats


Out[4]:
[0.22986521931911036,
 0.26275656311067508,
 0.26336528333627085,
 0.24401293423394374]

In [5]:
gstats


Out[5]:
[0.23910961452852442,
 0.25658639614683088,
 0.25675428915135667,
 0.24754970017328806]

In [6]:
bstats


Out[6]:
[0.21512158387164185,
 0.25881930481801574,
 0.25893464610165179,
 0.26712446520869065]

In [7]:
import matplotlib.pyplot as plt
%pylab inline
figure()
h00 = plt.hist(r_cfa[pix00], 50, normed=1, histtype='step', color='red', label='00')
h10 = plt.hist(r_cfa[pix10], 50, normed=1, histtype='step', color='green', label='10')
h01 = plt.hist(r_cfa[pix01], 50, normed=1, histtype='step', color='green', label='01')
h11 = plt.hist(r_cfa[pix11], 50, normed=1, histtype='step', color='blue', label='11')
plt.legend()
plt.title('red image')


Populating the interactive namespace from numpy and matplotlib
Out[7]:
<matplotlib.text.Text at 0x112353f10>

In [8]:
figure()
h00 = plt.hist(g_cfa[pix00], 50, normed=1, histtype='step', color='red', label='00')
h10 = plt.hist(g_cfa[pix10], 50, normed=1, histtype='step', color='green', label='10')
h01 = plt.hist(g_cfa[pix01], 50, normed=1, histtype='step', color='green', label='01')
h11 = plt.hist(g_cfa[pix11], 50, normed=1, histtype='step', color='blue', label='11')
plt.legend()
plt.title('green image')


Out[8]:
<matplotlib.text.Text at 0x12ef46690>

In [9]:
figure()
h00 = plt.hist(b_cfa[pix00], 50, normed=1, histtype='step', color='red', label='00')
h10 = plt.hist(b_cfa[pix10], 50, normed=1, histtype='step', color='green', label='10')
h01 = plt.hist(b_cfa[pix01], 50, normed=1, histtype='step', color='green', label='01')
h11 = plt.hist(b_cfa[pix11], 50, normed=1, histtype='step', color='blue', label='11')
plt.legend()
plt.title('blue image')


Out[9]:
<matplotlib.text.Text at 0x12f018f90>
Conclusion: red image is a little bit weird, but 00 pixels appear to be red microfilters, 01 and 10 pixels are green microfilters, and 11 pixels are blue microfilters.