colourdistance 0.9.11 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a975c48f2d6a1dce74d9f8a0eeeb8643c1a26f31
|
4
|
+
data.tar.gz: fdd1f5d5c9aca769fd809b47d9c28f39f978ab13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3595ff36180543a429f72a9386e07ff13c67a0201e751d7eb25911f18282019fa0259bdc30b6988971b3014172313428c36975dc3394eb84339a75176514e80a
|
7
|
+
data.tar.gz: cc04bc88a28ba4dfb792039059ea89ab4092cd2c0a79ccc2c4ed3474b5a17cfc9e9007819dc9a8be4f44595ab52a62b4ff3994e72c4886aa80457c7dd9fd0910
|
data/colourdistance.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.email = ["theseventhorange@gmail.com"]
|
12
12
|
|
13
13
|
spec.summary = "Measures the difference (as a distance between colors in lab space) between colours. Takes rgb input. Will add support for xyz and lab around version 1.0."
|
14
|
-
spec.description = "Currently only contains
|
14
|
+
spec.description = "Currently only contains three options (ciede 76, ciede94, and ciede2000), all weighted to (roughly) a [0,1] scale (actually possible to get slightly above 1). Will add more. All are my own implementations (although ciede2000 is based on a several dozen implementations found during research), and they may be wrong because of it. Thanks go out to Josh Clayton (https://robots.thoughtbot.com/get-your-c-on), for helping me to understand the structure I was attempting to acheive."
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
17
|
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
@@ -7,91 +7,98 @@
|
|
7
7
|
|
8
8
|
void Init_colourdistance() {
|
9
9
|
VALUE rb_mColourdistance = rb_define_module("Colourdistance");
|
10
|
+
rb_define_singleton_method(rb_mColourdistance, "cie76", ciede2000, 2);
|
11
|
+
rb_define_singleton_method(rb_mColourdistance, "cie94", ciede2000, 2);
|
10
12
|
rb_define_singleton_method(rb_mColourdistance, "ciede2000", ciede2000, 2);
|
11
13
|
}
|
12
14
|
|
13
|
-
static VALUE
|
15
|
+
static VALUE cie76(const VALUE self, VALUE color1, VALUE color2) {
|
14
16
|
double pi = 3.1415927;
|
15
17
|
double e = 2.7182818;
|
16
18
|
double conversion = pi/180.0;
|
17
|
-
double
|
18
|
-
double
|
19
|
-
double a1;
|
20
|
-
double a2;
|
19
|
+
static double lab1[3];
|
20
|
+
static double lab2[3];
|
21
21
|
|
22
|
-
|
23
|
-
double g1 = NUM2DBL(rb_hash_aref(color1, rb_str_intern(rb_str_new2("g"))))/255.0;
|
24
|
-
double b1 = NUM2DBL(rb_hash_aref(color1, rb_str_intern(rb_str_new2("b"))))/255.0;
|
22
|
+
rgb_to_lab(color1, lab1);
|
25
23
|
|
26
|
-
double
|
27
|
-
double
|
28
|
-
double
|
24
|
+
double l1 = lab1[0];
|
25
|
+
double a1 = lab1[1];
|
26
|
+
double b1 = lab1[2];
|
29
27
|
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
rgb_to_lab(color2, lab2);
|
29
|
+
double l2 = lab2[0];
|
30
|
+
double a2 = lab2[1];
|
31
|
+
double b2 = lab2[2];
|
33
32
|
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
double ldiff = l2 - l1;
|
34
|
+
double adiff = a2 - a1;
|
35
|
+
double bdiff = b2 - b1;
|
37
36
|
|
38
|
-
double
|
39
|
-
double y1 = 0.212671 * r1 + 0.715160 * g1 + 0.072169 * b1;
|
40
|
-
double z1 = 0.019334 * r1 + 0.119193 * g1 + 0.950227 * b1;
|
37
|
+
double val = sqrt(ldiff*ldiff+adiff*adiff+bdiff*bdiff)/100.0;
|
41
38
|
|
42
|
-
|
43
|
-
|
44
|
-
double z2 = 0.019334 * r2 + 0.119193 * g2 + 0.950227 * b2;
|
39
|
+
return DBL2NUM(val);
|
40
|
+
}
|
45
41
|
|
46
|
-
|
47
|
-
double
|
48
|
-
double
|
42
|
+
static VALUE cie94(const VALUE self, VALUE color1, VALUE color2) {
|
43
|
+
double pi = 3.1415927;
|
44
|
+
double e = 2.7182818;
|
45
|
+
double conversion = pi/180.0;
|
46
|
+
double kl = 2.0;
|
47
|
+
double k1 = 0.048;
|
48
|
+
double k2 = 0.014;
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
}else{
|
53
|
-
fx = cbrt(x1/0.95047);
|
54
|
-
}
|
50
|
+
static double lab1[3];
|
51
|
+
static double lab2[3];
|
55
52
|
|
56
|
-
|
57
|
-
l1 = 903.3 * y1;
|
58
|
-
fy = (7.787 * y1 + 16.0/116.0);
|
59
|
-
}else{
|
60
|
-
l1 = 116.0 * cbrt(y1) - 16.0;
|
61
|
-
fy = cbrt(y1);
|
62
|
-
}
|
53
|
+
rgb_to_lab(color1, lab1);
|
63
54
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
fz = cbrt(z1/1.08883);
|
68
|
-
}
|
55
|
+
double l1 = lab1[0];
|
56
|
+
double a1 = lab1[1];
|
57
|
+
double b1 = lab1[2];
|
69
58
|
|
70
|
-
|
71
|
-
|
59
|
+
rgb_to_lab(color2, lab2);
|
60
|
+
double l2 = lab2[0];
|
61
|
+
double a2 = lab2[1];
|
62
|
+
double b2 = lab2[2];
|
72
63
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
fx = cbrt(x2/0.95047);
|
77
|
-
}
|
64
|
+
double ldiff = l1 - l2;
|
65
|
+
double adiff = a1 - a2;
|
66
|
+
double bdiff = b1 - b2;
|
78
67
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
}else{
|
83
|
-
l2 = 116.0 * cbrt(y2) - 16.0;
|
84
|
-
fy = cbrt(y2);
|
85
|
-
}
|
68
|
+
double c1 = sqrt(a1*a1+b1*b1);
|
69
|
+
double c2 = sqrt(a2*a2+b2*b2);
|
70
|
+
double deltac = c1 - c2;
|
86
71
|
|
87
|
-
|
88
|
-
fz = (7.787 * z2/1.08883 + 16.0/116.0);
|
89
|
-
}else{
|
90
|
-
fz = cbrt(z2/1.08883);
|
91
|
-
}
|
72
|
+
double deltah = sqrt(adiff*adiff+bdiff*bdiff-deltac*deltac);
|
92
73
|
|
93
|
-
|
94
|
-
|
74
|
+
double sc = 1 + k1*c1;
|
75
|
+
double sh = 1 + k2*c1;
|
76
|
+
|
77
|
+
double e1 = ldiff/kl;
|
78
|
+
double e2 = deltac / (k1*sc);
|
79
|
+
double e3 = deltah / (k2*sh);
|
80
|
+
double val = sqrt(e1*e1+e2*e2+e3*e3)/100.0;
|
81
|
+
|
82
|
+
return DBL2NUM(val);
|
83
|
+
}
|
84
|
+
|
85
|
+
static VALUE ciede2000(const VALUE self, VALUE color1, VALUE color2) {
|
86
|
+
double pi = 3.1415927;
|
87
|
+
double e = 2.7182818;
|
88
|
+
double conversion = pi/180.0;
|
89
|
+
static double lab1[3];
|
90
|
+
static double lab2[3];
|
91
|
+
|
92
|
+
rgb_to_lab(color1, lab1);
|
93
|
+
|
94
|
+
double l1 = lab1[0];
|
95
|
+
double a1 = lab1[1];
|
96
|
+
double b1 = lab1[2];
|
97
|
+
|
98
|
+
rgb_to_lab(color2, lab2);
|
99
|
+
double l2 = lab2[0];
|
100
|
+
double a2 = lab2[1];
|
101
|
+
double b2 = lab2[2];
|
95
102
|
|
96
103
|
double c1 = sqrt(a1*a1+b1*b1);
|
97
104
|
double c2 = sqrt(a2*a2+b2*b2);
|
@@ -165,4 +172,47 @@ static VALUE ciede2000(const VALUE self, VALUE color1, VALUE color2) {
|
|
165
172
|
double val = sqrt(ldiff*ldiff+adiff*adiff+bdiff*bdiff+rdiff)/100.0;
|
166
173
|
|
167
174
|
return DBL2NUM(val);
|
175
|
+
}
|
176
|
+
|
177
|
+
|
178
|
+
void rgb_to_lab(VALUE color, double *lab) {
|
179
|
+
|
180
|
+
double r = NUM2DBL(rb_hash_aref(color, rb_str_intern(rb_str_new2("r"))))/255.0;
|
181
|
+
double g = NUM2DBL(rb_hash_aref(color, rb_str_intern(rb_str_new2("g"))))/255.0;
|
182
|
+
double b = NUM2DBL(rb_hash_aref(color, rb_str_intern(rb_str_new2("b"))))/255.0;
|
183
|
+
|
184
|
+
r = ((r <= 0.04045) ? r / 12.92 : pow(((r + 0.055) / 1.055),2.4));
|
185
|
+
g = ((g <= 0.04045) ? g / 12.92 : pow(((g + 0.055) / 1.055),2.4));
|
186
|
+
b = ((b <= 0.04045) ? b / 12.92 : pow(((b + 0.055) / 1.055),2.4));
|
187
|
+
|
188
|
+
double x = 0.412453 * r + 0.357580 * g + 0.180423 * b;
|
189
|
+
double y = 0.212671 * r + 0.715160 * g + 0.072169 * b;
|
190
|
+
double z = 0.019334 * r + 0.119193 * g + 0.950227 * b;
|
191
|
+
|
192
|
+
double fx;
|
193
|
+
double fy;
|
194
|
+
double fz;
|
195
|
+
|
196
|
+
if(x <= 0.008856){
|
197
|
+
fx = 7.787 * x/0.95047 + 16.0/116.0;
|
198
|
+
}else{
|
199
|
+
fx = cbrt(x/0.95047);
|
200
|
+
}
|
201
|
+
|
202
|
+
if(y <= 0.008856){
|
203
|
+
lab[0] = 903.3 * y;
|
204
|
+
fy = (7.787 * y + 16.0/116.0);
|
205
|
+
}else{
|
206
|
+
lab[0] = 116.0 * cbrt(y) - 16.0;
|
207
|
+
fy = cbrt(y);
|
208
|
+
}
|
209
|
+
|
210
|
+
if(z <= 0.008856){
|
211
|
+
fz = 7.787 * z/1.08883 + 16.0/116.0;
|
212
|
+
}else{
|
213
|
+
fz = cbrt(z/1.08883);
|
214
|
+
}
|
215
|
+
|
216
|
+
lab[1] = 500.0 * (fx-fy);
|
217
|
+
lab[2] = 200.0 * (fy-fz);
|
168
218
|
}
|
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: colourdistance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Orange Seven
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,9 +66,10 @@ dependencies:
|
|
66
66
|
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description: Currently only contains
|
70
|
-
to (roughly) a [0,1] scale (actually possible to get
|
71
|
-
add more.
|
69
|
+
description: Currently only contains three options (ciede 76, ciede94, and ciede2000),
|
70
|
+
all weighted to (roughly) a [0,1] scale (actually possible to get slightly above
|
71
|
+
1). Will add more. All are my own implementations (although ciede2000 is based on
|
72
|
+
a several dozen implementations found during research), and they may be wrong because
|
72
73
|
of it. Thanks go out to Josh Clayton (https://robots.thoughtbot.com/get-your-c-on),
|
73
74
|
for helping me to understand the structure I was attempting to acheive.
|
74
75
|
email:
|