function [R,G,B]=colorInterp0(r,g,b);
% [R,G,B]=colorInterp0(r,g,b);
%
% Written by Bao-Jun Jiang
%
% This function interpolates the colors r, g, and b for the
% bayer pattern (as created by the command bayer), and returns
% the [R,G,B] matrices with the missing color values filled
% by using the closest neighboring pixel (of that color) value on
% the left uppermost side of the matrix.
% The bayer pattern is assumed to be that of the following
%
%	GRGRGRGR...
%	BGBGBGBG...
%	GRGRGRGR...
%	BGBGBGBG...
%


R=r;
G=g;
B=b;
[NumOfRow, NumOfColumn]=size(R);

%=============================================
%for pixels that contain red information only
%=============================================

for j=1:floor(NumOfColumn/2),
     G(1,2*j)=G(1,2*j-1);
     B(1,2*j)=B(2,2*j-1);
end;

for i=1:floor(NumOfRow/2-1),
   for j=1:floor(NumOfColumn/2),
       G(2*i+1,2*j)=G(2*i+1,2*j-1);
       B(2*i+1,2*j)=B(2*i,2*j-1);
   end;
end;


%===============================================
%%for pixels that contain blue information only
%===============================================
for i=1:floor(NumOfRow/2),
      G(2*i,1)=G(2*i-1,1);
      R(2*i,1)=R(2*i-1,2);
end;
	    
for i=1:floor(NumOfRow/2),
  for j=1:round(NumOfColumn/2-1),
     G(2*i,2*j+1)=G(2*i,2*j);
     R(2*i,2*j+1)=R(2*i-1,2*j);
    end;
end;
		
%===============================================
%%for pixels that contain green information only
%===============================================

% even rows
    
for i=1:floor(NumOfRow/2),
  for j=1:floor(NumOfColumn/2),
      R(2*i,2*j)=R(2*i-1,2*j);
      B(2*i,2*j)=B(2*i,2*j-1);
  end;
end;
			
%odd rows

R(1,1)=R(1,2);
B(1,1)=B(2,1);
for j=1:round(NumOfColumn/2-1),
    R(1,2*j+1)=R(1,2*j);
    B(1,2*j+1)=B(2,2*j+1);
end;

for i=1:round(NumOfRow/2-1),
  R(2*i+1, 1)=R(2*i+1,2);
  B(2*i+1, 1)=B(2*i,1);
  for j=1:round(NumOfColumn/2-1),
     R(2*i+1,2*j+1)=R(2*i+1,2*j);
     B(2*i+1,2*j+1)=B(2*i,2*j+1);
  end;
end;



