MATLAB: How to color a certain pixel value in an intensity image

image processingImage Processing Toolboxintensity imagepixel value

I have an intensity image and want to color the pixels which their intensity is 50. I want to color them red.In fact I want to replace pixels who's value is 50 with red. How can I do this?

Best Answer

Either convert to an RGB image and change the 50 gray level pixels to red color.
% get a map of where the pixels with gray level 50 are.
pixels50 = grayImage == 50;
% Create r, g, and b channels.
redImage = grayImage;
greenImage = grayImage;
blueImage = grayImage;
% Change the colors for the pixels that are gray level 50.
redImage(pixels50) = 255;
greenImage(pixels50) = 0;
blueImage(pixels50) = 0;
% Combine into a new RGB image.
rgbImage = cat(3, redImage, greenImage, blueImage);
or keep it as monochrome but apply a colormap
cmap = gray(256);
cmap(51, :) = [1 0 0];
colormap(cmap);