sqed 0.4.3 → 0.4.4

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: 6e7eb1eb4ed58c823f9388bbe46f734834ff9825
4
- data.tar.gz: 4ff58cb61cc0910791c8c0504ee65680b909c192
3
+ metadata.gz: df36b8e8052dc45504b1a8cfb4f511b7d5af680f
4
+ data.tar.gz: 2557f8b06d2c521893d4bbace2c9433be420e376
5
5
  SHA512:
6
- metadata.gz: 4a33d512a77f4a36c883b059b1a6c3b975ae339bdb7ee01a05e10bd0251e16934bc3d712712d26d93c776e090efcc471bd9fbc8602d0f0b773d0ab1a5f3b6415
7
- data.tar.gz: 6b48b416a4b7c7685e595956711c046026931816c9b897d9263d45b141b92de06ca5d45a78cb17b9f1bdca78c493b2770e9ac7aa7d29bc5679f3fc80adc0a52b
6
+ metadata.gz: a190d03073872ad472a422d96b8f62fce283c2936a18d53d6b90f7409e07acfc6f407a5125d88350a04ccecccef3709e7c4c82fa2059ba806f52685cb86948eb
7
+ data.tar.gz: d29c8d94a3d04c4a8461e11573fafdb7be8383d305ccb7222a05b9cb123fd4e18d135f27df551eee96970552324a91e67688e81754cad37c631472bd41dd0fb3
@@ -130,8 +130,31 @@ class Sqed
130
130
 
131
131
  image_width = image.send(scan)
132
132
  sample_subdivision_size = get_subdivision_size(image_width) if sample_subdivision_size.nil?
133
- samples_to_take = (image_width / sample_subdivision_size).to_i - 1
134
133
 
134
+ attempts = 0
135
+ while attempts < 5 do
136
+ samples_to_take = (image_width / sample_subdivision_size).to_i - 1
137
+ border_hits = sample_border(image, boundary_color, samples_to_take, sample_subdivision_size, scan)
138
+
139
+ break if border_hits.select{|k,v| v > 1}.size > 2 || sample_subdivision_size == 1
140
+
141
+ sample_subdivision_size = (sample_subdivision_size.to_f / 2.0).to_i
142
+ attempts += 1
143
+ end
144
+
145
+ return nil if border_hits.length < 2
146
+
147
+ if sample_cutoff_factor.nil?
148
+ cutoff = max_difference(border_hits.values)
149
+ cutoff = border_hits.values.first - 1 if cutoff == 0 # difference of two identical things is 0
150
+ else
151
+ cutoff = (samples_to_take * sample_cutoff_factor).to_i
152
+ end
153
+
154
+ frequency_stats(border_hits, cutoff)
155
+ end
156
+
157
+ def self.sample_border(image, boundary_color, samples_to_take, sample_subdivision_size, scan)
135
158
  border_hits = {}
136
159
 
137
160
  (0..samples_to_take).each do |s|
@@ -160,17 +183,7 @@ class Sqed
160
183
  end
161
184
  end
162
185
 
163
- return nil if border_hits.length < 2
164
-
165
- if sample_cutoff_factor.nil?
166
- cutoff = max_difference(border_hits.values)
167
-
168
- cutoff = border_hits.values.first - 1 if cutoff == 0 # difference of two identical things is 0
169
- else
170
- cutoff = (samples_to_take * sample_cutoff_factor).to_i
171
- end
172
-
173
- frequency_stats(border_hits, cutoff)
186
+ border_hits
174
187
  end
175
188
 
176
189
  def self.is_green?(pixel)
@@ -30,7 +30,6 @@ class Sqed::BoundaryFinder::ColorLineFinder < Sqed::BoundaryFinder
30
30
  def find_bands
31
31
  case layout # boundaries.coordinates are referenced from stage image
32
32
 
33
- # No specs for this yet
34
33
  when :lep_stage
35
34
  top_bottom_split = Sqed::BoundaryFinder.color_boundary_finder(image: image, scan: :columns, boundary_color: boundary_color) # detect vertical division [array]
36
35
  left_right_split = Sqed::BoundaryFinder.color_boundary_finder(image: image, sample_subdivision_size: 2, boundary_color: boundary_color) # detect horizontal division [array]
@@ -48,8 +47,7 @@ class Sqed::BoundaryFinder::ColorLineFinder < Sqed::BoundaryFinder
48
47
 
49
48
  boundaries.set(0, [0, 0, left_top_split[1], top_bottom_split[0]] ) # keep as 1 for safety
50
49
 
51
- boundaries.set(1, [left_top_split[2], 0, left_top_image.columns - left_top_split[2], top_bottom_split[0]] ) # <
52
-
50
+ boundaries.set(1, [left_top_split[2], 0, left_top_image.columns - left_top_split[2], top_bottom_split[0]] )
53
51
  boundaries.set(2, [left_right_split[2], 0, image.columns - left_right_split[0], top_bottom_split[0]] )
54
52
 
55
53
  bottom_right_image = image.crop(left_right_split[2], top_bottom_split[2], image.columns - left_right_split[2], image.rows - top_bottom_split[2], true)
@@ -92,11 +90,13 @@ class Sqed::BoundaryFinder::ColorLineFinder < Sqed::BoundaryFinder
92
90
  right_bottom_image = image.crop(left_right_split[2], top_bottom_split[2], image.columns - left_right_split[2], image.rows - top_bottom_split[2], true) # sections 3,4,5
93
91
 
94
92
  right_top_split = ::SqedUtils.corrected_frequency(
95
- Sqed::BoundaryFinder.color_boundary_finder(image: right_top_image, boundary_color: boundary_color),
93
+ Sqed::BoundaryFinder.color_boundary_finder(image: right_top_image, boundary_color: boundary_color, scan: :rows),
96
94
  width_factor: 1.8,
97
95
  max_width: right_top_image.columns
98
96
  ) # vertical line b/w 1 & 2, use "corrected_frequency" to account for color bleed from previous crop
99
97
 
98
+
99
+
100
100
  boundaries.set(1, [left_right_split[2], 0, right_top_split[0], top_bottom_split[0]] )
101
101
  boundaries.set(2, [left_right_split[2] + right_top_split[2], 0, right_top_image.columns - right_top_split[2], top_bottom_split[0]])
102
102
 
@@ -1,3 +1,3 @@
1
1
  class Sqed
2
- VERSION = '0.4.3'.freeze
2
+ VERSION = '0.4.4'.freeze
3
3
  end
@@ -11,6 +11,9 @@ module SqedUtils
11
11
  # @param frequency_stats [Array]
12
12
  # like [1,2,3]
13
13
  #
14
+ # @param width_factor [Float]
15
+ #
16
+ #
14
17
  # @param max_width [Integer]
15
18
  # required, the width of the image in question
16
19
  #
@@ -33,9 +36,6 @@ module SqedUtils
33
36
  a = (m - v0).abs
34
37
  b = (v2 - m).abs
35
38
 
36
- c = a * width_factor
37
- d = b * width_factor
38
-
39
39
  largest = (a > b ? a : b)
40
40
 
41
41
  l = (m - b / 2)
@@ -44,17 +44,15 @@ module SqedUtils
44
44
  r = (m + a / 2)
45
45
  r = max_width if r > max_width
46
46
 
47
- x = a * width_factor
48
- y = b * width_factor
47
+ c = a * width_factor
48
+ d = b * width_factor
49
49
 
50
50
  [
51
- x > largest ? l : v0,
51
+ c > largest ? l : v0,
52
52
  m,
53
- y > largest ? r : v2
53
+ d > largest ? r : v2
54
54
  ]
55
55
 
56
56
  end
57
57
 
58
-
59
-
60
58
  end
@@ -60,10 +60,11 @@ describe Sqed::BoundaryFinder do
60
60
  expect(center).to be < 2495
61
61
  end
62
62
 
63
- specify 'FAILS to find the vertical dividing line a real image, with border still present, with 200x fewer subsamples' do
64
- center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.crossy_green_line_specimen, sample_subdivision_size: 2000 )
65
- expect(center).to be nil
66
- end
63
+ # This is found now because of increased refinement
64
+ # specify 'FAILS to find the vertical dividing line a real image, with border still present, with 200x fewer subsamples' do
65
+ # center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.crossy_green_line_specimen, sample_subdivision_size: 2000 )
66
+ # expect(center).to be nil
67
+ # end
67
68
 
68
69
  specify 'finds the vertical dividing line another real image, with border still present' do
69
70
  center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.greenline_image)[1]
@@ -60,5 +60,14 @@ describe 'handling 7 slot stages' do
60
60
  end
61
61
  end
62
62
  end
63
+ end
64
+
65
+ context 'another image' do
66
+ let(:s) { Sqed.new(image: ImageHelpers.frost_seven_slot, use_thumbnail: true, pattern: :seven_slot, boundary_color: :red, has_border: false ) }
67
+
68
+ specify '#result' do
69
+ expect(s.result).to be_truthy
70
+ end
63
71
  end
72
+
64
73
  end
@@ -19,6 +19,10 @@ module ImageHelpers
19
19
  get_image 'stage_images/boundary_cross_green.jpg'
20
20
  end
21
21
 
22
+ def frost_seven_slot
23
+ get_image 'stage_images/frost_7_slot.jpg'
24
+ end
25
+
22
26
  def frost_stage
23
27
  get_image 'stage_images/frost_stage.jpg'
24
28
  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.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Yoder
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-09-11 00:00:00.000000000 Z
12
+ date: 2018-09-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -171,6 +171,7 @@ files:
171
171
  - spec/support/files/stage_images/boundary_left_t_yellow.jpg
172
172
  - spec/support/files/stage_images/boundary_offset_cross_red.jpg
173
173
  - spec/support/files/stage_images/boundary_right_t_green.jpg
174
+ - spec/support/files/stage_images/frost_7_slot.jpg
174
175
  - spec/support/files/stage_images/frost_stage.jpg
175
176
  - spec/support/files/stage_images/frost_stage_medium.jpg
176
177
  - spec/support/files/stage_images/frost_stage_thumb.jpg
@@ -244,6 +245,7 @@ test_files:
244
245
  - spec/support/files/stage_images/boundary_left_t_yellow.jpg
245
246
  - spec/support/files/stage_images/boundary_offset_cross_red.jpg
246
247
  - spec/support/files/stage_images/boundary_right_t_green.jpg
248
+ - spec/support/files/stage_images/frost_7_slot.jpg
247
249
  - spec/support/files/stage_images/frost_stage.jpg
248
250
  - spec/support/files/stage_images/frost_stage_medium.jpg
249
251
  - spec/support/files/stage_images/frost_stage_thumb.jpg