MATLAB: How to use colormap

colormap

Hi everyone. I want to color in the letter 'a' from an image full of different characters. I have two images, one with the characters without the letter 'a'(call this A) and one with only the letter 'a'(call this B). I want to set the image B to the color red using colormap but not sure how to use this function in this situation.
Thanks for reading.

Best Answer

Cast the images to single. Then subtract them and take the absolute value. Then threshold it
subtractedImage = abs(single(imageA) - single(imageAwithLetter));
binaryImage = subtractedImage > thresholdValue;
Then create image B:
imageB = rgb2gray(imageA); % or just imageA if imageA is already grayscale.
imageB(imageB == 255) = 254; % Set existing 255 to 254
imageB(binaryImage) = 255; % Set only the letter pixels to 255.
imshow(imageB);
myColormap = gray(256);
myColormap (256,:) = [1 0 0]; % 256 goes to pure red.
colormap(myColormap);
colorbar;