function colorize(grayFile, markupFile, coloredFile)

%grayFile    = 'image.bmp'      ; % input grayscale image file
%markupFile  = 'markup.bmp'; % input markup image file. contains only the markup
%coloredFile = 'result.bmp'     ; % output colored image file

% read input files and normalize the values to [0.0 .. 1.0]
GrayImage   = double(imread(grayFile  )) / 255.0;
MarkupImage = double(imread(markupFile)) / 255.0;

% convert the markup image to binary (0 if no markup, 1 otherwise)
BinaryMarkupImage = (sum(MarkupImage, 3) < 2.99);
BinaryMarkupImage = double(BinaryMarkupImage);
%imshow(BinaryMarkupImage)

% convert the images to YUV color space
GrayImageYUV   = rgb2ntsc(GrayImage  );
MarkupImageYUV = rgb2ntsc(MarkupImage);

% combine the gray image and the markup image into one
CombinedImageYUV(:, :, 1) = GrayImageYUV  (:, :, 1); % Y channel is from the gray image
CombinedImageYUV(:, :, 2) = MarkupImageYUV(:, :, 2); % U channel is from the markup image
CombinedImageYUV(:, :, 3) = MarkupImageYUV(:, :, 3); % V channel is from the markup image

% colorize...
ColoredImage = getColorExact(BinaryMarkupImage, CombinedImageYUV);

% save the output
imwrite(ColoredImage, coloredFile);