function B=rgbtobayer(A)
% usage
%        B=rgbtobayer(A)
% purpose
%        converts RGB imager to Bayer pixel pattern%
% input   
%        A = RGB image
% output
%        B = Bayer pixel pattern image (RGB)
% Take a real image, and convert into three sub images of RGB, according
% to the Bayer pattern.
%
% G R G
% B G B
% G R G
%      
%     R. Kakarala, Agilent Labs 
%     9 Feb 2000: Written 

[r,c,p]=size(A);
B=A;
% remove G & B from R plane, first G
B(1:2:r,1:2:c,1)=zeros(size(B(1:2:r,1:2:c,1)));
B(2:2:r,2:2:c,1)=zeros(size(B(2:2:r,2:2:c,1)));
% now B
B(2:2:r,1:2:c,1)=zeros(size(B(2:2:r,1:2:c,1)));
% remove R & B from G plane, first R
B(1:2:r,2:2:c,2)=zeros(size(B(1:2:r,2:2:c,2)));
% now B
B(2:2:r,1:2:c,2)=zeros(size(B(2:2:r,1:2:c,2)));
% now remove R & G from B plane, first R
B(1:2:r,2:2:c,3)=zeros(size(B(1:2:r,2:2:c,3)));
% now G
B(1:2:r,1:2:c,3)=zeros(size(B(1:2:r,1:2:c,3)));
B(2:2:r,2:2:c,3)=zeros(size(B(2:2:r,2:2:c,3)));

