% function [out] = bayerSeparate(in)
% input: in, bayer pattern input image
% ouput: out, RGB image with only raw Bayer red data in R plane,
%        raw Bayer green data in G plane, raw blue data in B plane.
%        Plane #1 is red, #2 is green, #3 is blue.

function [out] = bayerSeparate(in)
rows=size(in,1);
cols=size(in,2);
out = zeros(size(in,1),size(in,2),3);

% Pattern looks like this:
% From trial and error.
% GB
% RG

g1 = in(1:2:rows,1:2:cols);
g2 = in(2:2:rows,2:2:cols);
b  = in(1:2:rows,2:2:cols);
r  = in(2:2:rows,1:2:cols);

% Now copy into color planes
out(1:2:rows,1:2:cols,2)=g1;
out(2:2:rows,2:2:cols,2)=g2;
out(1:2:rows,2:2:cols,3)=b;
out(2:2:rows,1:2:cols,1)=r;

