[go: up one dir, main page]

CN103561252A - Method for color space conversion from HSL to RGB - Google Patents

Method for color space conversion from HSL to RGB Download PDF

Info

Publication number
CN103561252A
CN103561252A CN201310589052.2A CN201310589052A CN103561252A CN 103561252 A CN103561252 A CN 103561252A CN 201310589052 A CN201310589052 A CN 201310589052A CN 103561252 A CN103561252 A CN 103561252A
Authority
CN
China
Prior art keywords
rgb
fixed
hsl
carried out
color
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201310589052.2A
Other languages
Chinese (zh)
Inventor
倪伟
郭彦锋
张继璠
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Wuxi Silicon Audiocodes Skill Co Ltd
Original Assignee
Wuxi Silicon Audiocodes Skill Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Wuxi Silicon Audiocodes Skill Co Ltd filed Critical Wuxi Silicon Audiocodes Skill Co Ltd
Priority to CN201310589052.2A priority Critical patent/CN103561252A/en
Publication of CN103561252A publication Critical patent/CN103561252A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Image Processing (AREA)

Abstract

The invention discloses a method for color space conversion from HSL to RGB. The method includes the steps that standardization is carried out on the HSL, and the scope ranges from 0 to 240; if S equals to zero, the R, G and B are equal, fixed-point calculation standardization is carried out, and the scope of the RGB ranges from 0 to 255; if the S is not equal to zero, fixed-point calculation is carried out on p, q and hk; fixed-point initialization is carried out on t R, t G and t B; the fixed-point calculation is carried out on tc corresponding to each color; the corresponding colors are calculated according to the tc, the p and the q; standardization is carried out on the RGB, and the scope of the RGB ranges from 0 to 255. The method has the advantages that fixed-pointed processing is adopted, the method can be used in embedded 8-bit, 16-bit and 32-bit single-chip microcomputer systems and X86 systems, so the application scope is broadened greatly; some applications can be achieved on the single-chip microcomputers, so the system cost is reduced greatly; in addition, the efficiency of the floating point arithmetic mode is also improved.

Description

A kind of HSL is to the method for rgb color space conversion
Technical field
The present invention relates to video and technical field of image processing, particularly a kind of HSL is to the method for rgb color space conversion.
Background technology
RGB(RGB) be the space that the definitions of color according to eye recognition goes out, can represent most of color, it is the most general color model towards hardware.But in scientific research, generally do not adopt RGB color space, because its details is difficult to carry out digitized adjustment; In addition, it is difficult to the expression of putting together of three amounts of hue, saturation, intensity separately.
HSL color mode is a kind of color standard of industrial quarters, by variation and their stacks each other of tone (H), saturation (S), three Color Channels of brightness (L) are obtained to color miscellaneous, HSL is the color that represents tone, saturation, three passages of brightness, this standard almost comprised mankind eyesights can perception all colours, be to use at present one of the widest color system.
RGB is applicable to machine sampling, and current display color consists of these three kinds of primary colours; And HSL is applicable to video, image is processed and section's research.It is particularly necessary that succinct conversion between them seems.
Current common HSL to RGB conversion method is: a color of (h, s, l) value definition in given HSL space, with h the codomain of indication form and aspect angle [0,360) in, represent that respectively the s of saturation and brightness and l are in codomain [0,1] in, corresponding (r, g, b) three primary colors in RGB space, with corresponding respectively to redness, green and blue r, g and b are also in codomain [0,1], and they can be calculated as:
First, if s=0, the color of result is achromatic or grey.In these special circumstances, r, g and b equal l.The value of noting h is undefined in this case.
In the time of s ≠ 0, can use following process:
q=
Figure 309784DEST_PATH_IMAGE001
p=
Figure 230205DEST_PATH_IMAGE002
Figure 403697DEST_PATH_IMAGE003
=
Figure 414378DEST_PATH_IMAGE004
Figure 444651DEST_PATH_IMAGE005
=
Figure 252387DEST_PATH_IMAGE007
=
Figure 930624DEST_PATH_IMAGE003
Figure 69482DEST_PATH_IMAGE008
=
Figure 652910DEST_PATH_IMAGE009
If <0
Figure 950216DEST_PATH_IMAGE011
=
Figure 259975DEST_PATH_IMAGE010
+1.0 for each C
Figure 330699DEST_PATH_IMAGE012
{R,G,B}
If >1 =
Figure 16130DEST_PATH_IMAGE010
-1.0 for each C
Figure 370888DEST_PATH_IMAGE012
{R,G,B}
For each color vector color=(
Figure 227985DEST_PATH_IMAGE013
,
Figure 922272DEST_PATH_IMAGE014
) =( r, g, b)
Figure 386882DEST_PATH_IMAGE015
=
Figure 432199DEST_PATH_IMAGE016
for each C
Figure 827408DEST_PATH_IMAGE012
{R,G,B}
In realizing process of the present invention, inventor finds that above-mentioned prior art exists following technical problem:
Be when in prior art, HSL is converted to rgb space, the poor compatibility of application; In addition, floating-point operation mode efficiency is low.
Summary of the invention
The object of this invention is to provide a kind of HSL to the method for rgb color space conversion, to realize the object that application is compatible good, floating-point operation mode efficiency is high.
For achieving the above object, the present invention is achieved through the following technical solutions:
HSL, to a method for rgb color space conversion, comprises the following steps:
1) HSL is demarcated, scope is between 0~240;
2) if S=0, RGB equates so, fixed-point computation is demarcated, RGB scope is between 0~255;
3) if S ≠ 0, so fixed-point computation p, q, hk; Fixed point initialization tR, tG, tB; The tc that each color of fixed-point computation is corresponding; According to tc, p, q, calculate corresponding color; Demarcate RGB, RGB scope is between 0~255.
Especially, described step 2), RGB calculating scaling method is: R=G=B=L*255/240.
Especially, in described step 3), q fixed-point computation method is: q=(l<120) ((unsigned short) (l * (240+s))/240): (l+s-(unsigned short) (l*s)/240).
Especially, in described step 3), p fixed-point computation method is: (2.0 * l) – q.
A kind of HSL of the present invention to the beneficial effect of the method for rgb color space conversion is: the present invention adopts fixed-point processing, can, for embedded 8,16,32 bit single-chip systems, also can, for X86 system, greatly expand range of application; For some application, can on single-chip microcomputer, realize, greatly lowered system cost; In addition, also improved floating-point operation mode efficiency.
Accompanying drawing explanation
Fig. 1 is that HSL of the present invention is to the flow chart of the method for rgb color space conversion.
Embodiment
To adopt 8 chip microcontroller color spaces to be converted to example, as shown in Figure 1, comprise the following steps:
1) HSL is demarcated, scope is between 0~240;
2) if S=0, RGB equates so, fixed-point computation is demarcated, RGB scope is between 0~255;
3) if S ≠ 0, so fixed-point computation p, q, hk; Fixed point initialization tR, tG, tB; The tc that each color of fixed-point computation is corresponding; According to tc, p, q, calculate corresponding color; Demarcate RGB, RGB scope is between 0~255.
Detailed process is as follows:
void hsl2rgb(u8 h,u8 s,u8 l,u8 *r,u8 *g,u8 *b)
{
unsigned short R, G, B;
unsigned char i;
if(s == 0)
{
R = G = B = l*255/240;
}
else
{
unsigned char q = (l<120) ((unsigned short)(l * (240+s))/240):(l+s -(unsigned short)(l*s)/240);
unsigned char p = (2.0 * l) - q;
unsigned char Hk = h;
unsigned short T[3];
T[0] = Hk + 80;
T[1] = Hk;
T[2] = Hk - 80;
for( i=0; i<3; i++)
{
if(T[i] < 0) T[i] += 240;
if(T[i] > 240) T[i] -= 240;
if((T[i]*6) < 240)
{
T[i] = p + ((q-p)*6*T[i])/240;
}
else if((T[i]*2) < 240)
{
T[i] = q;
}
else if((T[i]*3) < 480)
{
T[i] = p + (q-p) * (160 - T[i]) * 6/240;
}
else T[i] = p;
}
R = T[0]*255/240;
G = T[1]*255/240;
B = T[2]*255/240;
}
*r = (unsigned char)((R>255) 255 : ((R<0) 0 : R));
*g = (unsigned char)((G>255) 255 : ((G<0) 0 : G));
*b = (unsigned char)((B>255) 255 : ((B<0) 0 : B));
}。

Claims (4)

1. HSL, to a method for rgb color space conversion, is characterized in that, comprises the following steps:
1) HSL is demarcated, scope is between 0~240;
2) if S=0, RGB equates so, fixed-point computation is demarcated, RGB scope is between 0~255;
3) if S ≠ 0, so fixed-point computation p, q, hk; Fixed point initialization tR, tG, tB; The tc that each color of fixed-point computation is corresponding; According to tc, p, q, calculate corresponding color; Demarcate RGB, RGB scope is between 0~255.
2. HSL as claimed in claim 1, to a method for rgb color space conversion, is characterized in that: described step 2), RGB calculating scaling method is: R=G=B=L*255/240.
3. HSL as claimed in claim 1, to a method for rgb color space conversion, is characterized in that: in described step 3), q fixed-point computation method is: q=(l<120) ((unsigned short) (l * (240+s))/240): (l+s-(unsigned short) (l*s)/240).
4. HSL as claimed in claim 1, to a method for rgb color space conversion, is characterized in that: in described step 3), p fixed-point computation method is: (2.0 * l) – q.
CN201310589052.2A 2013-11-21 2013-11-21 Method for color space conversion from HSL to RGB Pending CN103561252A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201310589052.2A CN103561252A (en) 2013-11-21 2013-11-21 Method for color space conversion from HSL to RGB

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201310589052.2A CN103561252A (en) 2013-11-21 2013-11-21 Method for color space conversion from HSL to RGB

Publications (1)

Publication Number Publication Date
CN103561252A true CN103561252A (en) 2014-02-05

Family

ID=50015391

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201310589052.2A Pending CN103561252A (en) 2013-11-21 2013-11-21 Method for color space conversion from HSL to RGB

Country Status (1)

Country Link
CN (1) CN103561252A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110490945A (en) * 2019-09-11 2019-11-22 宋清海 A kind of method of adjustment of image color

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101339556A (en) * 2008-08-18 2009-01-07 福建四通石材有限公司 Method for implementing image color similarity contrast by taper cone coordinate
CN101521744A (en) * 2009-04-17 2009-09-02 东南大学 Video capture controller
CN101729663A (en) * 2009-11-23 2010-06-09 腾讯科技(深圳)有限公司 Device and method for changing skin of mobile terminal
CN102665135A (en) * 2012-04-18 2012-09-12 山东大学 Embedded screen transmission system and operating method thereof
CN102752606A (en) * 2011-11-21 2012-10-24 新奥特(北京)视频技术有限公司 Method for performing color spatial switching based on SSE2 (Streaming SIMD Extensions 2)
CN103065287A (en) * 2013-01-08 2013-04-24 天津光电高斯通信工程技术股份有限公司 Image enhancement algorithm based on hue, saturation, lightness (HSL) space and self-adaptation inverse hyperbolic tangent function
CN103310820A (en) * 2012-03-14 2013-09-18 三星电子(中国)研发中心 Method for optimizing multimedia player
CN103339944A (en) * 2011-01-31 2013-10-02 马维尔国际贸易有限公司 System and method for performing color adjustment of pixels on a color display

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101339556A (en) * 2008-08-18 2009-01-07 福建四通石材有限公司 Method for implementing image color similarity contrast by taper cone coordinate
CN101521744A (en) * 2009-04-17 2009-09-02 东南大学 Video capture controller
CN101729663A (en) * 2009-11-23 2010-06-09 腾讯科技(深圳)有限公司 Device and method for changing skin of mobile terminal
CN103339944A (en) * 2011-01-31 2013-10-02 马维尔国际贸易有限公司 System and method for performing color adjustment of pixels on a color display
CN102752606A (en) * 2011-11-21 2012-10-24 新奥特(北京)视频技术有限公司 Method for performing color spatial switching based on SSE2 (Streaming SIMD Extensions 2)
CN103310820A (en) * 2012-03-14 2013-09-18 三星电子(中国)研发中心 Method for optimizing multimedia player
CN102665135A (en) * 2012-04-18 2012-09-12 山东大学 Embedded screen transmission system and operating method thereof
CN103065287A (en) * 2013-01-08 2013-04-24 天津光电高斯通信工程技术股份有限公司 Image enhancement algorithm based on hue, saturation, lightness (HSL) space and self-adaptation inverse hyperbolic tangent function

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110490945A (en) * 2019-09-11 2019-11-22 宋清海 A kind of method of adjustment of image color

Similar Documents

Publication Publication Date Title
CN102097082B (en) Color regulation method for multi-play unit spliced display system and system thereof
CN103020996B (en) Based on the detection method of the image color cast of Lab space
WO2017024042A3 (en) Signal reshaping for high dynamic range signals
US9661187B1 (en) Color gamut mapping method based on color gamut of source image
CN105488488B (en) City black and odorous water remote sensing recognition method and device
CN101860762A (en) System for converting RGB three colors to RGBW four colors
CN101930596A (en) Color constancy method in two steps under a kind of complex illumination
RU2013114372A (en) AUTOMATIC PROCESSING OF WHITE BALANCE WITH FLEXIBLE SELECTION OF COLOR SPACE
CN102298769A (en) Colored fusion method of night vision low-light image and infrared image based on color transmission
CN108337496A (en) White balancing treatment method, processing unit, processing equipment and storage medium
CN106296620B (en) A kind of color rendition method based on histogram translation
CN104581105A (en) Automatic white balance method based on color temperature range conversion weight map
CN103854261A (en) Method for correcting color cast images
CN106454300B (en) Color domain expanding system and method
JPWO2014119060A1 (en) Image processing apparatus, image processing method, program, and recording medium
CN104486608A (en) Image data processing method and device
WO2015176631A1 (en) Method for de-hazing image data on the basis of histogram equalization
CN102752606B (en) A kind of method carrying out color space conversion based on SSE2
CN102542526B (en) Image decolorizing method
CN103561252A (en) Method for color space conversion from HSL to RGB
CN106412544A (en) Color gamut keeping system and method
CN103780887B (en) A kind of video signal processing method and device
CN103209331A (en) System and method for strengthening image color saturation
CN104394302A (en) Real-time video defogging system based on FPGA
CN103516998A (en) Station caption superposition method for analog video

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
C12 Rejection of a patent application after its publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20140205