In this post we will learn to how filter color in Matlab. Matlab provide very good Image processing tool box with many ready made functions. Here I have illustrated a very basic method to filter color in Matlab. The concept is- in the 3D matrix of RGB color space, if the value at a particular pixel have more value in Red space than blue or Green, and if it is within a tolerance value then consider that pixel Red.

eg -

elseif

white(i,j)=0;

green(i,j)=0;

blue(i,j)=0;

Copy this code an save as .m file. then run this file.

eg -

elseif

**im(i,j,1)>200 & im(i,j,2)<50 & im(i,j,3)<50**white(i,j)=0;

green(i,j)=0;

blue(i,j)=0;

**red(i,j)=1;**Copy this code an save as .m file. then run this file.

*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*

*% ------------------------@author:- RITESH RANJAN*

*% -------- visit:- http://programing-tutorial.blogspot.com/*

*% ------I have used a simple method. There are many more complex*

*%--------------- methods too that I will discuss Later*

*% ------------Just copy it save a .m file run in MATLAB 7 or higher*

*% ----------------Don't forget to change the name of Image file*

*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*

clear;

im=imread('image.jpg'); %put image name here

imtool(im);

sz=size(im);

for i=1:sz(1)

for j=1:sz(2)

if im(i,j,1)>200 & im(i,j,2)>200 & im(i,j,3)>200

white(i,j)=1;

green(i,j)=0;

blue(i,j)=0;

red(i,j)=0;

elseif im(i,j,1)>200 & im(i,j,2)<50 & im(i,j,3)<50

white(i,j)=0;

green(i,j)=0;

blue(i,j)=0;

red(i,j)=1;

elseif im(i,j,1)<50 & im(i,j,2)>200 & im(i,j,3)<50

white(i,j)=0;

green(i,j)=1;

blue(i,j)=0;

red(i,j)=0;

elseif im(i,j,1)<50 & im(i,j,2)<50 & im(i,j,3)>200

white(i,j)=0;

green(i,j)=0;

blue(i,j)=1;

red(i,j)=0;

else

white(i,j)=0;

green(i,j)=0;

blue(i,j)=0;

red(i,j)=0;

end

end

end

imtool(white);

imtool(green);

imtool(blue);

imtool(red);

Hello. Mr. Ritesh. I want to ask you about color segmentation in Matlab.

ReplyDeleteCan you help me how to find a* value for green colour by converting RGB to CIElab colour space.

thnx bro...gud wrk keep it up..:)

ReplyDeletehello sir i want to find hidden object of image can u provide me code

ReplyDeletesir i need matlab code for image processing for our b.tech project please help

ReplyDeletesir,could u help us get matlab coding for image enhancement

ReplyDeletecan u send me time complexity of clustering

ReplyDeletesir i am doing project inorder to differentitate good an bad tomato in image processing using matlab .i want matlab code for this project.

ReplyDeletehello sir i need coding for homomorphic filtering, anisotropic filtering and bilateral filtering codings...

ReplyDeletehello sir i want to know that after showing image the matrix is generated in matlab so how can i modify,control,change dat matrix numbers???plzzz suggest.....

ReplyDeleteWrite an image processing algorithm to detect a linear scratch over an image as given in the figure 1a. For simplicity, here we can assume that the intensity of scratch is constant. Our output should show the scratch area in a separate image file like in the figure 1b. You should also show the length of scratch in the number of pixels at the command window.

ReplyDeletethank you very much ...

ReplyDeletehi sir i need your help for my project of image processing using matlab i need some info about matlab

ReplyDeleteI need to find the area covered by the green colour only(leaf); plaese send me the code; naveen.4skr@gmail.com

ReplyDeletehello sir,

ReplyDeleteim working on my final year project in which im sorting objects on the basis of colour using a conveyor belt and some actuators i.e. plungers,cylinders (to be decided) ...

sir i need a code which can tell whether the object under the camera is green, blue or red ?? i will be thankfull if you have something to share in this regard ... kindly mail the code to the following email

thankyou very much

ahsankhalid.mecha09@yahoo.com

hello sir i need coding for remove particular areas from an image based on color in matlab. please help me sir....

ReplyDeleteplease send me complete code algorithm & flow chart at rajatsharma.sharma143@gmail.com

ReplyDeleteI want to sort objects with 3 different shapes(circle,square,hexagon).....Pls send MATLAB codes for the above project @ s.sivanesan100@yahoo.com

ReplyDeleteIn addition to these projects you can have a look at these Matlab projects also;

ReplyDeleteRGB Image Compression using Discrete Cosine Transform: http://berksoysal.blogspot.com/2014/07/rgb-image-compression-using-discrete.html

Pseudo Coloring

http://berksoysal.blogspot.com/2014/05/ee431-introduction-to-image-video.html

All source codes are included, keep visiting for more Image Processing Projects.

removing pixels which are not related to the red

ReplyDeletecolour using a CY-based colour filter..in image.any one know...help mee sir/mam..

This comment has been removed by the author.

ReplyDelete