function maskedIm = bayerCFA(filename)
%bayerCFA returns a Bayer filtered RGB array of values between 0.0 and 1.0
% Gives [R G R G...
%        G B G B...
%        R G R G...
%        . . . .
%        . . . .
%        . . . .               ]

im = imread(filename);
imDouble = cast(im, 'double') ./ 255;

imR = imDouble(:,:,1);
imG = imDouble(:,:,2);
imB = imDouble(:,:,3);

imSize = size(im);

maskR = zeros(imSize(1), imSize(2));
maskR(1:2:end, 1:2:end) = 1;

maskB = zeros(imSize(1), imSize(2));
maskB(2:2:end, 2:2:end) = 1;

maskG = zeros(imSize(1), imSize(2));
maskG(1:2:end, 2:2:end) = 1;
maskG(2:2:end, 1:2:end) = 1;

maskedImR = imR .* maskR;
maskedImG = imG .* maskG;
maskedImB = imB .* maskB;

maskedIm(:,:,1) = maskedImR;
maskedIm(:,:,2) = maskedImG;
maskedIm(:,:,3) = maskedImB;



%imshow(maskedIm)