MATLAB Answers


Replacing pixel value a another colour

Asked by FIR
on 6 Dec 2012

I have a image in that suppose i want to change the pixel colour ,how i can do it.assume i have peppers image,in that if i want to replace a pixel value say 5 by yellow colour or some other colour,please tell how to proceed

please asist


1 Answer

Answer by Image Analyst
on 6 Dec 2012

5 in which color channel and which color space? In general it's

rgbImage(row, column, 1) = 255;
rgbImage(row, column, 2) = 255;
rgbImage(row, column, 3) = 0;

for yellow (though I suspect you knew this already). If you have a mask (a binary image of where the 5's occur), it's somewhat different.


on 7 Dec 2012

Sir the problem is, the whole image becomes red or other color depending upon mean.i cannot see what objects are present in it possible to see the objects in image after making the block any colour

Yes. Like I said, that's what you asked for. We can do something different. Recall that I said to you: " If you want something different than that you need to say specifically what it is. It would be best if you made a shot at some code to explain it also." So, how did you get that image? If you can't give code, then at least describe the method in words.

on 8 Dec 2012
Yes i got that image that image  using 
my code is 
cform = makecform('srgb2lab');
lab = applycform(rgbBlock, cform); 
L_channel = lab(:,:,1);
A_channel = lab(:,:,2);
B_channel = lab(:,:,3);
L_channelNew = 100 - L_channel;
A_channelNew = 255-A_channel;
labNew = cat(3, L_channelNew, A_channelNew, B_channel);
cform2 = makecform('lab2srgb');
rgbNew = applycform(labNew,cform2);

i have attached a image below is it possible to give different colour for different objects

in this

i want to give different colour for fifferent objects ,say for green one colour ,brown one colour,others another colur,i tried with above code,but did not get actual result

plz assist

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!