Class: KvgCharacterRecognition::HeatmapFeature
- Inherits:
-
Object
- Object
- KvgCharacterRecognition::HeatmapFeature
- Includes:
- NonStructuralFeature
- Defined in:
- lib/kvg_character_recognition/heatmap_feature.rb
Instance Attribute Summary collapse
-
#heatmaps ⇒ Object
Returns the value of attribute heatmaps.
-
#number_of_grids ⇒ Object
Returns the value of attribute number_of_grids.
-
#size ⇒ Object
Returns the value of attribute size.
-
#weights ⇒ Object
Returns the value of attribute weights.
Instance Method Summary collapse
- #generate_heatmaps(bi_normed, ld_normed, pd_normed) ⇒ Object
-
#initialize(bi_normed, ld_normed, pd_normed, size, number_of_grids, weights = [1/9.0, 1/9.0, 1/9.0, 1/9.0, 1/9.0, 1/9.0, 1/9.0, 1/9.0, 1/9.0]) ⇒ HeatmapFeature
constructor
A new instance of HeatmapFeature.
Methods included from NonStructuralFeature
Constructor Details
#initialize(bi_normed, ld_normed, pd_normed, size, number_of_grids, weights = [1/9.0, 1/9.0, 1/9.0, 1/9.0, 1/9.0, 1/9.0, 1/9.0, 1/9.0, 1/9.0]) ⇒ HeatmapFeature
Returns a new instance of HeatmapFeature.
5 6 7 8 9 10 11 |
# File 'lib/kvg_character_recognition/heatmap_feature.rb', line 5 def initialize bi_normed, ld_normed, pd_normed, size, number_of_grids, weights=[1/9.0, 1/9.0, 1/9.0, 1/9.0, 1/9.0, 1/9.0, 1/9.0, 1/9.0, 1/9.0] @size = size @number_of_grids = number_of_grids @number_of_points = bi_normed.flatten(1).count @weights = weights @heatmaps = smooth(generate_heatmaps(bi_normed, ld_normed, pd_normed)) end |
Instance Attribute Details
#heatmaps ⇒ Object
Returns the value of attribute heatmaps.
4 5 6 |
# File 'lib/kvg_character_recognition/heatmap_feature.rb', line 4 def heatmaps @heatmaps end |
#number_of_grids ⇒ Object
Returns the value of attribute number_of_grids.
4 5 6 |
# File 'lib/kvg_character_recognition/heatmap_feature.rb', line 4 def number_of_grids @number_of_grids end |
#size ⇒ Object
Returns the value of attribute size.
4 5 6 |
# File 'lib/kvg_character_recognition/heatmap_feature.rb', line 4 def size @size end |
#weights ⇒ Object
Returns the value of attribute weights.
4 5 6 |
# File 'lib/kvg_character_recognition/heatmap_feature.rb', line 4 def weights @weights end |
Instance Method Details
#generate_heatmaps(bi_normed, ld_normed, pd_normed) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/kvg_character_recognition/heatmap_feature.rb', line 13 def generate_heatmaps bi_normed, ld_normed, pd_normed grid_size = size / @number_of_grids.to_f map = Map.new @number_of_grids, @number_of_grids, [0, 0, 0] #fill the heatmap bi_normed.each do |stroke| stroke.each do |point| grid1 = [(point[0] / grid_size).floor, (point[1] / grid_size).floor] map[grid1[0], grid1[1]] = [map[grid1[0], grid1[1]][0] + (1 / @number_of_points.to_f).round(4), map[grid1[0], grid1[1]][1], map[grid1[0], grid1[1]][2]] if grid1[0] < @number_of_grids && grid1[1] < @number_of_grids end end ld_normed.each do |stroke| stroke.each do |point| grid2 = [(point[0] / grid_size).floor, (point[1] / grid_size).floor] map[grid2[0], grid2[1]] = [map[grid2[0], grid2[1]][0], map[grid2[0], grid2[1]][1] + (1 / @number_of_points.to_f).round(4), map[grid2[0], grid2[1]][2]] if grid2[0] < @number_of_grids && grid2[1] < @number_of_grids end end pd_normed.each do |stroke| stroke.each do |point| grid4 = [(point[0] / grid_size).floor, (point[1] / grid_size).floor] map[grid4[0], grid4[1]] = [map[grid4[0], grid4[1]][0], map[grid4[0], grid4[1]][1], map[grid4[0], grid4[1]][2] + (1 / @number_of_points.to_f).round(4)] if grid4[0] < @number_of_grids && grid4[1] < @number_of_grids end end map end |