Class: Sqed::BoundaryFinder::StageFinder

Inherits:
Sqed::BoundaryFinder show all
Defined in:
lib/sqed/boundary_finder/stage_finder.rb

Overview

Some of this code was originally inspired by Emmanuel Oga’s gist gist.github.com/EmmanuelOga/2476153.

Constant Summary collapse

MIN_CROP_RATIO =

How small we accept a cropped picture to be. E.G. if it was 100x100 and ratio 0.1, min output should be 10x10

0.1

Constants inherited from Sqed::BoundaryFinder

COLOR_DELTA, THUMB_SIZE

Instance Attribute Summary collapse

Attributes inherited from Sqed::BoundaryFinder

#boundaries, #image, #layout, #original_image, #use_thumbnail

Instance Method Summary collapse

Methods inherited from Sqed::BoundaryFinder

color_boundary_finder, derivative, derivative_signs, frequency_stats, get_subdivision_size, #height_factor, is_black?, is_blue?, is_green?, is_red?, #longest_thumbnail_axis, max_difference, max_pairwise_difference, sample_border, #thumbnail, #thumbnail_height, #thumbnail_width, #width_factor, #zoom_boundaries

Constructor Details

#initialize(**opts) ⇒ StageFinder

Returns a new instance of StageFinder.



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
# File 'lib/sqed/boundary_finder/stage_finder.rb', line 18

def initialize(**opts)
  image = opts[:image]
  is_border_proc = opts[:is_border_proc]
  min_ratio = opts[:min_ratio]
  min_ratio ||= MIN_CROP_RATIO

  super(image: image, layout: :internal_box)

  @min_ratio = min_ratio

  # Initial co-ordinates
  @x0, @y0 = 0, 0
  @x1, @y1 = image.columns, image.rows
  @min_width, @min_height = image.columns * @min_ratio, image.rows * @min_ratio # minimum resultant area
  @columns, @rows = image.columns, image.rows


  # We need a border finder proc. Provide one if none was given.
  @is_border = is_border_proc || self.class.default_border_finder(image) # if no proc specified, use default below

  @x00 = @x0
  @y00 = @y0
  @height0 = height
  @width0 = width
  find_edges
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



16
17
18
# File 'lib/sqed/boundary_finder/stage_finder.rb', line 16

def columns
  @columns
end

#is_borderObject (readonly)

The proc containing the border finding algorithim



8
9
10
# File 'lib/sqed/boundary_finder/stage_finder.rb', line 8

def is_border
  @is_border
end

#min_heightObject (readonly)

Returns the value of attribute min_height.



16
17
18
# File 'lib/sqed/boundary_finder/stage_finder.rb', line 16

def min_height
  @min_height
end

#min_widthObject (readonly)

Returns the value of attribute min_width.



16
17
18
# File 'lib/sqed/boundary_finder/stage_finder.rb', line 16

def min_width
  @min_width
end

#rowsObject (readonly)

Returns the value of attribute rows.



16
17
18
# File 'lib/sqed/boundary_finder/stage_finder.rb', line 16

def rows
  @rows
end

#x0Object (readonly)

Returns the value of attribute x0.



16
17
18
# File 'lib/sqed/boundary_finder/stage_finder.rb', line 16

def x0
  @x0
end

#x1Object (readonly)

Returns the value of attribute x1.



16
17
18
# File 'lib/sqed/boundary_finder/stage_finder.rb', line 16

def x1
  @x1
end

#y0Object (readonly)

Returns the value of attribute y0.



16
17
18
# File 'lib/sqed/boundary_finder/stage_finder.rb', line 16

def y0
  @y0
end

#y1Object (readonly)

Returns the value of attribute y1.



16
17
18
# File 'lib/sqed/boundary_finder/stage_finder.rb', line 16

def y1
  @y1
end