Based on rgb value position color in colour disk the method for position, device and terminal
Technical field
The present invention relates to color treatments field, more particularly, to a kind of side based on rgb value position color position in colour disk
Method and device.
Background technology
Position position in colour disk for this color for based on rgb value, be currently by sampling to colour disk, then finding out and take
Sampling point and the immediate color of current color, and then position position in colour disk for this color.Due to sampling uneven or taking
When sampling point is not enough, with current color can there is larger error in immediate sampling point and current color, leads to work as
Front color is inaccurate in colour disk positioning, and error is larger.
Accordingly, it would be desirable to a kind of new technical scheme is accurately positioned position in standard RGB color disk for the rgb value.
Content of the invention
In view of this, the technical problem to be solved in the present invention is to provide a kind of rgb value position color that is based in colour disk middle position
The method and apparatus put, to be accurately positioned position in standard colour disk for this color according to rgb value.
The technical scheme that present invention solution above-mentioned technical problem is adopted is as follows:
According to an aspect of the present invention, a kind of method based on rgb value position color position in colour disk, the party are provided
Method includes:
Colour disk is divided into three sector regions by R, G and B three primary colors;
Described three sector regions are divided into two sub-regions more respectively;
Calculate the coordinate value of this color according to R, G and B value and its affiliated subregion.
Preferably, also include before the method:
Obtain brightness H, colourity S and saturation degree L value;
Described H, S and L value is converted into R, G and B value.
Preferably, described acquisition brightness H, colourity S and saturation degree L value further include:
Obtain brightness H, colourity S and the saturation degree L value of RGB lamp.
Preferably, described H, S and L value is converted into R, G and B value to include:
If s=0, r, g and b are equal to l;
If s ≠ 0,
P=2 × l-q
And
And
And
For each color vector Color=(ColorR, ColorG, ColorB)=(r, g, b),
Wherein, h represents hue angle, and h ∈ [0,360];S represents saturation degree, and l represents brightness, and s ∈ [0,1], l ∈ [0,
1], r, g, b represent the normalization codomain of color R, G and B value, r ∈ [0,1], g ∈ [0,1], b ∈ [0,1] respectively;To return
One change codomain is multiplied by 255 values for corresponding RGB.
Preferably, further included according to the coordinate value that R, G and B value and its affiliated subregion calculate this color:
Judge whether R, G, B value is particular value, if it is, pressing particular point coordinates computed;If it is not, then pressing following public affairs
Formula calculates:
If xORy is true,
And,
When xySign is fictitious time, y=-y, x=y/temp2
When xySign is true time, y is constant, x=y/temp2
If xORy is false,
And,
When xySign is fictitious time, x=-x;Y=x*temp2
When xySign is true time, x is constant, y=x*temp2
Wherein, angleSign represents the positive and negative of angle coefficient;XySign indicates whether whether by x or y be original phase
Counter count, xORy represents and obtains the positive and negative of coordinate according to x or y, true value represent according to x positive and negative obtaining, falsity represents according to y
Positive and negative obtaining, and:
If G=255 and R<B, then K=60, xySign are true, and xORy is true, and angleSign is false, M=R, N=
B;
If G=255 and R>=B, then K=60, xySign are true, and angleSign is true, M=B, N=R;
If R=255 and B<G, then K=180, xySign are false, and xORy is false, and angleSign is false, M=B, N=
G;
If R=255 and B>=G, then K=180, xySign are false, and xORy is false, and angleSign is true, M=G, N
=B;
If B=255 and G<R, then K=300, xySign are false, and xORy is true, and angleSign is false, M=G, N=
R;
If B=255 and G>=R, then K=300, xySign are false, and xORy is true, and angleSign is false, M=G, N
=R;
If angleSign be on the occasion of,
If angleSign is negative value,
Preferably, described include by particular point coordinates computed:
If G=255 and B=255,Y=0
If G=255, R=255 and B=0, then
If B=255, R=255 and G=0, then
If R=255, G=255 and B=255, then x=0, y=0.
According to a further aspect in the invention, a kind of device based on rgb value position color position in colour disk, this device bag
Include with lower module:
Colour disk division module, for colour disk is divided into three sector regions by R, G and B three primary colors, described three is fanned
Shape zone subdivision is not divided into two sub-regions;
Coordinate calculation module, for calculating the coordinate value of this color according to R, G and B value and its affiliated subregion.
Preferably, described device also includes:
HSL acquisition module, for obtaining brightness H, colourity S and saturation degree L value;
RGB computing module, for being converted into R, G and B value by described H, S and L value.
Preferential, described HSL acquisition module specifically for:
Obtain brightness H, colourity S and the saturation degree L value of RGB lamp.
According to a further aspect of the invention, the present invention also provides a kind of intelligent terminal, and intelligent terminal includes above-mentioned being based on
The device of rgb value position color position in colour disk.
The method of the embodiment of the present invention, device and terminal, according to R, G, B three primary colors in RGB color disk according to certain rule
The characteristic of distribution, by rgb value coordinates computed come position color the position in RGB color disk, can not be accurately positioned, not by mistake
Difference.
Brief description
A kind of stream based on rgb value position color method of position in colour disk that Fig. 1 provides for the embodiment of the present invention one
Cheng Tu;
Fig. 2 divides schematic diagram for the RGB color disk that the embodiment of the present invention one provides;
Color coordinates schematic diagram in the RGB color disk that Fig. 3 provides for the embodiment of the present invention one;
The flow chart of positioning RGB lamp color method of position in colour disk that Fig. 4 provides for the embodiment of the present invention two;
The module knot based on rgb value position color device of position in colour disk that Fig. 5 provides for the embodiment of the present invention three
Composition;
The function structure chart of positioning RGB lamp color device of position in colour disk that Fig. 6 provides for the embodiment of the present invention four.
Specific embodiment
In order that the technical problem to be solved, technical scheme and beneficial effect are clearer, clear, below tie
Close drawings and Examples, the present invention will be described in further detail.It should be appreciated that specific embodiment described herein is only
In order to explain the present invention, it is not intended to limit the present invention.
Embodiment one
As shown in figure 1, the present invention provide a kind of method based on rgb value position color position in colour disk, including with
Lower step:
S102, colour disk is divided into three sector regions by R, G and B three primary colors, three sector regions is distinguished decile again
For two sub-regions.
Specifically, as Fig. 2 and Fig. 3, colour disk is divided into three sector regions by RGB three primary colors, by these three fan sections
Domain is divided into two sub-regions more respectively;Calculate the rgb value of this color point according to the affiliated subregion of color point and its coordinate.Its
In, six sub-regions G-B subregions, G-R subregion, R-G subregion, R-B subregion, B-R subregion, B-G subregion are respectively
For primary colors subregion.I.e. in 255 colour disks of standard, three sector regions of red, green, blue can be divided into, then disk can
To be divided into three 120 ° of region.In each area, it is divided into two 60 ° again, so a circle is divided into six regions to divide
Do not calculate.In each color region, the component value of current region must be equal to 255.As the R-G sub-district in red sector region
The R value of domain and R-B subregion is constant for 255, and the G value of G-B subregion and G-R subregion is constant for 255, B-R subregion and B-G
The G value of subregion is constant for 255.
S104, calculate the coordinate value of this color according to R, G and B value and its affiliated subregion.
As shown in figure 3, setting the coordinate of centre point as (0,0), radius of circle is r, and the coordinate of color point A is A (x, y), and x, y are
Natural numerical value, and number range is (0~r), R represents red color component value, and G represents green component values, and B represents blue component
Value.In conjunction with coordinate quadrant it is possible to obtain x, y value by these three values of R, G, B, thus orienting this color point on colour disk
Position.
1) first determine whether whether R, G, B value is particular value, if it is, pressing particular point coordinates computed.
If G=255 and B=255,Y=0
If G=255, R=255 and B=0, then
If B=255, R=255 and G=0, then
If R=255, G=255 and B=255, then x=0, y=0
2) if R, G, B value is not particular value, coordinates computed in the following manner.
2.1) define following parameter:AngleSign represents the positive and negative of angle coefficient, and flase is negative, and true is just;
XySign indicates whether whether by x or y be original opposite number, and flase is negative, and true is just;XORy represents according to x still
Y obtaining the positive and negative of coordinate, false represent according to x positive and negative obtaining, true represent according to y positive and negative obtaining;M and N only table
Show it is the meaning of parameter.
If G=255 and R<B then xy coordinate points in G-B subregion, now
K=60
XySign is true
XORy is true
AngleSign is false
M=R
N=B
If G=255 and R>Then xy coordinate points exist=B, G-R subregion, now
K=60
XySign is true
AngleSign is true
M=B
N=R
If R=255 and B<G then xy coordinate points in R-G subregion, now
K=180
XySign is false
XORy is false
AngleSign is false
M=B
N=G
If R=255 and B>=G then xy coordinate points in R-B subregion, now
K=180
XySign is false
XORy is false
AngleSign is true
M=G
N=B
If B=255 and G<R then xy coordinate points in B-R subregion, now
K=300
XySign is false
XORy is true
AngleSign is false
M=G
N=R
If B=255 and G>=R then xy coordinate points in B-G subregion, now
K=300
XySign is false
XORy is true
AngleSign is false
M=G
N=R
2.2) above-mentioned parameter substitution below equation is calculated
If angleSign is true,
If angleSign is false,
If xORy is true,
If xySign is false, then y=-y;X=y/temp2;
If xySign is true, then y is constant;X=y/temp2;
If xORy is false,
If xySign is false, then x=-x;Y=x*temp2.
If xySign is true, then x is constant;Y=x*temp2.
The coordinate value of arbitrfary point A (x, y) can be drawn by above-mentioned calculating.
The method of the embodiment of the present invention, according to R, G, B three primary colors in colour disk according to the characteristic of certain rule distribution, passes through
Rgb value coordinates computed comes position in RGB color disk for the position color, can be accurately positioned, not have error.
Embodiment two
As shown in figure 4, the embodiment of the present invention is taking RGB lamp as a example, provide a kind of position in colour disk for positioning RGB lamp color
Method, the method comprises the following steps:
S402, the brightness H obtaining RGB lamp, colourity S and saturation degree L value.
It should be noted that the present embodiment only illustrates taking RGB lamp as a example, can be from arbitrarily aobvious in practical embodiments
Show that the equipment of color change obtains H, S, L value.The such as equipment such as RGB electronic display.
S404, H, S and L value is converted into R, G and B value.S406, colour disk is divided into three sectors by R, G and B three primary colors
Region, three sector regions are divided into two sub-regions more respectively.
S408, calculate the coordinate value of this color according to R, G and B value and its affiliated subregion.
Wherein, step S406 is identical with the S102 of above-described embodiment one, step S104 respectively with step S406, this enforcement
No longer repeat in example.
The method of the embodiment of the present invention, by obtaining the HSL value of RGB lamp, and then is converted into rgb value, R in foundation colour disk,
G, B three primary colors according to the characteristic of certain rule distribution, by rgb value coordinates computed come position color the position in RGB color disk
Put, can be accurately positioned, there is no error.
Embodiment three
As shown in figure 5, the present invention provide a kind of method based on rgb value position color position in colour disk, including with
Lower module:
Colour disk division module 530, for colour disk is divided into three sector regions by R, G and B three primary colors, by three sectors
Zone subdivision is not divided into two sub-regions.
Specifically, as Fig. 2 and Fig. 3, colour disk is divided into three sector regions by RGB three primary colors, by these three fan sections
Domain is divided into two sub-regions more respectively;Calculate the rgb value of this color point according to the affiliated subregion of color point and its coordinate.Its
In, six sub-regions G-B subregions, G-R subregion, R-G subregion, R-B subregion, B-R subregion, B-G subregion are respectively
For primary colors subregion.I.e. in 255 colour disks of standard, three sector regions of red, green, blue can be divided into, then disk can
To be divided into three 120 ° of region.In each area, it is divided into two 60 ° again, so a circle is divided into six regions to divide
Do not calculate.In each color region, the component value of current region must be equal to 255.As the R-G sub-district in red sector region
The R value of domain and R-B subregion is constant for 255, and the G value of G-B subregion and G-R subregion is constant for 255, B-R subregion and B-G
The G value of subregion is constant for 255.
Coordinate calculation module 540, for calculating the coordinate value of this color according to R, G and B value and its affiliated subregion.
As shown in figure 3, setting the coordinate of centre point as (0,0), radius of circle is r, and the coordinate of color point A is A (x, y), and x, y are
Natural numerical value, and number range is (0~r), R represents red color component value, and G represents green component values, and B represents blue component
Value.In conjunction with coordinate quadrant, computing module 20 just can obtain x, y value by these three values of R, G, B, thus orienting this color
Position on colour disk for the point, specifically for:
1) first determine whether whether R, G, B value is particular value, if it is, pressing particular point coordinates computed.
If G=255 and B=255,Y=0
If G=255, R=255 and B=0, then
If B=255, R=255 and G=0, then
If R=255, G=255 and B=255, then x=0, y=0
2) if R, G, B value is not particular value, coordinates computed in the following manner.
2.1) define following parameter:AngleSign represents the positive and negative of angle coefficient, and flase is negative, and true is just;
XySign indicates whether whether by x or y be original opposite number, and flase is negative, and true is just;XORy represents according to x still
Y obtaining the positive and negative of coordinate, false represent according to x positive and negative obtaining, true represent according to y positive and negative obtaining.
If G=255 and R<B then xy coordinate points in G-B subregion, now
K=60
XySign is true
XORy is true
AngleSign is false
M=R
N=B
If G=255 and R>Then xy coordinate points exist=B, G-R subregion, now
K=60
XySign is true
AngleSign is true
M=B
N=R
If R=255 and B<G then xy coordinate points in R-G subregion, now
K=180
XySign is false
XORy is false
AngleSign is false
M=B
N=G
If R=255 and B>=G then xy coordinate points in R-B subregion, now
K=180
XySign is false
XORy is false
AngleSign is true
M=G
N=B
If B=255 and G<R then xy coordinate points in B-R subregion, now
K=300
XySign is false
XORy is true
AngleSign is false
M=G
N=R
If B=255 and G>=R then xy coordinate points in B-G subregion, now
K=300
XySign is false
XORy is true
AngleSign is false
M=G
N=R
2.2) above-mentioned parameter substitution below equation is calculated
If angleSign is true,
If angleSign is false,
If xORy is true,
If xySign is false, then y=-y;X=y/temp2;
If xySign is true, then y is constant;X=y/temp2;
If xORy is false,
If xySign is false, then x=-x;Y=x*temp2.
If xySign is true, then x is constant;Y=x*temp2.
The coordinate value of arbitrfary point A (x, y) can be drawn by above-mentioned calculating.
The device of the embodiment of the present invention, according to R, G, B three primary colors in colour disk according to the characteristic of certain rule distribution, passes through
Rgb value coordinates computed comes position in RGB color disk for the position color, can be accurately positioned, not have error.
Example IV
As shown in fig. 6, the embodiment of the present invention is taking RGB lamp as a example, provide a kind of position in colour disk for positioning RGB lamp color
Device, the method comprises the following steps:
HSL acquisition module 610, for obtaining brightness H, colourity S and the saturation degree L value of RGB lamp.
It should be noted that the present embodiment only illustrates taking RGB lamp as a example, can be from arbitrarily aobvious in practical embodiments
Show that the equipment of color change obtains H, S, L value.The such as equipment such as RGB electronic display.
Rgb value computing module 620, for being converted into R, G and B value by H, S and L value.
If s=0, r, g and b are equal to l;
If s ≠ 0,
P=2 × l-q
And
And
And
For each color vector Color=(ColorR, ColorG, ColorB)=(r, g, b),
Wherein, h represents hue angle, and h ∈ [0,360];S represents saturation degree, and l represents brightness, and s ∈ [0,1], l ∈ [0,
1], r, g, b represent the normalization codomain of color R, G and B value, r ∈ [0,1], g ∈ [0,1], b ∈ [0,1] respectively;To return
One change codomain is multiplied by 255 values for corresponding RGB.
Colour disk division module 630, for colour disk is divided into three sector regions by R, G and B three primary colors, by three sectors
Zone subdivision is not divided into two sub-regions.
Coordinate calculation module 640, for calculating the coordinate value of this color according to R, G and B value and its affiliated subregion.
Wherein, division module 630 and coordinate calculation module 640 division module 530 and the seat with above-described embodiment three respectively
Mark computing module 540 is identical, no longer repeats in the present embodiment.
The device of the embodiment of the present invention, by obtaining the HSL value of RGB lamp, and then is converted into rgb value, R in foundation colour disk,
G, B three primary colors according to the characteristic of certain rule distribution, by rgb value coordinates computed come position color the position in RGB color disk
Put, can be accurately positioned, there is no error.
Additionally, present invention also offers a kind of terminal, this terminal include above-mentioned any one technical scheme based on rgb value
The device of position in colour disk for the position color.
One of ordinary skill in the art will appreciate that it is permissible for realizing all or part of step in above-described embodiment method
The hardware being controlled correlation by program is completed, described program can in being stored in a computer read/write memory medium,
Described storage medium, such as ROM/RAM, disk, CD etc..
The preferred embodiments of the present invention above by reference to brief description, not thereby limit to the interest field of the present invention.This
Skilled person, all should be at this without departing from any modification, equivalent and the improvement made in the scope of the present invention and essence
Within the interest field of invention.