function I = markpixels(I, mask, color)
% MARKPIXELS Mark pixels in an image according to a mask.
%
% This function takes and input image I and sets all of
% the pixels corresponding to MASK to the RGB color COLOR.
%
% function I = MARKPIXELS(I, MASK, COLOR)
% Parameters:
%      I     - Input image, can be either grayscale or RGB
%      MASK  - Logical mask for positions to color
%      COLOR - RGB triplet for color to use
% 
% Example:
%     I = imread('circuit.tif');
%     BW = edge(I,'canny');
%     COLOR = [0, 0, 255];   % Blue
%     Imark = markpixels(I, BW, COLOR);
%     figure, imshow(I);
%     figure, imshow(Imark);

if ( ~islogical(mask) )
  error('MASK must be a logical');
end

if ( length(color) ~= 3 )
  error('COLOR must be a 3-element vector for an RGB color');
end

if ( ndims(I) == 2 )
  R = I;
  G = I;
  B = I;
elseif ( ndims(I) == 3)
  R = I(:,:,1);
  G = I(:,:,2);
  B = I(:,:,3);
else
  error('I must either be a 2 dimensional or 3 dimensional matrix');
end

R(mask) = color(1);
G(mask) = color(2);
B(mask) = color(3);

I = cat(3, R, G, B);
