Code covered by the BSD License  

Highlights from
Simple color detection by hue

4.18182

4.2 | 13 ratings Rate this file 154 Downloads (last 30 days) File Size: 6.56 KB File ID: #28512
image thumbnail

Simple color detection by hue

by

 

Detect yellow regions in an image via thresholding in HSV color space.

| Watch this File

File Information
Description

This script is a demo that shows you how to find objects of a certain color in an image. For this example I'm using the standard onion, peppers, or kids image that ships with the Image Processing Toolbox. You can also select one of your own color images instead if you wish. Then I separate the image into its component hue, saturation, and value color bands. I compute thresholds, and ultimately find a mask for the yellow objects. Prompts will guide you through the demo step by step. I multiply this mask by the original image to show the image with only the yellow objects showing and everything else blacked out. This script can be adapted to find other colors (white, green, blue, yellow, etc.)

If you want to do any measurements of the objects, I refer you to my blob measurement demo file at http://www.mathworks.com/matlabcentral/fileexchange/25157

Requires the Image Processing Toolbox. Tested with MATLAB release R2010a.

Acknowledgements

Image Segmentation Tutorial ("Blobs Demo") and Simple Color Detection inspired this file.

MATLAB release MATLAB 7.10 (R2010a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (28)
20 Jun 2014 Jacques Fourie  
12 Feb 2014 XIAOMIN  
09 Feb 2014 Shrikant

Hi,
I m trying with this. But, im getting error. While getting histogram for Blue, the captions gets reversed just like mirrored image.
How to get rid of it...???

02 Dec 2013 Vanessa

Hi, just want to ask im a newbie and I find matlab really amazing.
Im planning to do a color measurement device using matlab script. How am I going to start? Or, what should I first consider? Thanks!!!

10 Nov 2013 Rishi Pal Singh  
01 May 2013 Tarmizi Mohamad

hi bro,
how can I detecting the green region?

04 Oct 2012 Ibrahim Qdemat  
04 Oct 2012 Ibrahim Qdemat  
18 Aug 2012 Anselm Griffin  
18 Aug 2012 Anselm Griffin  
22 Jun 2012 Matt Wang  
22 Jun 2012 Matt Wang

Good job. Thx 4 sharing! But I'm wondering how to change the color as I want... Is there any way to compute it? For example, how about the red one?

25 May 2012 Image Analyst

mischa: why the low rating? You can see how I do it simply by looking at my code. If you don't want fixed, hard coded values, then use my thresholding app to interactively select them.

25 May 2012 Image Analyst

cesar: You could use my interactive thresholding application (also in my File Exchange)

08 May 2012 cesar pulgarin ortiz

Hi, how can i compute the hi and low hsv thresholds for any color? i was trying with paint but i couldn't determine those numbers

02 Mar 2012 mishca nelson

I compute thresholds, and ultimately find a mask for the yellow objects.how do you do it?

14 Jul 2011 Jason  
12 Jun 2011 neo

hi....for bruno....the green hue thresholdlow=0.22..........
thresholdhigh=0.39.........
saturationthreshollow=0.15..
'''''''''''''''''hight=1
valuetresholdlow=0.15...
of course this values from my opinion...if you want to find yours:
1-go to paint.
2-select any color double clicks.
3-define customized colors.
you will find 2 systems-RGB-HSV...u will select your own threshold.......but i have always the same problem with the light intensity....good luck

09 Jun 2011 Bruno

Thanks for your work. How you know what value to put in "Assign the low and high thresholds for each color band"? I want to detect Green. How can i know what values i have to use? Thanks

09 Jun 2011 anju

Would you be able to help on me on the matlab coding for the object tracking of the using Hue value ? As i am new to matlab i couldnt find much details on it .

My object is to perform color calibration in order to define the upper and lower limit of the HUE value for to detect the color at any light intensity .

06 Jun 2011 neo

than you so much for answer me....i want to thank you very much for this good work....but i want to know the algorithgm that you use....thanx

05 Jun 2011 Image Analyst

neo: You might want to look at my "Delta E" color detection submission. This lets you define (by outlining it) the color that you want to find.

31 May 2011 neo

hi guys i want to know...the diffrent steps of this program or the algorytm....thanx guysssss....n_n

22 May 2011 German Espinal

Hi guys !!! I need to capture a primary color card with my webcam, then I need to determine what color is it ??? Can someone of you Help me please with the MatLab code ???? TKS A lot !!!

11 May 2011 neo

thanx for this good works....but the others colors for exp the yelow and the magenta....how can i detect thissss...thanx againnnn..

22 Apr 2011 Image Analyst

Alain: You have to change the thresholds in the section that says "Assign the low and high thresholds for each color band." Red would have hue values less than about 0.1 and greater than about 0.9.

10 Apr 2011 Alain

How can I change the color detection to red?

14 Feb 2011 Nasser

a good work..

Contact us