Changing pixel color to white

Hi, I am a newbee to Matlab. I want to change the brown color of every red blood cells into white. Could someone please help me how to do it? I want to read every pixel in image, and, if it found this color in the image, then the program should change it to white color. Thanks in advance.

 Accepted Answer

Image Analyst
Image Analyst on 25 Nov 2014
Are you sure you want to turn them into pure, solid white? Why do you want to do this? Do you want to estimate background? If you do want pure white, just take the green channel (which will give you the best contrast, not the red channel obviously) and threshold around 121 to create a mask. Then use the mask to set all three color channels to 255.
If you want a better job, then do color segmentation like in my File Exchange.

5 Comments

Thanks for your reply actually i am doing this so that all the brown pixels turn into white and only the infected red blood cells remains in the pictures like in picture below.can you please help in this.Thanks
Image Analyst
Image Analyst on 25 Nov 2014
Edited: Image Analyst on 25 Nov 2014
But why do you want them white? Why not just segment out the ones you want? If you want purple, you can get purple. If you want brown, get just the brown. Why don't you say what you really want to measure , rather than spell out a way that you think will achieve that? For example, I want to count the number of purple blobs per frame, or I want their average color, size, whatever.... The problem is some people, like Sanya, will just do what you say even though what you said is not the best way to approach what you really want .
Umer Siddique
Umer Siddique on 25 Nov 2014
Edited: Umer Siddique on 25 Nov 2014

Sorry Sir you are saying right my approach might be wrong what i want is this that i only want to extract the infected red blood cells which are shown in below picture in the circles.i am total new in image processing so don't know much how to do this can you kindly guide me how to achieve this.i want to make program that can detect these infected red blood cells in microscopic images.

You need to do color segmentation. Changing the brown cells to white is not the correct approach. If you have the stats toolbox, try this demo: http://www.mathworks.com/products/demos/image/color_seg_k/ipexhistology.html
If you don't have that toolbox, try to tweak the settings in my "Simple color detection by hue" demo here: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
Thanks alot :)

Sign in to comment.

More Answers (1)

I assume your image is an RGB image. Use this to get only the red plane:
Image_r = Image(:,:,1)
You have to know the intensity value of the color which you wish to replace.
You can use the 'find' command in MATLAB.
ind_plain = find(Image_r == old_value);
Image_new (ind_plain) = new_value;

3 Comments

can you please explain in detail thanks.
Out of the MXNX3 (24 bit) image, this extracts the first plane, i.e., Red plane:
Image_r = Image(:,:,1)
Suppose the value of "brown pixel" that you want to replace is 120.
ind_plain = find(Image_r == 120);
"ind_plain" contains the indices of all pixels with those values
Image_r (ind_plain) = 255
Now, the corresponding pixels in red plane is changed to 255.
Similarly, extract the blue and green planes:
Image_Blue = Image(:,:,2);
Image_Green = Image(:,:,3);
Replace the same pixel indices with 255 (for white, R, G and B is 255)
Image_Blue (ind_plain) = 255;
Image_Green(ind_plain) = 255;
New_image = (Image_r, Image_Blue,Image_Green)
To get a better understanding, you can execute these and observe the results in each stage.
Thank you Sanya for the help :)

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!