MATLAB Answers

0

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

Asked by Asif Hasan on 30 Oct 2014
Latest activity Commented on by Asif Hasan on 31 Oct 2014
Sir,
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:

  0 Comments

Sign in to comment.

2 Answers

Answer by Image Analyst
on 30 Oct 2014
 Accepted Answer

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

  8 Comments

It works just fine. Here's proof:
s = load('binaryimage.mat')
binaryImage = s.show;
subplot(1,2,1);
imshow(binaryImage);
redAndBlueChannel = 255 * uint8(binaryImage);
greenChannel = 255 * ones(size(binaryImage), 'uint8'); % Green Everywhere.
rgbImage = cat(3, redAndBlueChannel, greenChannel, redAndBlueChannel);
subplot(1,2,2);
imshow(rgbImage);

Sign in to comment.


Answer by Doug Hull on 30 Oct 2014

Change colormap?
clf
im = round(rand(10));
imshow(im)
colormap([0 1 0; 1 1 1])

  1 Comment

Sir please explain i can't understand.

Sign in to comment.