How can i detect Green and Blue color from an image?

4 views (last 30 days)
My project is about colors and shapes detection. I detected what the shape is, But my problem is how to detect the color in this case? like this image for example.
  2 Comments
Rik
Rik on 26 Feb 2018
This question is impossible to answer without an example and/or a description. Have a read here and here. It will greatly improve your chances of getting an answer.

Sign in to comment.

Accepted Answer

Cam Salzberger
Cam Salzberger on 26 Feb 2018
Hello Odai,
If you are able to determine the shape of objects in the image, then you likely have the location of the item as well - (row, col) of centroid, or maybe even dimensions or bounding box. If you are simply trying to answer an "is this object red or blue?", you could simply pick a pixel or a patch and check the greatest color channel:
if I(row, col, 1) > I(row, col, 2) && I(row, col, 1) > I(row, col, 3)
disp('Red!')
elseif I(row, col, 2) > I(row, col, 3)
disp('Green!')
else
disp('Blue!')
end
Of course, that's pretty suboptimal and naive, but it serves to illustrate. You can do something smarter by doing the average over the whole shape, or compare the average's RGB vector to some known colors to find what it is "closest" to.
Hope that helps!
-Cam

More Answers (0)

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!