How to change particular pixel color of a binary image to other color?

7 views (last 30 days)
I have a binary image and i want to change the color of the black pixel to green. How do i do that ? Please help. Thanks in advance.
This is the binary image:

Accepted Answer

Image Analyst
Image Analyst on 30 Oct 2014
Try this:
%grayImage = imread('cameraman.tif');
%binaryImage = grayImage > 128;
redAndBlueChannel = 255 * uint8(binaryImage);
greenChannel = 255 * ones(size(binaryImage), 'uint8'); % Green Everywhere.
rgbImage = cat(3, redAndBlueChannel, greenChannel, redAndBlueChannel);
Remove the % if you want to demo it using a standard MATLAB demo image.

Sign in to comment.

More Answers (1)

Doug Hull
Doug Hull on 30 Oct 2014
Change colormap?
im = round(rand(10));
colormap([0 1 0; 1 1 1])


Find more on Colormaps in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!