Identify areas of an image based on their surroundings

10 views (last 30 days)
How would you identify specific points in an image based on the pixels around the point(s) that you wish to identify?
For example, if I had an image with lots of different colors but I only wanted to find the blue areas which are next to green areas and ignore everything else.
I'm sure the first step in this example would be to pass a filter over the image to remove all colors apart from green and blue but I wouldn't know where to go from there in eliminating green and blue parts which are not adjacent.

Accepted Answer

Sean de Wolski
Sean de Wolski on 12 Jul 2011
No. The first step is how do you define "green" "blue" and "red". Once you have that - then you pass a filter over the image!
The simplest way to detect a color is to just require that a specific color's channel be greater than the other two color's channels.
red = rgb(:,:,1)>(max(rgb(:,:,[2 3]),[],3)+30);
%red channel must be 30 values greater than green/blue channels.
Now you can use a filter. The easiest method for judging adjacency is to use the distance transform - bwdist. Require that an object be "blue" and withing x pixels of a "green" object. etc.
Good Luck!

More Answers (0)

Community Treasure Hunt

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

Start Hunting!