Code covered by the BSD License  

Highlights from
Color Detection Using HSV Color Space (Training and Testing)

5.0

5.0 | 3 ratings Rate this file 78 Downloads (last 30 days) File Size: 165.72 KB File ID: #18440
image thumbnail

Color Detection Using HSV Color Space (Training and Testing)

by Theodoros Giannakopoulos

 

23 Jan 2008 (Updated 24 Jan 2008)

The provided Matlab functions demonstrate a simple method for training and testing a color detection

| Watch this File

File Information
Description

The provided Matlab functions demonstrate a simple method for training and testing a color detection system. In general, a color detection algorithm searches an image for pixels that have a specific color. In this demo the HSV color space has been used, instead of the RGB space. According to that model, H(ue) dimension represents the "color", S(aturation) dimension represents the dominance of that color and the V(alue) dimension represents the brightness. Therefore, the color detection algorithm can search in terms of color position and color "purity", instead of searching for specific RGB values. We have to note here, that in order to detect the desired color, it is needed to define a tolerance in each HSV dimension. For example a tolerance equal to 0.050 in the H dimension means that the algorithm will detect pixels whose H value has a distance (from the desired value) less than 0.050.

 For training the color detection scheme (i.e. for calculating the average HSV values of your objects of interest), you just have to run the getHSVColorFromDirectory() function on an known set of JPG images, stored all in a specific directory. For exaple:

HSV = getHSVColorFromDirectory('train');

This will open all JPG images in "train" folder and for each image you will be prompt to select small (5x5) areas of interest (by left clicking).

The returned value (HSV) is a Mx3 matrix (M is the number of images): each row of that matrix corresponds to the median hsv value of the selected areas in the respective image. Therefore, by taking the average, or median of that matrix, you get an estimation of the hsv value you are searching for. Now, you are ready to go through the color detection process:

colorDetectHSV('balls.jpg', median(HSV), [0.05]);

This will detect all pixels of balls.jpg whose H value has a distance of less than 0.050 from the given color (2nd argument). If you want to specify tolerance for all 3 dimensions simply write:

colorDetectHSV('balls.jpg', median(HSV), [0.05 0.5 0.50]);

-------------------------------
Theodoros Giannakopoulos
http://www.di.uoa.gr/~tyiannak
-------------------------------

Required Products Image Processing Toolbox
MATLAB release MATLAB 7 (R14)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
03 Mar 2008 Semeth Jan  
23 Apr 2008 Ye Naung Kyaw Kyaw  
12 Sep 2008 jose Ramireez

Great man :) just what I was looking

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
color Theodoros Giannakopoulos 22 Oct 2008 09:44:12
color detection Theodoros Giannakopoulos 22 Oct 2008 09:44:12
hsv Theodoros Giannakopoulos 22 Oct 2008 09:44:12
rgb Theodoros Giannakopoulos 22 Oct 2008 09:44:12
color detection wit csc 10 Mar 2009 12:25:28
color detection Atakan 13 Jun 2009 05:46:13
rgb Jianhua 28 Oct 2009 14:32:40
hsv nirja 14 Nov 2011 00:26:38

Contact us at files@mathworks.com