How to count the number of colored objects in a picture?

10 views (last 30 days)
Hi Everyone I am just starting image processing with matlab, I need to find how many colored pins in the picture attached and how many of each color and then find and count individual colors, then detect the white and transparent pins can someone help please and keep in mind I never did any image processing before what so ever.
  2 Comments
dusi jayasree
dusi jayasree on 28 Aug 2017
i m a newbie..and wanted to know if we can count the colors in as image directly by any process or count the colors present in image by segmentation....is it possible to count colors after an image segmentation..???plz help me wit th is question
Image Analyst
Image Analyst on 28 Aug 2017
Edited: Image Analyst on 28 Aug 2017
I'd probably convert to HSV color space and threshold on saturation. Then I'd convert to lab colorspace with rgb2lab() and get the lab mean for each blob (pushpin). Any blobs that are within a certain distance (Delta E color difference) of each other, I'd consider them to be the same color pushpin. Then count the number of clusters you have after this merging operation. This should work for most colored pushpins, though the white and clear ones will be problematic and might have to be detected by a different algorithm.

Sign in to comment.

Accepted Answer

Carl
Carl on 6 Feb 2017
Edited: Carl on 6 Feb 2017
It looks like you'd like to perform some standard image segmentation. See the following page for an example on doing Color-based Segmentation:
https://www.mathworks.com/help/images/examples/color-based-segmentation-using-k-means-clustering.html?prodcode=IP&language=en
You should also take a look at the following tutorial on image segmentation:
In general, you could convert your image to a L*a*b* colorspace, classify each color with clustering, label your original image, and then count each component or manipulate your image as necessary.

More Answers (1)

Image Analyst
Image Analyst on 6 Feb 2017
See my Color segmentation demos in my File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
As far as determining how many colors there are you'll have to use some unsupervised clustering methods in the Statistics and Machine Learning Toolbox. Since you don't know how many colors in advance, you can't use easy methods like kmeans or k-nearest neighbor. See http://www.mathworks.com/help/stats/cluster-analysis.html At one extreme, you could consider that every pixel in the image is a different color, so you probably have literally thousands of unique colors, but you don't want that so you have to do cluster analysis.
  1 Comment
NASADUDE
NASADUDE on 7 Feb 2017
Hi Image Analyst I am trying all this but again I am very new and this is way over my head, anyway I can have some direct contact to you for questions ?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!