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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 882eae2fbbf34e9fa57aeaa7208d885f9fb3decc
4
- data.tar.gz: a79e2d06ad5a20510432c6c0dca298303f9265ec
3
+ metadata.gz: 11687929d5850b325870f2f76a4d628f2707f324
4
+ data.tar.gz: f38950c622a96cda352855e494e97ce3bdb8bf8e
5
5
  SHA512:
6
- metadata.gz: 80710a342c934ac10406f6877976b4818666a99a3a3fdabe0aef379f85a622f820848193d57b6dd9bc551f12051938111ef0510f848f4eab003644ba10a23983
7
- data.tar.gz: 0dda1445cbe018f052937b71f1a638e218941a553e6b0052a61004de1c7d1b2d240898e6c2c07812dc88c5e3ceda1456eed3d50d3898daffec9203382b1c61c9
6
+ metadata.gz: 486844c8d1499848dbab9bedfd69155a023eac59d2470914cdec6d80c58a8457db398386ada6f9d4b153e549ece076c471279d3ef768be13333bb767f78d1e9e
7
+ data.tar.gz: bcf06a0b5d27545bbac8123a1dd69f84166f37d760dff9a95e33b5e8d73f688ed8d12cd419ec84a76011fd328c4aa1ccaa58ecaed863a94a22fd2d5ab82fc424
@@ -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 :auto_detect_border
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, auto_detect_border: true, boundary_color: :green)
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
- @auto_detect_border = auto_detect_border
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 @auto_detect_border && @image
55
+ set_stage_boundary if @image
54
56
  end
55
57
 
56
- # This handles the case of
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 if @auto_detect_border
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(@stage_boundary)
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 @stage_boundary.complete
92
- @stage_image = @image.crop(*@stage_boundary.for(SqedConfig.index_for_section_type(:stage, :stage)), true)
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: @stage_boundary,
112
- auto_detect_border: @auto_detect_border,
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
- @stage_boundary = Sqed::BoundaryFinder::StageFinder.new(image: @image).boundaries
122
- if !@stage_boundary.complete
123
- @stage_boundary.coordinates[0] = [0, 0, @image.columns, @image.rows]
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
 
@@ -84,11 +84,11 @@ class Sqed::Boundaries
84
84
  end
85
85
 
86
86
  def populated?
87
- @coordinates.each do |c|
88
- return false if c[0].nil?
87
+ self.each do |index, coords|
88
+ coords.each do |c|
89
+ return false if c.nil?
89
90
  end
91
+ end
90
92
  true
91
93
  end
92
-
93
-
94
94
  end
@@ -1,3 +1,3 @@
1
1
  class Sqed
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -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
- specimen: [ Sqed::Parser::OcrParser ],
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 => :specimen }
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::ColorLineFinder,
111
+ boundary_finder: Sqed::BoundaryFinder::CrossFinder,
112
112
  layout: :equal_cross,
113
- metadata_map: {0 => :curator_metadata, 1 => :identifier, 2 => :image_registration, 3 => :specimen }
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::CrossFinder,
117
+ boundary_finder: Sqed::BoundaryFinder::ColorLineFinder,
118
118
  layout: :cross,
119
- metadata_map: {0 => :curator_metadata, 1 => :identifier, 2 => :image_registration, 3 => :specimen }
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
- before {
176
- finder.boundaries.each do |i, coord|
177
- # q = thumb.crop(*coord, true)
178
- # q.write("tmp/thumb#{i}.jpg")
179
- end
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)
@@ -94,7 +94,6 @@ describe Sqed::BoundaryFinder do
94
94
  expect(center).to be < 1332
95
95
  end
96
96
  end
97
-
98
97
  end
99
98
 
100
99
  context '.frequency_stats(frequency_hash, samples_taken)' do
@@ -22,7 +22,7 @@ describe Sqed::Result do
22
22
 
23
23
  context 'with a new() result' do
24
24
  specify '#text_for(section)' do
25
- expect(r.text_for(:specimen)).to eq(nil)
25
+ expect(r.text_for(:annotated_specimen)).to eq(nil)
26
26
  end
27
27
 
28
28
  specify '#barcode_text_for(section)' do
@@ -25,8 +25,8 @@ describe Sqed do
25
25
  expect(s).to respond_to(:boundaries)
26
26
  end
27
27
 
28
- specify '#auto_detect_border' do
29
- expect(s).to respond_to(:auto_detect_border)
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 a specimen section' do
103
- expect(r.text_for(:specimen)).to match('Saucier Creek')
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sqed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Yoder