jnylen-colorscore 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -2
- data/lib/colorscore/histogram.rb +2 -6
- data/lib/colorscore/version.rb +1 -1
- data/test/histogram_test.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8c814223d7b429f76b6b62d53fbe3be2e5a42d3
|
4
|
+
data.tar.gz: 46ccd43cf3c9b432366c2ea42904e4b8780fa549
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff4b836aa50ea6697793be254d12e0c98856b311ee1f69f6eec11b0069649b464d1f360b466c2e77a5714bc3b6ffb34d31329e628b52088405e7244371fd378e
|
7
|
+
data.tar.gz: 60b82f50750ef6e663f849874b53086c8ba7144b38a6a0e814f2d0834a8b0148d2556639372e6f7bff74cfcfea9d4271f86391d931e23a76260ba5c58345dd8a
|
data/README.md
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
Major change from normal colorscore: .colors is .hex_colors.
|
2
|
-
|
3
1
|
# Colorscore
|
4
2
|
|
5
3
|
Colorscore is a simple library that uses ImageMagick to quantize an image and find its representative colors. It can also score those colors against a palette using the CIE2000 Delta E formula. This could be used to index images for a "search by color" feature.
|
data/lib/colorscore/histogram.rb
CHANGED
@@ -21,15 +21,11 @@ module Colorscore
|
|
21
21
|
end
|
22
22
|
|
23
23
|
# Returns an array of colors in descending order of occurances.
|
24
|
-
def
|
24
|
+
def colors
|
25
25
|
hex_values = @lines.map { |line| line[/#([0-9A-F]{6}) /, 1] }.compact
|
26
26
|
hex_values.map { |hex| Color::RGB.from_html(hex) }
|
27
27
|
end
|
28
28
|
|
29
|
-
def rgb_colors
|
30
|
-
@lines.map { |line| line[/ \(([0-9, ]+)\) /, 1].split(',').map(&:strip).take(3).join(',') }.compact
|
31
|
-
end
|
32
|
-
|
33
29
|
def color_counts
|
34
30
|
@lines.map { |line| line.split(':')[0].to_i }
|
35
31
|
end
|
@@ -37,7 +33,7 @@ module Colorscore
|
|
37
33
|
def scores
|
38
34
|
total = color_counts.inject(:+).to_f
|
39
35
|
scores = color_counts.map { |count| count / total }
|
40
|
-
scores.zip(
|
36
|
+
scores.zip(colors)
|
41
37
|
end
|
42
38
|
end
|
43
39
|
end
|
data/lib/colorscore/version.rb
CHANGED
data/test/histogram_test.rb
CHANGED
@@ -4,11 +4,11 @@ class HistogramTest < Test::Unit::TestCase
|
|
4
4
|
def test_color_count_is_correct
|
5
5
|
colors = 7
|
6
6
|
histogram = Histogram.new("test/fixtures/skydiver.jpg", :colors => colors)
|
7
|
-
assert_operator histogram.
|
7
|
+
assert_operator histogram.colors.size, :<=, colors
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_transparency_is_ignored
|
11
11
|
histogram = Histogram.new("test/fixtures/transparency.png")
|
12
|
-
assert_equal Color::RGB.from_html('0000ff'), histogram.
|
12
|
+
assert_equal Color::RGB.from_html('0000ff'), histogram.colors.first
|
13
13
|
end
|
14
14
|
end
|