1. 在同时使用色调、饱和度和亮度值的组合的情况下这些区域中的每一个是可定义的。
    Each of these regions is definable using a combination of hue, saturation and luminance values simultaneously. Provided by gtcom
  2. 3
    您可以更改色调、饱和度、亮度、透明度、流动性比例和其他许多方面。
    You can change color hue, saturation, lightness, opacity, fluidity scale, and many more aspects. www.ibm.com
  3. 4
    背景视频包括像素,每个像素表示色调、饱和度和亮度(hsl)的值。
    The background video is comprised of pixels, each of which represents a value of hue, saturation and luminance ( hsl). Provided by gtcom
  4. 5
    一个这种颜色空间的示例是对使用者更有直观意义的hsl(色调、饱和度、亮度)空间。
    An example of one such color space is the hsl ( h ue, saturation, luminance) space, which is more intuitively meaningful to the user. Provided by gtcom
  5. 6
    本文提出了一种基于色调、饱和度和亮度联合概率分布的彩色图象分割方法。
    In this paper, we propose a new color image segmentation method, which bases on union probability density of hue, light and saturation. dict.cnki.net
  6. 7
    本文在快速HSI(色调、饱和度和亮度)变换空间基础上,采用了一种利用移动网格与动态窗口技术相结合的算法进行目标识别,达到了预期的效果。
    Based on rapid HSI transform space, a target identification algorithm is adopted, which combined a mobile grid and dynamic window technology. www.fabiao.net
  7. 8
    对归为非纹理类的图象,探讨了一种基于色调、饱和度和亮度联合概率分布的彩色图象分割方法。
    To non-texture images, a new color image segmentation method is proposed in this chapter, which based on union probability density of hue, light and saturation. dict.cnki.net
  8. 9
    将图像的RGB值转换成色调、饱和度和亮度值,并将色调和饱和度结合产生融合图像,以消除地表、天空等背景的影响。
    The color image was translated from RGB system to HSI system, and the hue, lightness and saturation images were acquired. In order to eliminate the influence of background of soil and sky, the hue and saturation data was combined and produced fusion image. dict.cnki.net
  9. 10
    由于RGB空间仅利用亮度信息而较少利用颜色信息,并且该空间三分量高度相关,与人类视觉倾向于用色调、饱和度和亮度共同描述彩色物体不一致,不适合于边缘检测任务。
    RGB color space using only the brightness information and less use of color information, and the space three components are highly correlated, human vision prefers to use hue, saturation and brightness to describe the color object is inconsistent, not suitable for edge detection task. www.fabiao.net
  10. 11
    本文通过在HSI空间对色调和饱和度进行合理划分,并对图像间色调、饱和度和亮度进行匹配、加权求和,给出了根据局部累积直方图计算图片间相似值的一种具体算法。
    Through experiment, we provide a concrete color image retrieval algorithm, which divides the hue and saturation in HSI color space, uses matching algorithm to two pictures and calculates similar amount. dict.cnki.net
  11. 12
    本文介绍一种适用于PAL制式电视终端的模拟式实时装置。该装置能按色调、饱和度与亮度对彩色图象进行分解显示,并对显示背景作适当的处理。
    A real time analogue apparatus is presented, which can be suitable for terminals of PAL television system and can segment-display color images with appropriate background by hue, saturation and brightness. dict.cnki.net
  12. 13
    本文提出了系统的评价思路和方案,从整体外观表现(颜色的多少、分布特征、均匀程度),到颜色的三要素(色调、饱和度、亮度),并结合成因进行讨论。
    A systemic way is suggested for appraisement, from the appearance to the 3 elements of color, i.e. from the amount, distributing, uniformity to the tone, saturation, brightness, and include the causing of color. dict.cnki.net
  13. 14
    图形和背景除了色调不同外,饱和度和亮度也应有区别。如果可能,应尽量避免在彩色背景上运用彩色文本。
    Objects and background should vary in brightness or saturation, in addition to hue, and color text on color backgrounds should also be avoided when possible. Provided by gtcom
  14. 15
    而当亮度和饱和度都大于各自的阈值时,颜色由其色调和饱和度来代表,而忽略不同亮度的影响。
    Otherwise color is represented by its hue and saturation, thus the influence of intensity is ignored. dict.cnki.net
  15. 16
    为研究四诊客观化,采用数码采集,并用计算机图像软件PHOTOSHOP60分别计算爪掌的RGB数值,然后换算成色调(H)、饱和度(S)、亮度(V)值,对爪色进行分析。
    To objectify the Chinese medical diagnosis, the RGB values of hind paws were calculated by Photoshop 6.0 and converted into hue, saturation and luminance, and contrasted with paw color. dict.cnki.net
  16. 17
    结果表明:碎膜样品的色调主要集中在绿色,其中3号样品的饱和度、亮度最高,但其色调偏黄;
    The result shows that the color tone of the broken films mainly focuses on green. The saturation and brightness of sample No. 3 is the highest, but its color tone is somewhat yellow. dict.cnki.net
  17. 18
    色调和饱和度的投影直方图反映了颜色的空间分布,而亮度的投影直方图则体现了图像的形状。
    The projective histograms of hue and saturation discribe the color distribution in space, and the projective histogram of intensity reflects the shape of the image. dict.cnki.net
  18. 19
    这对于给定的色调将具有对要包括在颜色空间的子集中的饱和度和亮度的范围进行加宽的效果。
    This would have the effect, for a given hue, of widening the ranges of saturation and luminance that are to be included in the subset of the color space. Provided by gtcom
  19. 20
    通过对球体彩色图像的亮度、色调和饱和度的分布特征的分析发现,球体图像颜色失真主要跟颜色的亮度分量有关,而与色调和饱和度分量关系不大。
    After analyzing the distribution characteristics of brightness, hue and saturation of ball images, it was found that the image color distortion was only related to brightness, but hue and saturation of images. dict.cnki.net

openCv RGB到HSV空间的学习



标签: opencvRGBHSV



2014-08-06 20:18 556人阅读 评论(0) 收藏 举报


本文章已收录于:







分类: opencv进化之旅(13)


作者同类文章 X




版权声明:本文为博主原创文章,未经博主允许不得转载。


这次我主要说说颜色空间,包括三个方面:RGB颜色空间,HSV颜色空间以及颜色空间的转换


RGB颜色空间介绍:


1:RGB颜色空间简介




         三基色原理:大多数的颜色可以通过红、绿、蓝<数学中基的概念>三色按照不同的比例合成产生,同样绝大多数单色光也可以分解成红绿蓝三种色光


         红绿蓝三基色按照不同的比例相加合成混色称为相加混色。其中一些混色的规律有:


                   红色+绿色 = 黄色


                   绿色+蓝色 = 青色


                   红色+蓝色 = 品红


                   红色+绿色+蓝色 = 白色


                   红色+青色 = 白色


                   绿色+品红 = 白色


                   蓝色+黄色 = 白色




得到青色、黄色、品红分别是红色、蓝色、绿色的补色。


 


3:亮度的定义:


         单色光的亮度强度各不相同,根据人的感受是:绿光最高,红光次之,蓝光最弱,假设得到的白光的强度为100%。如果用Y表示景物的亮度,则通常有:


                   Y= 0.299R + 0.587G + 0.114B


因为红﹑绿﹑蓝三基色能够合成自然界所有的色彩,因此在电子设备和软件中,经常使用红绿蓝三基色合成五颜六色的图像。用以上的相加混色所表示的颜色模式成为RGB模式


注意:


1:CvLoadImage(“”,0)所得到的图像即为灰度单通道图像,所对应的像素即为Y;而与split函数得到的单通道图像R,G,B不一样,但其亮度显示也是按照下图的直线来显示的<即为RGB空间的直线>


三通道图不一定是彩色的,彩色图一定是三通道的。



3:单通道图像亮度显示也是通过下图来显示的


得到上图的代码为:


[cpp] view plain copy print ?


#include <iostream>
#include "cv.h"
#include "highgui.h"
#include "cxcore.h"
using namespace std;
int main()
{
	IplImage *dst = cvCreateImage(cvSize(255, 255), 8, 3);
	for(int y = dst->height - 1; y >= 0; y--)
	{
		cvSet2D(dst, y,  dst->height - y - 1, cvScalar(255-y, 255-y, 255-y));
	}
	cvNamedWindow("show");
	cvShowImage("show", dst);
	cvWaitKey(0);
	cvReleaseImage(&dst);
	cvDestroyWindow("show");
	return 0;
}






HSV颜色空间



H:色调 0°对应红色, 120°对应绿色, 240°对应蓝色---对应不同的颜色 取值范围0~360度


S:饱和度  比若说:红色的纯度,越白纯度越低,取值范围0~1


V:亮度  比如你穿了一件红色衣服 在白天亮度较高(0~255之间)傍晚或者黄昏就比较低(0~255之间),即多少的光照上去反射出来被看见,取值范围0~255


如图:

颜色空间的转换


用到的核心函数有: cvConvertScale, cvSplit, cvMerge, cvCvtColor


需要注意的是:由于加载进来图像是uchar,最多只能是255,而opencv正常程序的结构显示H色调都会小于等于180<因为程序知道表示不了360,直接全部缩小到180>,而H色调的取值范围0~360,因此我们需要将图像转换成float类型,而cvConvertScale 可以实现放大缩小偏移同时可以做类型转换;之后我们可以将hsv各通道转换到0~255之间,使用到的函数仍然是cvConvertScale 。最后需要注意的一点是:CvShowImage显示的图像都会被当做RGB颜色空间的图像来处理.


下面给出这之间范围变化的代码:


1:没有考虑H(色调)范围的代码,此时H的范围只能在0~180之间。


代码:




[cpp] view plain copy print ?


#include <iostream>
#include "cv.h"
#include "highgui.h"
#include "cxcore.h"

using namespace std;

int main()
{
	IplImage *src = cvLoadImage("F:\\tongtong.jpg", 1);
	IplImage *hsv_img = cvCreateImage(cvGetSize(src), 8 , 3);
	IplImage *h_img = cvCreateImage(cvGetSize(src), 8, 1);
	IplImage *s_img = cvCreateImage(cvGetSize(src), 8, 1);
	IplImage *v_img = cvCreateImage(cvGetSize(src), 8, 1);

	cvCvtColor(src, hsv_img, CV_BGR2HSV);
	cvSplit(hsv_img, h_img, s_img, v_img, NULL);
	for(int y = 0; y < hsv_img->height; y++){
		for(int x = 0; x < hsv_img->width; x++)
		{
			cout << cvGetReal2D(h_img, y, x) << " ";
		}
		cout << endl;
	}
	cvNamedWindow("src", 0);
	cvShowImage("src", hsv_img);
	cvWaitKey(0);
	cvReleaseImage(&src);
	cvDestroyWindow("src");
	return 0;
}



2:将色调H的取值范围转换到0~360之间



[cpp] view plain copy print ?

#include <iostream>
#include "cv.h"
#include "highgui.h"
#include "cxcore.h"

using namespace std;

int main()
{
	IplImage *src = cvLoadImage("F:\\tongtong.jpg", 1);
	IplImage *src_float = cvCreateImage(cvGetSize(src),IPL_DEPTH_32F, 3);
	<span style="color: rgb(255, 0, 0);">cvConvertScale(src, src_float, 1.0, 0.0);
	IplImage *hsv_img = cvCreateImage(cvGetSize(src), IPL_DEPTH_32F , 3);
	IplImage *h_img = cvCreateImage(cvGetSize(src), IPL_DEPTH_32F, 1);
	IplImage *s_img = cvCreateImage(cvGetSize(src), IPL_DEPTH_32F, 1);
	IplImage *v_img = cvCreateImage(cvGetSize(src), IPL_DEPTH_32F, 1);
</span>
	cvCvtColor(src_float, hsv_img, CV_BGR2HSV);
	cvSplit(hsv_img, h_img, s_img, v_img, NULL);
	for(int y = 0; y < hsv_img->height; y++){
		for(int x = 0; x < hsv_img->width; x++)
		{
			cout << cvGetReal2D(h_img, y, x) << " ";
		}
		cout << endl;
	}
	cvNamedWindow("src", 0);
	cvShowImage("src", hsv_img);
	cvWaitKey(0);
	cvReleaseImage(&src);
	cvDestroyWindow("src");
	return 0;
}


3:将H,S,V的范围转化到0~255之间


[cpp] view plain copy print ?


1. #include <iostream>
2. #include "cv.h"
3. #include "highgui.h"
4. #include "cxcore.h"
5.   
6. using namespace
7.   
8. int
9. {  
10. "F:\\tongtong.jpg", 1);  
11.     IplImage *src_float = cvCreateImage(cvGetSize(src),IPL_DEPTH_32F, 3);  
12.     cvConvertScale(src, src_float, 1.0, 0.0);  
13.     IplImage *hsv_img = cvCreateImage(cvGetSize(src), IPL_DEPTH_32F , 3);  
14.     IplImage *h_img = cvCreateImage(cvGetSize(src), IPL_DEPTH_32F, 1);  
15.     IplImage *s_img = cvCreateImage(cvGetSize(src), IPL_DEPTH_32F, 1);  
16.     IplImage *v_img = cvCreateImage(cvGetSize(src), IPL_DEPTH_32F, 1);  
17. <span style="color: rgb(255, 0, 0);">  
18.     IplImage *h = cvCreateImage(cvGetSize(src), 8, 1);  
19.     IplImage *s = cvCreateImage(cvGetSize(src), 8, 1);  
20.     IplImage *v = cvCreateImage(cvGetSize(src), 8, 1);  
21.   
22.     cvCvtColor(src_float, hsv_img, CV_BGR2HSV);  
23.     cvSplit(hsv_img, h_img, s_img, v_img, NULL);  
24.     cvConvertScale(h_img, h, (1.0/360)*255, 0.0);  
25. // 因为S的取值范围为0~1
26.     cvConvertScale(v_img, v, 1.0, 0.0);</span>  
27. for(int
28. for(int
29.         {  
30. if(cvGetReal2D(h, y, x) > 200)cout << cvGetReal2D(h, y, x) << " ";  
31.         }  
32.         cout << endl;  
33.     }  
34. "src", 0);  
35. "src", hsv_img);  
36.     cvWaitKey(0);  
37.     cvReleaseImage(&src);  
38. "src");  
39. return
40.   
41. }




这次我主要说说颜色空间,包括三个方面:RGB颜色空间,HSV颜色空间以及颜色空间的转换


RGB颜色空间介绍:


1:RGB颜色空间简介




         三基色原理:大多数的颜色可以通过红、绿、蓝<数学中基的概念>三色按照不同的比例合成产生,同样绝大多数单色光也可以分解成红绿蓝三种色光


         红绿蓝三基色按照不同的比例相加合成混色称为相加混色。其中一些混色的规律有:


                   红色+绿色 = 黄色


                   绿色+蓝色 = 青色


                   红色+蓝色 = 品红


                   红色+绿色+蓝色 = 白色


                   红色+青色 = 白色


                   绿色+品红 = 白色


                   蓝色+黄色 = 白色




得到青色、黄色、品红分别是红色、蓝色、绿色的补色。


 


3:亮度的定义:


         单色光的亮度强度各不相同,根据人的感受是:绿光最高,红光次之,蓝光最弱,假设得到的白光的强度为100%。如果用Y表示景物的亮度,则通常有:


                   Y= 0.299R + 0.587G + 0.114B


因为红﹑绿﹑蓝三基色能够合成自然界所有的色彩,因此在电子设备和软件中,经常使用红绿蓝三基色合成五颜六色的图像。用以上的相加混色所表示的颜色模式成为RGB模式


注意:


1:CvLoadImage(“”,0)所得到的图像即为灰度单通道图像,所对应的像素即为Y;而与split函数得到的单通道图像R,G,B不一样,但其亮度显示也是按照下图的直线来显示的<即为RGB空间的直线>


三通道图不一定是彩色的,彩色图一定是三通道的。



3:单通道图像亮度显示也是通过下图来显示的


得到上图的代码为:


[cpp] view plain copy print ?


#include <iostream>
#include "cv.h"
#include "highgui.h"
#include "cxcore.h"
using namespace std;
int main()
{
	IplImage *dst = cvCreateImage(cvSize(255, 255), 8, 3);
	for(int y = dst->height - 1; y >= 0; y--)
	{
		cvSet2D(dst, y,  dst->height - y - 1, cvScalar(255-y, 255-y, 255-y));
	}
	cvNamedWindow("show");
	cvShowImage("show", dst);
	cvWaitKey(0);
	cvReleaseImage(&dst);
	cvDestroyWindow("show");
	return 0;
}






HSV颜色空间



H:色调 0°对应红色, 120°对应绿色, 240°对应蓝色---对应不同的颜色 取值范围0~360度


S:饱和度  比若说:红色的纯度,越白纯度越低,取值范围0~1


V:亮度  比如你穿了一件红色衣服 在白天亮度较高(0~255之间)傍晚或者黄昏就比较低(0~255之间),即多少的光照上去反射出来被看见,取值范围0~255


如图:

颜色空间的转换


用到的核心函数有: cvConvertScale, cvSplit, cvMerge, cvCvtColor


需要注意的是:由于加载进来图像是uchar,最多只能是255,而opencv正常程序的结构显示H色调都会小于等于180<因为程序知道表示不了360,直接全部缩小到180>,而H色调的取值范围0~360,因此我们需要将图像转换成float类型,而cvConvertScale 可以实现放大缩小偏移同时可以做类型转换;之后我们可以将hsv各通道转换到0~255之间,使用到的函数仍然是cvConvertScale 。最后需要注意的一点是:CvShowImage显示的图像都会被当做RGB颜色空间的图像来处理.


下面给出这之间范围变化的代码:


1:没有考虑H(色调)范围的代码,此时H的范围只能在0~180之间。


代码:




[cpp] view plain copy print ?


#include <iostream>
#include "cv.h"
#include "highgui.h"
#include "cxcore.h"

using namespace std;

int main()
{
	IplImage *src = cvLoadImage("F:\\tongtong.jpg", 1);
	IplImage *hsv_img = cvCreateImage(cvGetSize(src), 8 , 3);
	IplImage *h_img = cvCreateImage(cvGetSize(src), 8, 1);
	IplImage *s_img = cvCreateImage(cvGetSize(src), 8, 1);
	IplImage *v_img = cvCreateImage(cvGetSize(src), 8, 1);

	cvCvtColor(src, hsv_img, CV_BGR2HSV);
	cvSplit(hsv_img, h_img, s_img, v_img, NULL);
	for(int y = 0; y < hsv_img->height; y++){
		for(int x = 0; x < hsv_img->width; x++)
		{
			cout << cvGetReal2D(h_img, y, x) << " ";
		}
		cout << endl;
	}
	cvNamedWindow("src", 0);
	cvShowImage("src", hsv_img);
	cvWaitKey(0);
	cvReleaseImage(&src);
	cvDestroyWindow("src");
	return 0;
}



2:将色调H的取值范围转换到0~360之间



[cpp] view plain copy print ?

#include <iostream>
#include "cv.h"
#include "highgui.h"
#include "cxcore.h"

using namespace std;

int main()
{
	IplImage *src = cvLoadImage("F:\\tongtong.jpg", 1);
	IplImage *src_float = cvCreateImage(cvGetSize(src),IPL_DEPTH_32F, 3);
	<span style="color: rgb(255, 0, 0);">cvConvertScale(src, src_float, 1.0, 0.0);
	IplImage *hsv_img = cvCreateImage(cvGetSize(src), IPL_DEPTH_32F , 3);
	IplImage *h_img = cvCreateImage(cvGetSize(src), IPL_DEPTH_32F, 1);
	IplImage *s_img = cvCreateImage(cvGetSize(src), IPL_DEPTH_32F, 1);
	IplImage *v_img = cvCreateImage(cvGetSize(src), IPL_DEPTH_32F, 1);
</span>
	cvCvtColor(src_float, hsv_img, CV_BGR2HSV);
	cvSplit(hsv_img, h_img, s_img, v_img, NULL);
	for(int y = 0; y < hsv_img->height; y++){
		for(int x = 0; x < hsv_img->width; x++)
		{
			cout << cvGetReal2D(h_img, y, x) << " ";
		}
		cout << endl;
	}
	cvNamedWindow("src", 0);
	cvShowImage("src", hsv_img);
	cvWaitKey(0);
	cvReleaseImage(&src);
	cvDestroyWindow("src");
	return 0;
}


3:将H,S,V的范围转化到0~255之间


[cpp] view plain copy print ?


    1. #include <iostream>
    2. #include "cv.h"
    3. #include "highgui.h"
    4. #include "cxcore.h"
    5.   
    6. using namespace
    7.   
    8. int
    9. {  
    10. "F:\\tongtong.jpg", 1);  
    11.     IplImage *src_float = cvCreateImage(cvGetSize(src),IPL_DEPTH_32F, 3);  
    12.     cvConvertScale(src, src_float, 1.0, 0.0);  
    13.     IplImage *hsv_img = cvCreateImage(cvGetSize(src), IPL_DEPTH_32F , 3);  
    14.     IplImage *h_img = cvCreateImage(cvGetSize(src), IPL_DEPTH_32F, 1);  
    15.     IplImage *s_img = cvCreateImage(cvGetSize(src), IPL_DEPTH_32F, 1);  
    16.     IplImage *v_img = cvCreateImage(cvGetSize(src), IPL_DEPTH_32F, 1);  
    17. <span style="color: rgb(255, 0, 0);">  
    18.     IplImage *h = cvCreateImage(cvGetSize(src), 8, 1);  
    19.     IplImage *s = cvCreateImage(cvGetSize(src), 8, 1);  
    20.     IplImage *v = cvCreateImage(cvGetSize(src), 8, 1);  
    21.   
    22.     cvCvtColor(src_float, hsv_img, CV_BGR2HSV);  
    23.     cvSplit(hsv_img, h_img, s_img, v_img, NULL);  
    24.     cvConvertScale(h_img, h, (1.0/360)*255, 0.0);  
    25. // 因为S的取值范围为0~1
    26.     cvConvertScale(v_img, v, 1.0, 0.0);</span>  
    27. for(int
    28. for(int
    29.         {  
    30. if(cvGetReal2D(h, y, x) > 200)cout << cvGetReal2D(h, y, x) << " ";  
    31.         }  
    32.         cout << endl;  
    33.     }  
    34. "src", 0);  
    35. "src", hsv_img);  
    36.     cvWaitKey(0);  
    37.     cvReleaseImage(&src);  
    38. "src");  
    39. return
    40.   
    41. }