matlab颜色hsv,使用HSV颜色空间进行色彩检测

Color Detection Using HSV Color Space (Training and Testing)

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

-------------------------------

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值