Android Camera Live Filter (vi)

Source: Internet
Author: User

HSL Color Mode 1. Color HSL

H:hue Hue
Saturation of S:saturation
L:lum brightness

2. Overview
    • The HSL color model is a color standard for industry, which is the color of hue, saturation, and brightness of three channels by varying the color channels of tones (H), saturation (S), luminance (L), and their superposition to each other (three). This standard almost includes all the colors that human vision can perceive, and is one of the most widely used color systems.
    • HSL color mode uses the HSL model to assign the HSL component of each pixel in an image to a strength value in the 0~255 range. The HSL image uses only three channels, allowing them to blend in different proportions and reproduce 16777216 colors on the screen.
    • In HSL mode, values from 0 to 255 can be used for each HSL component. (where L is a gradient from black (0) to White (255)).
3. HSL and RGB conversion

A) algorithm description for RGB→HSL

Step 1: Turn the RGB values into "0,1" values.
Step 2: Find the maximum value in R,g and B.
Step 3: Set l= (Maxcolor + mincolor)/2
Step 4: If the maximum and minimum color values are the same, which means gray, then S is defined as 0, and H is undefined and is usually written in the program as 0.
Step 5: Otherwise, test L:
If l<0.5, s= (maxcolor-mincolor)/(Maxcolor + mincolor)
If l>=0.5, s= (maxcolor-mincolor)/(2.0-maxcolor-mincolor)
Step 6: If r=maxcolor, h= (g-b)/(Maxcolor-mincolor)
If G=maxcolor, h=2.0+ (b-r)/(Maxcolor-mincolor)
If B=maxcolor, h=4.0+ (r-g)/(Maxcolor-mincolor)
Step 7: From the calculation of the 6th step, H is divided into the 0~6 area. The RGB color space is a cube and the HSL color space is two hexagon cones, where l is the main diagonal of the RGB cube. Therefore, the vertices of the RGB cube: Red, yellow, green, cyan, blue, and magenta become the vertices of the HSL hexagonal, and the numerical 0~6 tells us which part H is. h=h*60.0, if H is negative, add 360.

b) algorithm description for Hsl→rgb

Step 1: If s=0, indicates gray, define R,G and B are all L.
Step 2: Otherwise, test L:
If l<0.5,temp2=l* (1.0+s)
If l>=0.5,temp2=l+s-l*s
Step 3: TEMP1=2.0*-TEMP2
Step 4: Convert H to 0~1.
Step 5: For R,g,b, calculate an additional temporary value of Temp3. Here's how:
For R, temp3=h+1.0/3.0
For G, Temp3=h
For B, temp3=h-1.0/3.0
If temp3<0, temp3=temp3+1.0
If temp3>1, temp3=temp3-1.0
Step 6: Do the following tests for R,g,b:
If 6.0*temp3<1,color=temp1+ (TEMP2-TEMP1) *6.0*temp3
Else if 2.0*TEMP3<1,COLOR=TEMP2
Else if 3.0*temp3<2,
color=temp1+ (TEMP2-TEMP1) * ((2.0/3.0)-temp3) *6.0
Else COLOR=TEMP1

Example

Android Camera Live Filter (vi)

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.