当前位置:网站首页>HSV color model and color component range in opencv

HSV color model and color component range in opencv

2022-06-21 14:30:00 Modest learning and progress

https://www.cnblogs.com/wangyblzu/p/5710715.html

HSV Color model

HSV(Hue, Saturation, Value) According to the intuitive characteristics of color A. R. Smith stay 1978 A color space created in , Also known as the hexagonal cone model (Hexcone Model).、 The parameters of color in this model are : tonal (H), saturation (S), brightness (V).

 

tonal H: Measure in terms of angles , The value range is 0°~360°, Counting counter clockwise from red , Red as 0°, Green is 120°, Blue 240°. Their complementary color is : Yellow is 60°, Blue is 180°, Fuchsin is 300°;

saturation S: The value range is 0.0~1.0;

brightness V: The value range is 0.0( black )~1.0( white ).

 

RGB and CMY Color models are hardware oriented , and HSV(Hue Saturation Value) The color model is user oriented .

HSV The three-dimensional representation of the model starts from RGB The cube evolved . Imagine from RGB Look at the black vertices along the diagonal of the cube , You can see the hexagonal shape of the cube . Hexagonal boundaries represent colors , The horizontal axis shows purity , Lightness is measured along the vertical axis .

 

HSV Color component range

Generally, the effective processing of color space image is in HSV Space goes on , And then for the basic color corresponding to HSV Components need to be given a strict range , The following is the fuzzy range calculated by experiment ( The exact range is not given on the Internet ).

H:  0— 180

S:  0— 255

V:  0— 255

Here, part of red is classified as purple :( stay OpenCv Library functions used in RGB2HSV The switch to HSV After the color model ,H The weight should be in 0~360 Range , That is, the following table H The component value should be multiplied by 2)

 

HSV Hexagonal pyramid

H Parameters represent color information , That is, the position of the spectral color . This parameter is represented by an angular quantity , red 、 green 、 Blue purity respectively S Is a proportional value , Range from 0 To 1, It is expressed as the ratio between the purity of the selected color and the maximum purity of that color .S=0 when , Only grayscale . Apart, 120 degree . Complementary colors differ from each other 180 degree .

V Indicates the brightness of a color , Range from 0 To 1. There is one caveat : There's no direct relationship between it and light intensity .

 

1、RGB Convert to HSV The algorithm of :

max=max(R,G,B)

min=min(R,G,B)

V=max(R,G,B)

S=(max-min)/max

ifR = max,H =(G-B)/(max-min)* 60

ifG = max,H = 120+(B-R)/(max-min)* 60

ifB = max,H = 240 +(R-G)/(max-min)* 60

ifH < 0,H = H+ 360

 

2、HSV Convert to RGB The algorithm of :

if s = 0

R=G=B=V

else

H /= 60;

i = INTEGER(H)

f = H - i

a = V * ( 1 - s )

b = V * ( 1 - s * f )

c = V * ( 1 - s * (1 - f ) )

switch(i)

case 0: R = V; G = c; B = a;

case 1: R = b; G = v; B = a;

case 2: R = a; G = v; B = c;

case 3: R = a; G = b; B = v;

case 4: R = c; G = a; B = v;

case 5: R = v; G = a; B = b;

 

  HSV It is an intuitive color model for users . We can start with a pure color , That is, specify the color angle H, And let V=S=1, Then we can add black and white to it to get the color we need . Increasing black can reduce V and S unchanged , Similarly, increasing white can reduce S and V unchanged . for example , To get dark blue ,V=0.4 S=1 H=240 degree . To get a light blue ,V=1 S=0.4 H=240 degree .

   As a general rule , The human eye can distinguish 128 Different colors ,130 Color saturation ,23 A shade . If we use 16Bit Express HSV Words , It can be used 7 To store H,4 To store S,5 To store V, namely 745 perhaps 655 We can meet our needs .

   because HSV It is an intuitive color model , Therefore, it is widely used in many image editing tools , Such as Photoshop( stay Photoshop It's called in Chinese HSB) wait , But this also determines that it is not suitable for use in lighting models , Many ray mixing operations 、 Light intensity calculation cannot be used directly HSV To achieve .

原网站

版权声明
本文为[Modest learning and progress]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202221424252744.html