function B = AddBorder(A,w,c)
% A is an nRows-by-nCols-by-3 uint8 color array that corresponds to some image I
% w is a real number that satisfies 0<=w<=1
% c is an rgb vector
% B is a uint8 color array with the property that imshow(B) looks like
% imshow(A) with a border. The border color is specified by c and
% the width of the border in pixels is the nearest integer to
% w times the smaller of nA and nB.

% Determine k = the border width in pixels
[nRows,nCols,z] = size(A);
k = floor(w*min(nRows,nCols));

% Initialize B to have the border color...
v = uint8(255*c);
B = zeros(nRows+2*k,nCols+2*k,3,'uint8');
B(:,:,1) = v(1);
B(:,:,2) = v(2);
B(:,:,3) = v(3);

% Insert the red, blue and green layers...
B(k+1:k+nRows,k+1:k+nCols,1) = A(:,:,1);
B(k+1:k+nRows,k+1:k+nCols,2) = A(:,:,2);
B(k+1:k+nRows,k+1:k+nCols,3) = A(:,:,3);