sqed 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sqed.rb +35 -24
- data/lib/sqed/boundaries.rb +4 -4
- data/lib/sqed/version.rb +1 -1
- data/lib/sqed_config.rb +6 -6
- data/spec/lib/sqed/boundary_finder/color_line_finder_spec.rb +6 -6
- data/spec/lib/sqed/boundary_finder_spec.rb +0 -1
- data/spec/lib/sqed/result_spec.rb +1 -1
- data/spec/lib/sqed_spec.rb +46 -6
- 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: 11687929d5850b325870f2f76a4d628f2707f324
|
4
|
+
data.tar.gz: f38950c622a96cda352855e494e97ce3bdb8bf8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 486844c8d1499848dbab9bedfd69155a023eac59d2470914cdec6d80c58a8457db398386ada6f9d4b153e549ece076c471279d3ef768be13333bb767f78d1e9e
|
7
|
+
data.tar.gz: bcf06a0b5d27545bbac8123a1dd69f84166f37d760dff9a95e33b5e8d73f688ed8d12cd419ec84a76011fd328c4aa1ccaa58ecaed863a94a22fd2d5ab82fc424
|
data/lib/sqed.rb
CHANGED
@@ -36,30 +36,30 @@ class Sqed
|
|
36
36
|
attr_accessor :boundaries
|
37
37
|
|
38
38
|
# Boolean, whether to detect the border on initialization, i.e. new()
|
39
|
-
attr_accessor :
|
39
|
+
attr_accessor :has_border
|
40
40
|
|
41
41
|
# a symbol, :red, :green, :blue, describing the boundary color within the stage
|
42
42
|
attr_accessor :boundary_color
|
43
43
|
|
44
|
-
def initialize(image: image, pattern: pattern,
|
44
|
+
def initialize(image: image, pattern: pattern, has_border: true, boundary_color: :green)
|
45
|
+
raise 'extraction pattern not defined' if pattern && !SqedConfig::EXTRACTION_PATTERNS.keys.include?(pattern)
|
46
|
+
|
45
47
|
@image = image
|
46
48
|
@boundaries = nil
|
47
49
|
@stage_boundary = Sqed::Boundaries.new(:internal_box)
|
48
|
-
@
|
50
|
+
@has_border = has_border
|
49
51
|
@pattern = pattern
|
50
52
|
@pattern ||= :cross
|
51
53
|
@boundary_color = boundary_color
|
52
54
|
|
53
|
-
set_stage_boundary if @
|
55
|
+
set_stage_boundary if @image
|
54
56
|
end
|
55
57
|
|
56
|
-
#
|
57
|
-
# s = Sqed.new() # no image: @some_image on init
|
58
|
-
# s.image = @some_image
|
59
|
-
#
|
58
|
+
# Attributes accessor overides
|
60
59
|
def image=(value)
|
61
60
|
@image = value
|
62
|
-
set_stage_boundary
|
61
|
+
set_stage_boundary
|
62
|
+
@image
|
63
63
|
end
|
64
64
|
|
65
65
|
def boundaries(force = false)
|
@@ -67,32 +67,36 @@ class Sqed
|
|
67
67
|
@boundaries
|
68
68
|
end
|
69
69
|
|
70
|
+
def stage_boundary
|
71
|
+
set_stage_boundary if !@stage_boundary.populated?
|
72
|
+
@stage_boundary
|
73
|
+
end
|
74
|
+
|
75
|
+
def stage_image
|
76
|
+
crop_image if @stage_image.nil?
|
77
|
+
@stage_image
|
78
|
+
end
|
79
|
+
|
70
80
|
# Return [Sqed::Boundaries instance]
|
71
81
|
# a boundaries instance that has the original image (prior to cropping stage) coordinates
|
72
82
|
def native_boundaries
|
73
83
|
# check for @boundaries.complete first? OR handle partial detections ?!
|
74
84
|
if @boundaries.complete
|
75
|
-
@boundaries.offset(
|
85
|
+
@boundaries.offset(stage_boundary)
|
76
86
|
else
|
77
87
|
nil
|
78
88
|
end
|
79
89
|
end
|
80
90
|
|
81
|
-
# return [Image]
|
82
|
-
# crops the image if not already done
|
83
|
-
def stage_image
|
84
|
-
crop_image if @stage_boundary.complete && @stage_image.nil?
|
85
|
-
@stage_image
|
86
|
-
end
|
87
|
-
|
88
91
|
# return [Image]
|
89
92
|
# crops the stage if not done, then sets/returns @stage_image
|
90
93
|
def crop_image
|
91
|
-
if @
|
92
|
-
@stage_image = @image.crop(
|
94
|
+
if @has_border
|
95
|
+
@stage_image = @image.crop(*stage_boundary.for(SqedConfig.index_for_section_type(:stage, :stage)), true)
|
93
96
|
else
|
94
97
|
@stage_image = @image
|
95
98
|
end
|
99
|
+
@stage_image
|
96
100
|
end
|
97
101
|
|
98
102
|
def result
|
@@ -108,8 +112,8 @@ class Sqed
|
|
108
112
|
{
|
109
113
|
image: @image,
|
110
114
|
boundaries: @boundaries,
|
111
|
-
stage_boundary:
|
112
|
-
|
115
|
+
stage_boundary: stage_boundary,
|
116
|
+
has_border: @has_border,
|
113
117
|
pattern: @pattern,
|
114
118
|
boundary_color: @boundary_color
|
115
119
|
}
|
@@ -118,12 +122,19 @@ class Sqed
|
|
118
122
|
protected
|
119
123
|
|
120
124
|
def set_stage_boundary
|
121
|
-
|
122
|
-
|
123
|
-
|
125
|
+
if @has_border
|
126
|
+
boundary = Sqed::BoundaryFinder::StageFinder.new(image: @image).boundaries
|
127
|
+
if boundary.populated?
|
128
|
+
@stage_boundary.set(0, boundary.for(0)) # = boundary
|
129
|
+
else
|
130
|
+
raise 'error detecting stage'
|
131
|
+
end
|
132
|
+
else
|
133
|
+
@stage_boundary.set(0, [0, 0, @image.columns, @image.rows])
|
124
134
|
end
|
125
135
|
end
|
126
136
|
|
137
|
+
# TODO make this a setter
|
127
138
|
def get_section_boundaries
|
128
139
|
boundary_finder_class = SqedConfig::EXTRACTION_PATTERNS[@pattern][:boundary_finder]
|
129
140
|
|
data/lib/sqed/boundaries.rb
CHANGED
data/lib/sqed/version.rb
CHANGED
data/lib/sqed_config.rb
CHANGED
@@ -91,7 +91,7 @@ module SqedConfig
|
|
91
91
|
identifier: [ Sqed::Parser::BarcodeParser, Sqed::Parser::OcrParser ],
|
92
92
|
deterimination_labels: [ Sqed::Parser::OcrParser ],
|
93
93
|
curator_metadata: [ Sqed::Parser::OcrParser ],
|
94
|
-
|
94
|
+
annotated_specimen: [ Sqed::Parser::OcrParser]
|
95
95
|
}
|
96
96
|
|
97
97
|
EXTRACTION_PATTERNS = {
|
@@ -104,19 +104,19 @@ module SqedConfig
|
|
104
104
|
vertical_offset_cross: {
|
105
105
|
boundary_finder: Sqed::BoundaryFinder::ColorLineFinder,
|
106
106
|
layout: :vertical_offset_cross,
|
107
|
-
metadata_map: {0 => :curator_metadata, 1 => :identifier, 2 => :image_registration, 3 => :
|
107
|
+
metadata_map: {0 => :curator_metadata, 1 => :identifier, 2 => :image_registration, 3 => :annotated_specimen }
|
108
108
|
},
|
109
109
|
|
110
110
|
equal_cross: {
|
111
|
-
boundary_finder: Sqed::BoundaryFinder::
|
111
|
+
boundary_finder: Sqed::BoundaryFinder::CrossFinder,
|
112
112
|
layout: :equal_cross,
|
113
|
-
metadata_map: {0 => :curator_metadata, 1 => :identifier, 2 => :image_registration, 3 => :
|
113
|
+
metadata_map: {0 => :curator_metadata, 1 => :identifier, 2 => :image_registration, 3 => :annotated_specimen }
|
114
114
|
},
|
115
115
|
|
116
116
|
cross: {
|
117
|
-
boundary_finder: Sqed::BoundaryFinder::
|
117
|
+
boundary_finder: Sqed::BoundaryFinder::ColorLineFinder,
|
118
118
|
layout: :cross,
|
119
|
-
metadata_map: {0 => :curator_metadata, 1 => :identifier, 2 => :image_registration, 3 => :
|
119
|
+
metadata_map: {0 => :curator_metadata, 1 => :identifier, 2 => :image_registration, 3 => :annotated_specimen }
|
120
120
|
},
|
121
121
|
|
122
122
|
stage: {
|
@@ -172,12 +172,12 @@ describe Sqed::BoundaryFinder::ColorLineFinder do
|
|
172
172
|
|
173
173
|
let(:pct) { 0.08 }
|
174
174
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
175
|
+
# before {
|
176
|
+
# finder.boundaries.each do |i, coord|
|
177
|
+
# q = thumb.crop(*coord, true)
|
178
|
+
# q.write("tmp/thumb#{i}.jpg")
|
179
|
+
# end
|
180
|
+
# }
|
181
181
|
|
182
182
|
specify "for section 0" do
|
183
183
|
expect(finder_boundaries.x_for(0)).to be_within(pct*thumb.columns).of(0)
|
data/spec/lib/sqed_spec.rb
CHANGED
@@ -25,8 +25,8 @@ describe Sqed do
|
|
25
25
|
expect(s).to respond_to(:boundaries)
|
26
26
|
end
|
27
27
|
|
28
|
-
specify '#
|
29
|
-
expect(s).to respond_to(:
|
28
|
+
specify '#has_border' do
|
29
|
+
expect(s).to respond_to(:has_border)
|
30
30
|
end
|
31
31
|
|
32
32
|
specify '#boundary_color' do
|
@@ -67,10 +67,10 @@ describe Sqed do
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
context 'all together' do
|
70
|
+
context 'all together, without border' do
|
71
71
|
let(:image) { ImageHelpers.frost_stage }
|
72
72
|
let(:pattern) { :vertical_offset_cross }
|
73
|
-
let(:s) { Sqed.new(image: image, pattern: pattern)
|
73
|
+
let(:s) { Sqed.new(image: image, pattern: pattern, has_border: false) }
|
74
74
|
|
75
75
|
specify '#boundaries returns a Sqed::Boundaries instance' do
|
76
76
|
expect(s.boundaries.class.name).to eq('Sqed::Boundaries')
|
@@ -99,8 +99,8 @@ describe Sqed do
|
|
99
99
|
expect(r.text_for(:identifier)).to match('000041196')
|
100
100
|
end
|
101
101
|
|
102
|
-
specify 'for
|
103
|
-
expect(r.text_for(:
|
102
|
+
specify 'for an annotated_specimen section' do
|
103
|
+
expect(r.text_for(:annotated_specimen)).to match('Saucier Creek')
|
104
104
|
end
|
105
105
|
|
106
106
|
specify 'for a curator_metadata section' do
|
@@ -110,4 +110,44 @@ describe Sqed do
|
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
|
+
context 'all together, with border' do
|
114
|
+
let(:image) { ImageHelpers.greenline_image }
|
115
|
+
let(:pattern) { :right_t }
|
116
|
+
let(:s) { Sqed.new(image: image, pattern: pattern, has_border: false) }
|
117
|
+
|
118
|
+
specify '#boundaries returns a Sqed::Boundaries instance' do
|
119
|
+
expect(s.boundaries.class.name).to eq('Sqed::Boundaries')
|
120
|
+
end
|
121
|
+
|
122
|
+
specify '#stage_image returns an Magick::Image' do
|
123
|
+
expect(s.stage_image.class.name).to eq('Magick::Image')
|
124
|
+
end
|
125
|
+
|
126
|
+
specify '#crop_image returns an Magick::Image' do
|
127
|
+
expect(s.crop_image.class.name).to eq('Magick::Image')
|
128
|
+
end
|
129
|
+
|
130
|
+
specify '#crop_image returns #stage_image' do
|
131
|
+
expect(s.crop_image).to eq(s.stage_image)
|
132
|
+
end
|
133
|
+
|
134
|
+
context '#result' do
|
135
|
+
let(:r) { s.result }
|
136
|
+
specify 'returns a Sqed::Result' do
|
137
|
+
expect(r.class.name).to eq('Sqed::Result')
|
138
|
+
end
|
139
|
+
|
140
|
+
context 'extracted data' do
|
141
|
+
specify 'for an :identifier section' do
|
142
|
+
expect(r.text_for(:identifier)).to match('000085067')
|
143
|
+
end
|
144
|
+
|
145
|
+
specify 'for a specimen section' do
|
146
|
+
expect(r.text_for(:annotated_specimen)).to match('Aeshna')
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
|
113
153
|
end
|