percept 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/bin/percept +5 -0
- data/lib/percept.rb +4 -0
- data/lib/percept/line.rb +20 -0
- data/lib/percept/runner.rb +114 -0
- data/lib/percept/version.rb +3 -0
- data/new_permission.png +0 -0
- data/percept.gemspec +23 -0
- data/permission.png +0 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d9f0295d271b07be1b12d895a96975074bc59054
|
4
|
+
data.tar.gz: 7a91b69305d1a3e292c40f49d023b2fa8cca52fe
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f0171db0bbb7d4c9b8355dc07f3b53beac2abd30f14e512756d6dcec1a710d630d3886450dd34dbb10a941834ce8077c21acf81229589c233da3238a404084b0
|
7
|
+
data.tar.gz: 76d28cdee9fe4a8ce8a3832085e59edc1f6304e371354870edab2aa7f490e9c9ea9d455b125c544a92a0359a03e0f2dc7836b56fea3f70b994623a44b6a46617
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Robert Fletcher
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Percept
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'percept'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install percept
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/bin/percept
ADDED
data/lib/percept.rb
ADDED
data/lib/percept/line.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Percept
|
2
|
+
|
3
|
+
class Line
|
4
|
+
|
5
|
+
attr_accessor :start_x, :end_x, :start_y, :end_y, :row
|
6
|
+
def initialize(params)
|
7
|
+
self.start_x = params.fetch(:start_x)
|
8
|
+
self.end_x = params.fetch(:end_x)
|
9
|
+
self.start_y = params.fetch(:start_y)
|
10
|
+
self.end_y = params.fetch(:end_y) { start_y }
|
11
|
+
self.row = params.fetch(:row)
|
12
|
+
end
|
13
|
+
|
14
|
+
def pixels
|
15
|
+
row
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
module Percept
|
2
|
+
|
3
|
+
class Runner
|
4
|
+
def scaled_color(value)
|
5
|
+
(value * 256) - 1
|
6
|
+
end
|
7
|
+
|
8
|
+
LINE_LENGTH = 50
|
9
|
+
|
10
|
+
def tolerance
|
11
|
+
scaled_color(150)
|
12
|
+
end
|
13
|
+
#def black?(pixel)
|
14
|
+
# [pixel.red, pixel.green, pixel.blue].all? { |color| color == 0 }
|
15
|
+
#end
|
16
|
+
#
|
17
|
+
def blackish?(pixel)
|
18
|
+
[pixel.red, pixel.green, pixel.blue].all? { |color| color <= tolerance }
|
19
|
+
end
|
20
|
+
out_pixels = []
|
21
|
+
|
22
|
+
def highlight_lines!(row)
|
23
|
+
black = false
|
24
|
+
start_index = nil
|
25
|
+
line_indices = []
|
26
|
+
|
27
|
+
row.each_with_index do |pixel, index|
|
28
|
+
if blackish?(pixel) && start_index
|
29
|
+
# continue
|
30
|
+
elsif blackish?(pixel) && !start_index
|
31
|
+
start_index = index
|
32
|
+
elsif start_index
|
33
|
+
if index - start_index > LINE_LENGTH
|
34
|
+
line_indices += (start_index...index).to_a
|
35
|
+
end
|
36
|
+
start_index = nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
line_indices.each do |index|
|
41
|
+
pixel = row[index]
|
42
|
+
pixel.red = scaled_color(256)
|
43
|
+
end
|
44
|
+
row
|
45
|
+
end
|
46
|
+
|
47
|
+
def find_lines(row, row_number)
|
48
|
+
start_index = nil
|
49
|
+
lines = []
|
50
|
+
|
51
|
+
row.each_with_index do |pixel, index|
|
52
|
+
if blackish?(pixel)
|
53
|
+
start_index ||= index
|
54
|
+
elsif start_index
|
55
|
+
if index - start_index > LINE_LENGTH
|
56
|
+
lines << Line.new(:start_x => start_index, :end_x => index, :row => row, :start_y => row_number)
|
57
|
+
end
|
58
|
+
start_index = nil
|
59
|
+
end
|
60
|
+
end
|
61
|
+
lines
|
62
|
+
end
|
63
|
+
|
64
|
+
def each_row(image)
|
65
|
+
column_count = image.columns
|
66
|
+
row_count = image.rows
|
67
|
+
row_count.times do |row_number|
|
68
|
+
row = image.get_pixels(0, row_number, column_count, 1)
|
69
|
+
yield(row, row_number)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def run
|
74
|
+
images = Magick::ImageList.new('./permission.png')
|
75
|
+
image = images.first
|
76
|
+
#new_image = Magick::Image.new
|
77
|
+
|
78
|
+
rows = image.rows
|
79
|
+
columns = image.columns
|
80
|
+
|
81
|
+
lines = []
|
82
|
+
output_pixels = []
|
83
|
+
each_row(image) do |row, index|
|
84
|
+
output_pixels += row
|
85
|
+
if index % 50 == 0
|
86
|
+
puts "working on row: #{index} of #{rows}"
|
87
|
+
end
|
88
|
+
lines += find_lines(row, index)
|
89
|
+
#out_pixels += highlight_lines!(row)
|
90
|
+
#row.each do |pixel|
|
91
|
+
# pixel.red = scaled_color(256) if blackish?(pixel)
|
92
|
+
# out_pixels << pixel
|
93
|
+
#end
|
94
|
+
end
|
95
|
+
|
96
|
+
line_count = lines.count
|
97
|
+
lines.each_with_index do |line, index|
|
98
|
+
puts "coloring line #{index} of #{line_count}"
|
99
|
+
line.pixels.each do |pixel|
|
100
|
+
pixel.red = scaled_color(256)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
#image.each_pixel do |pixel, column, row|
|
105
|
+
# pixel.red = 60000 if blackish?(pixel)
|
106
|
+
# out_pixels << pixel
|
107
|
+
#end
|
108
|
+
|
109
|
+
image = image.store_pixels(0, 0, columns, rows, output_pixels)
|
110
|
+
image.write('new_permission.png')
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
data/new_permission.png
ADDED
Binary file
|
data/percept.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'percept/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'percept'
|
8
|
+
spec.version = Percept::VERSION
|
9
|
+
spec.authors = ['Robert Fletcher']
|
10
|
+
spec.email = ['lobatifricha@gmail.com']
|
11
|
+
spec.description = %q{Detect lines in an image}
|
12
|
+
spec.summary = %q{Blackish lines for now...}
|
13
|
+
spec.homepage = ''
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(spec)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
end
|
data/permission.png
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: percept
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robert Fletcher
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Detect lines in an image
|
42
|
+
email:
|
43
|
+
- lobatifricha@gmail.com
|
44
|
+
executables:
|
45
|
+
- percept
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- .gitignore
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/percept
|
55
|
+
- lib/percept.rb
|
56
|
+
- lib/percept/line.rb
|
57
|
+
- lib/percept/runner.rb
|
58
|
+
- lib/percept/version.rb
|
59
|
+
- new_permission.png
|
60
|
+
- percept.gemspec
|
61
|
+
- permission.png
|
62
|
+
homepage: ''
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.1.11
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: Blackish lines for now...
|
86
|
+
test_files: []
|
87
|
+
has_rdoc:
|