kaleidoscope 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kaleidoscope.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Josh Smith
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,131 @@
1
+ # Kaleidoscope
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/kaleidoscope.png)][gem] [![Build Status](https://travis-ci.org/JoshSmith/kaleidoscope.png?branch=master)](https://travis-ci.org/JoshSmith/kaleidoscope) [![Dependency Status](https://gemnasium.com/JoshSmith/kaleidoscope.png)](https://gemnasium.com/JoshSmith/kaleidoscope) [![Code Climate](https://codeclimate.com/github/JoshSmith/kaleidoscope.png)](https://codeclimate.com/github/JoshSmith/kaleidoscope)
4
+
5
+ Kaleidoscope is color search for Rails using Active Record and Paperclip. The intent behind it was to index a database of images by color for quick retrieval.
6
+
7
+ Kaleidoscope works by running histograms on images and converting their top *n* colors (by frequency) into [L*a*b* color space](http://en.wikipedia.org/wiki/Lab_color_space) for a more approximate representation of human vision. Colors are then matched to a specified set of colors using Euclidean distance. The gem will store hexadecimal values of the image's original color and the matched color, along with the frequency of that color within the image (for sorting based on frequency) and the Euclidean distance (for sorting by tolerance).
8
+
9
+ Since L*a*b* relies so heavily on lightness, matches for white, black, and grey will all be quite poor compared to other color types.
10
+
11
+ Here's an example of what Kaleidoscope can do:
12
+
13
+ ![Kaleidoscope Example](http://cl.ly/image/3n2C16170i0k/Screen%20Shot%202013-02-05%20at%206.56.44%20PM.png)
14
+
15
+ ## Requirements
16
+
17
+ ### Paperclip
18
+
19
+ Currently Kaleidoscope requires you to have [Paperclip](https://github.com/thoughtbot/paperclip) already run on the model you want indexed for color search.
20
+
21
+ In the future, it would be nice if Paperclip were not a requirement and Kaleidoscope could work with, say, CarrierWave.
22
+
23
+ ### Image Processor
24
+
25
+ [ImageMagick](http://www.imagemagick.org/) must be installed and Kaleidoscope must have access to it via [RMagick](https://github.com/rmagick/rmagick). To ensure that it does, on your command line, run `which convert` (one of the ImageMagick utilities). This will give you the path where that utility is installed. For example, it might return `/usr/local/bin/convert/`.
26
+
27
+ If you're on Mac OS X, you'll want to run the following with Homebrew:
28
+
29
+ ```
30
+ brew install imagemagick
31
+ ```
32
+
33
+ ## Installation
34
+
35
+ Add this line to your application's Gemfile:
36
+
37
+ gem 'kaleidoscope'
38
+
39
+ And then execute:
40
+
41
+ $ bundle
42
+
43
+ Or install it yourself as:
44
+
45
+ $ gem install kaleidoscope
46
+
47
+ ## Usage
48
+
49
+ Generate your migration by specifying the Paperclip model, e.g. `Photo`:
50
+
51
+ ```bash
52
+ rails generate kaleidoscope photo
53
+ ```
54
+
55
+ This will generate the model `PhotoColor`.
56
+
57
+ Alternatively, in your models:
58
+
59
+ ```ruby
60
+ class Photo < ActiveRecord::Base
61
+ has_many :photo_colors
62
+ end
63
+
64
+ class PhotoColor < ActiveRecord::Base
65
+ belongs_to :photo
66
+
67
+ attr_accessible :photo_id, :distance, :frequency, :original_color, :reference_color
68
+ end
69
+ ```
70
+
71
+ And in your migrations:
72
+
73
+ ```ruby
74
+ class AddPhotoColors < ActiveRecord::Migration
75
+ def change
76
+ create_table :photo_colors do |t|
77
+ t.integer :photo_id
78
+ t.string :original_color
79
+ t.string :reference_color
80
+ t.float :frequency
81
+ t.integer :distance
82
+
83
+ t.timestamps
84
+ end
85
+
86
+ add_index :photo_colors, :photo_id
87
+ add_index :photo_colors, :original_color
88
+ add_index :photo_colors, :reference_color
89
+ add_index :photo_colors, :frequency
90
+ add_index :photo_colors, :distance
91
+ end
92
+ end
93
+ ```
94
+
95
+ In your controller:
96
+
97
+ ```ruby
98
+ def index
99
+ @photos = Photo.all.with_color(params[:color])
100
+ end
101
+ ```
102
+
103
+ To refresh the color database:
104
+
105
+ ```bash
106
+ rake kaleidosocope:refresh
107
+ ```
108
+
109
+ ## Contributing
110
+
111
+ Please submit pull requests! I'd love to feature you as a contributor. Here's a guide:
112
+
113
+ 1. Fork the repo.
114
+ 2. Run the tests. We only take pull requests with passing tests.
115
+ 3. Add a test for your change. Only refactoring and documentation changes require no new tests. If you are adding functionality or fixing a bug, we need a test.
116
+ 4. Make the test pass.
117
+ 5. Push to your fork and submit a pull request.
118
+
119
+ We'll review your changes, comment, and then accept or throw it back to you for improvement.
120
+
121
+ ### Syntax
122
+
123
+ * Two spaces, no tabs.
124
+ * No trailing whitespace.
125
+ * Prefer &&/II over and/or.
126
+ * a = b and not a=b
127
+ * Follow conventions you see used in the source already.
128
+
129
+ ## TODO
130
+
131
+ 1. Enable Kaleidoscope to work without requiring Paperclip. Ideally, any database of images should be searchable and we don't want to be tied down to one specific gem.
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require "rspec/core/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new
6
+
7
+ task :default => :spec
8
+ task :test => :spec
@@ -0,0 +1,36 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kaleidoscope/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "kaleidoscope"
8
+ gem.version = Kaleidoscope::VERSION
9
+ gem.platform = Gem::Platform::RUBY
10
+ gem.authors = ["Josh Smith"]
11
+ gem.email = ["joshdotsmith@gmail.com"]
12
+ gem.description = %q{Color search for Rails}
13
+ gem.summary = %q{Kaleidoscope is color search for Rails using Active Record and Paperclip. The intent behind it was to index a database of images by color for quick retrieval.}
14
+ gem.homepage = "https://github.com/JoshSmith/kaleidoscope"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.requirements << "ImageMagick"
22
+ gem.required_ruby_version = ">= 1.9.2"
23
+
24
+ gem.add_dependency('activerecord', '>= 3.0.0')
25
+ gem.add_dependency('activemodel', '>= 3.0.0')
26
+ gem.add_dependency('activesupport', '>= 3.0.0')
27
+
28
+ gem.add_dependency('rmagick', '>= 2.13.0')
29
+
30
+ gem.add_dependency('paperclip', '>= 3.3.0')
31
+
32
+ gem.add_development_dependency('rspec')
33
+ gem.add_development_dependency('generator_spec')
34
+ gem.add_development_dependency('railties')
35
+ gem.add_development_dependency('rails')
36
+ end
@@ -0,0 +1,26 @@
1
+ require 'rails/generators/active_record'
2
+
3
+ class KaleidoscopeGenerator < ActiveRecord::Generators::Base
4
+ desc "Create a migration to add kaleidoscope models."
5
+
6
+ def self.source_root
7
+ @source_root ||= File.expand_path('../templates', __FILE__)
8
+ end
9
+
10
+ def generate_migration
11
+ migration_template "kaleidoscope_migration.rb.erb", "db/migrate/#{migration_file_name}"
12
+ end
13
+
14
+ protected
15
+ def migration_name
16
+ "create_#{name.underscore}_colors"
17
+ end
18
+
19
+ def migration_file_name
20
+ "#{migration_name}.rb"
21
+ end
22
+
23
+ def migration_class_name
24
+ migration_name.camelize
25
+ end
26
+ end
@@ -0,0 +1,19 @@
1
+ class <%= migration_class_name %> < ActiveRecord::Migration
2
+ def change
3
+ create_table :<%= name.underscore %>_colors do |t|
4
+ t.integer :<%= name.underscore %>_id
5
+ t.string :original_color
6
+ t.string :reference_color
7
+ t.float :frequency
8
+ t.integer :distance
9
+
10
+ t.timestamps
11
+ end
12
+
13
+ add_index :<%= name.underscore %>_colors, :<%= name.underscore %>_id
14
+ add_index :<%= name.underscore %>_colors, :original_color
15
+ add_index :<%= name.underscore %>_colors, :reference_color
16
+ add_index :<%= name.underscore %>_colors, :frequency
17
+ add_index :<%= name.underscore %>_colors, :distance
18
+ end
19
+ end
@@ -0,0 +1,6 @@
1
+ require 'RMagick'
2
+ require 'kaleidoscope/version'
3
+
4
+ module Kaleidoscope
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,3 @@
1
+ module Kaleidoscope
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,18 @@
1
+ module Kaleidoscope
2
+ module Task
3
+ def self.obtain_class
4
+ class_name = ENV['CLASS'] || ENV['class']
5
+ raise "Must specify CLASS" unless class_name
6
+ class_name
7
+ end
8
+ end
9
+ end
10
+
11
+ namespace :kaleidoscope do
12
+ desc "Refreshes color data."
13
+ task :refresh => ["kaleidoscope:refresh"]
14
+
15
+ namespace :refresh do
16
+ desc "Refreshes color data for a given CLASS."
17
+ end
18
+ end
@@ -0,0 +1,50 @@
1
+ require 'rails'
2
+ require 'spec_helper'
3
+ require 'generator_spec/test_case'
4
+ require 'generators/kaleidoscope/kaleidoscope_generator'
5
+
6
+ describe 'TestMigration' do
7
+ include GeneratorSpec::TestCase
8
+ tests KaleidoscopeGenerator
9
+ destination File.expand_path("../tmp", __FILE__)
10
+ arguments %w(photo)
11
+
12
+ before do
13
+ prepare_destination
14
+ run_generator
15
+ end
16
+
17
+ it 'Should create a correct migration file' do
18
+ assert_migration 'db/migrate/create_photo_colors' do |migration|
19
+ assert_match /class CreatePhotoColors/, migration
20
+
21
+ assert_method :change, migration do |change|
22
+ expected = <<MIGRATION
23
+ create_table :photo_colors do |t|
24
+ t.integer :photo_id
25
+ t.string :original_color
26
+ t.string :reference_color
27
+ t.float :frequency
28
+ t.integer :distance
29
+
30
+ t.timestamps
31
+ end
32
+
33
+ add_index :photo_colors, :photo_id
34
+ add_index :photo_colors, :original_color
35
+ add_index :photo_colors, :reference_color
36
+ add_index :photo_colors, :frequency
37
+ add_index :photo_colors, :distance
38
+ MIGRATION
39
+
40
+ assert_equal expected.squish, change.squish
41
+ end
42
+ end
43
+ end
44
+
45
+ it 'Should not create the migration without required arguments' do
46
+ prepare_destination
47
+ silence_stream(STDERR) { run_generator %w() }
48
+ assert_no_migration 'db/migrate/create_photo_colors'
49
+ end
50
+ end
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+
3
+ require 'active_support'
4
+ require 'active_support/core_ext'
5
+
6
+ # This file was generated by the `rspec --init` command. Conventionally, all
7
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
8
+ # Require this file using `require "spec_helper"` to ensure that it is only
9
+ # loaded once.
10
+ #
11
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
12
+ RSpec.configure do |config|
13
+ config.treat_symbols_as_metadata_keys_with_true_values = true
14
+ config.run_all_when_everything_filtered = true
15
+ config.filter_run :focus
16
+
17
+ # Run specs in random order to surface order dependencies. If you find an
18
+ # order dependency and want to debug it, you can fix the order by providing
19
+ # the seed, which is printed after each run.
20
+ # --seed 1234
21
+ config.order = 'random'
22
+ end
metadata ADDED
@@ -0,0 +1,207 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kaleidoscope
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Josh Smith
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activerecord
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: activemodel
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 3.0.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 3.0.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: activesupport
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 3.0.0
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 3.0.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: rmagick
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: 2.13.0
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 2.13.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: paperclip
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: 3.3.0
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 3.3.0
94
+ - !ruby/object:Gem::Dependency
95
+ name: rspec
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: generator_spec
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: railties
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: rails
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ description: Color search for Rails
159
+ email:
160
+ - joshdotsmith@gmail.com
161
+ executables: []
162
+ extensions: []
163
+ extra_rdoc_files: []
164
+ files:
165
+ - .gitignore
166
+ - .rspec
167
+ - Gemfile
168
+ - LICENSE.txt
169
+ - README.md
170
+ - Rakefile
171
+ - kaleidoscope.gemspec
172
+ - lib/generators/kaleidoscope/kaleidoscope_generator.rb
173
+ - lib/generators/kaleidoscope/templates/kaleidoscope_migration.rb.erb
174
+ - lib/kaleidoscope.rb
175
+ - lib/kaleidoscope/version.rb
176
+ - lib/tasks/kaleidoscope.rake
177
+ - spec/generator_spec.rb
178
+ - spec/spec_helper.rb
179
+ homepage: https://github.com/JoshSmith/kaleidoscope
180
+ licenses: []
181
+ post_install_message:
182
+ rdoc_options: []
183
+ require_paths:
184
+ - lib
185
+ required_ruby_version: !ruby/object:Gem::Requirement
186
+ none: false
187
+ requirements:
188
+ - - ! '>='
189
+ - !ruby/object:Gem::Version
190
+ version: 1.9.2
191
+ required_rubygems_version: !ruby/object:Gem::Requirement
192
+ none: false
193
+ requirements:
194
+ - - ! '>='
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ requirements:
198
+ - ImageMagick
199
+ rubyforge_project:
200
+ rubygems_version: 1.8.23
201
+ signing_key:
202
+ specification_version: 3
203
+ summary: Kaleidoscope is color search for Rails using Active Record and Paperclip.
204
+ The intent behind it was to index a database of images by color for quick retrieval.
205
+ test_files:
206
+ - spec/generator_spec.rb
207
+ - spec/spec_helper.rb