No BSD License  

Highlights from
Remosaic of RGB image array

from Remosaic of RGB image array by Ketan Patel
Converts a MxNx3 color image array into a 2Mx2N intensity mosaic.

ReMosaic (A)
function B = ReMosaic (A)

% REMOSAIC converts a NxMxP RGB image array into 2Nx2M intensity array
% i.e. the origianlly generated mosaic from a Bayer sensor
%
% function B = ReMosaic(A)
%
% A is a NxMxP matrix of a NxM image with P color pages
%    P(1) -> red; P(2) -> green; P(3) -> blue
% by default, a standard sRGB Bayer mosaic sensor is assumed
% where sensor has NxM array of cells, each being 2x2 mosaic tile
% as following:   G R   
%                 B G
% The sensor is assumed to composed of 2N x 2M array of light 
% sensing elemements
%    (see http://www.siliconimaging.com/RGB%20Bayer.htm)
% 
% Output B would be the original 2Nx2M mosiac intensity array:
%
%   G11 R11 G12 R12 ... G1M R1M
%   B11 G11 B12 G12 ... B1M G1M
%               .
%           Gnm Rnm 
%           Bnm Gnm 
%               .   
%   GN1 RN1     ....    GNM RNM
%   BN1 GN1     ....    BNM GNM
%
% Color page 2 (green) is simply replicated assuming that it is
% the average value of the two G pixels of the sensor
%
% This function is written for use in capturing a strictly monochrome 
% image, like actively illuminated IR image, with a color sensor.  
% 
% by Ketan M. Patel, 8 May 2009
%    Princeton Lightwave Inc.
%

[Ny,Nx,Nc]  = size(A);  % determine dimension of image matrix

B(2*Ny,2*Nx)= 0;        % initiallize the mosaic array

idy     = 1:Ny;
idx     = 1:Nx;

% interleave the color pages in to mosaic arry 

B(2*idy-1, 2*idx-1) = A(idy,idx,1);     % interleave the red page
B(2*idy  , 2*idx)   = A(idy,idx,3);     % interleave the blue page
B(2*idy  , 2*idx-1) = A(idy,idx,2);     % interleave the green page
B(2*idy-1, 2*idx)   = A(idy,idx,2);     % interleave the green page in the
                                        % 2nd location

Contact us at files@mathworks.com