MATLAB: How to change the color of the black and white image without using a FOR loop

changingcolorcolormapMATLAB

I have an image that is black and white (binary matrix). I want to change the white pixels into red pixels. I would like to do that without using a FOR loop.

Best Answer

In order to change current pixel color to another color for the whole image, create your own colormap. For example if the image is black and white (binary matrix), you can convert white pixels into red pixels by executing a code similar to the following:
I = eye(100);
imshow(I);
map = [0 0 0;1 0 0]; % black and red color
colormap(map);
Related Question