The HSV and RGB of intelligent illumination

Source: Internet
Author: User
Tags color representation

The HSV and RGB of intelligent illumination

One, RGB color model

The RGB (Red, Green, Blue) color mode is a hardware-oriented color model, and the display system uses an RGB color model for image display. RGB color model is the principle of additive mixing, the higher the value of each primary color, the brighter the colors, RGB is 0 o'clock is black, are 255 white.

RGB color model is direct, but the RGB value and color of the three attributes are not directly linked, can not reveal the relationship between colors.

Second, HSV color model

The most widely used HSV color pattern is an inverted cone model, a color model for user senses, with a focus on color representation. This is based on the human visual system to the brightness of the sensitivity of the color value of the physiological characteristics of the proposed color model.

The HSV (hue, saturation, Value) corresponds to hue, saturation, and lightness, respectively.

Hue h: With the angle measure, the value range is 0°~360°, starting from red in accordance with the counter-clockwise calculation, red is 0°, Green is 120°, Blue is 240°, yellow is 60°, cyan is 180°, magenta is 300°, corresponds to the angle of the center axis around the cylinder. Saturation s: Indicates the purity of the color, corresponding to the distance from the center axis of the cylinder. The higher the value, the darker and more vivid, the lower the value, the darker the color, the 0.0~1.0, the white s=0. Lightness V: Indicates how bright the color is. The value range is 0.0 (black) ~1.0 (white). Corresponds to the height of the center axis around the cylinder, the axis value is from the bottom of the black v=0 to the top of the white v=1.

III. Application of HSV

The HSV color wheel is often used in computer graphics applications where hue is represented as a ring and a separate triangle is used to represent saturation (S) and lightness (V). The vertical axis of this triangle represents saturation, and the horizontal axis represents lightness. In this way, select a color to first select the hue in the ring, and select the desired saturation and lightness in the triangle.

The HSV model can also be represented by a cylindrical body. Hue changes along the outer circumference of the cylinder, the distance of the saturation along the center of the cross-section, and the lightness along the bottom-to-top of the cross-sectional area.

Four, HSV and RGB mutual transfer

Because the HSV is a user-oriented color model, and the display system uses the hardware-oriented RGB color model, it is necessary to convert the HSB and RGB when controlling the hardware.

Set (R, G, b) is the red, green, and blue coordinates of a color, respectively, whose value is a real number between 0 and 1. Set Max to be equivalent to R, the largest in G and B. Set min equals the smallest of these values. To find a value in HSV space (h, S, v), here h∈[0, 360) is the angle of the hue angle, while S, v∈[0,1] is the saturation and lightness.

Because the HSV and RGB are all involved in the calculation of decimal operations, the conversion will have a precision loss.

/* h:0~360 s:0~1 v:0~1 */void Hsv2rgb (float h, float s, float v) {float h60;
	float F;
	unsigned int h60f;

    unsigned int hi;
    float p, q, t;
    Float R, G, B;

    unsigned int color_r, color_g, Color_b;

	printf ("h:%.2f s:%.2f v:%.2f\r\n", H, S, v);
	H60 = h/60.0;

	h60f = H/60;
	hi = (int) h60f% 6;

    f = h60-h60f;
    p = v * (1-s);
    Q = v * (1-F * s);

    t = v * (1-(1-f) * s);
    r = G = b = 0;  Switch (HI) {case 0:r = V;  g = t;
        b = P;

        Break  Case 1:r = q;  g = V;
        b = P;

        Break   Case 2:r = p;  g = V;
        b = t;

        Break  Case 3:r = p;  g = q;
        b = V;

        Break  Case 4:r = t;  g = P;
        b = V;

        Break  Case 5:r = v;  g = P;
        b = q;
    Break
    } R = (R * 255.0) * 100;
    g = (g * 255.0) * 100;

    b = (b * 255.0) * 100;
    Color_r = (R + 49)/100; Color_g = (g + 49)/100;

    Color_b = (b + 49)/100;
 printf ("Color_r:%u color_g:%u color_b:%u\n\n", Color_r, Color_g, Color_b); }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.