colorscore 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of colorscore might be problematic. Click here for more details.

@@ -0,0 +1,22 @@
1
+ # Colorscore
2
+
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.
4
+
5
+ ## Requirements
6
+
7
+ * ImageMagick 6.5+
8
+
9
+ ## Usage
10
+
11
+ ```ruby
12
+ include Colorscore
13
+ histogram = Histogram.new('test/fixtures/skydiver.jpg')
14
+
15
+ # This image is 78.8% #7a9ab5:
16
+ histogram.scores.first # => [0.7884625, RGB [#7a9ab5]]
17
+
18
+ # This image is closest to pure blue:
19
+ palette = Palette.from_hex(['ff0000', '00ff00', '0000ff'])
20
+ scores = palette.scores(histogram.scores, 1)
21
+ scores.first # => [0.16493763694876, RGB [#0000ff]]
22
+ ```
@@ -1,7 +1,7 @@
1
1
  module Colorscore
2
2
  class Histogram
3
3
  def initialize(image_path, colors=16, depth=8)
4
- output = `convert #{image_path} -resize 400x400 -format %c -dither None -quantize LAB -colors #{colors} -depth #{depth} histogram:info:-`
4
+ output = `convert #{image_path} -resize 400x400 -format %c -dither None -quantize YIQ -colors #{colors} -depth #{depth} histogram:info:-`
5
5
  @lines = output.lines.sort.reverse.map(&:strip).reject(&:empty?)
6
6
  end
7
7
 
@@ -7,10 +7,14 @@ module Colorscore
7
7
  "000000", "999999", "cccccc", "ffffff"]
8
8
 
9
9
  def self.default
10
- new DEFAULT.map { |hex| Color::RGB.from_html(hex) }
10
+ from_hex DEFAULT
11
11
  end
12
12
 
13
- def scores(histogram_scores)
13
+ def self.from_hex(hex_values)
14
+ new hex_values.map { |hex| Color::RGB.from_html(hex) }
15
+ end
16
+
17
+ def scores(histogram_scores, distance_threshold=0.275)
14
18
  scores = map do |palette_color|
15
19
  score = 0
16
20
 
@@ -19,7 +23,7 @@ module Colorscore
19
23
 
20
24
  color = color.to_hsl.tap { |c| c.s = 0.05 + c.s * (4 - c.l * 2.5) }.to_rgb
21
25
 
22
- if (distance = Metrics.distance(palette_color, color)) < 0.275
26
+ if (distance = Metrics.distance(palette_color, color)) < distance_threshold
23
27
  distance_penalty = (1 - distance) ** 4
24
28
  score += color_score * distance_penalty
25
29
  end
@@ -1,3 +1,3 @@
1
1
  module Colorscore
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: colorscore
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Milo Winningham
@@ -15,11 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-12 00:00:00 -08:00
19
- default_executable:
18
+ date: 2012-02-12 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  prerelease: false
22
+ type: :runtime
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
25
25
  requirements:
@@ -29,11 +29,11 @@ dependencies:
29
29
  segments:
30
30
  - 0
31
31
  version: "0"
32
- type: :runtime
33
32
  name: color
34
33
  version_requirements: *id001
35
34
  - !ruby/object:Gem::Dependency
36
35
  prerelease: false
36
+ type: :development
37
37
  requirement: &id002 !ruby/object:Gem::Requirement
38
38
  none: false
39
39
  requirements:
@@ -43,7 +43,6 @@ dependencies:
43
43
  segments:
44
44
  - 0
45
45
  version: "0"
46
- type: :development
47
46
  name: rake
48
47
  version_requirements: *id002
49
48
  description: Finds the dominant colors in an image and scores them against a user-defined palette, using the CIE2000 Delta E formula.
@@ -58,6 +57,7 @@ extra_rdoc_files: []
58
57
  files:
59
58
  - .gitignore
60
59
  - Gemfile
60
+ - README.md
61
61
  - Rakefile
62
62
  - colorscore.gemspec
63
63
  - lib/colorscore.rb
@@ -70,7 +70,6 @@ files:
70
70
  - test/metrics_test.rb
71
71
  - test/palette_test.rb
72
72
  - test/test_helper.rb
73
- has_rdoc: true
74
73
  homepage:
75
74
  licenses: []
76
75
 
@@ -100,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
99
  requirements: []
101
100
 
102
101
  rubyforge_project:
103
- rubygems_version: 1.6.2
102
+ rubygems_version: 1.8.15
104
103
  signing_key:
105
104
  specification_version: 3
106
105
  summary: Finds the dominant colors in an image.