Class: LogoSoup::Core::FeatureMeasurer

Inherits:
Object
  • Object
show all
Defined in:
lib/logosoup/core/feature_measurer.rb

Overview

Measures raster features (density, content box, visual center offsets).

Constant Summary collapse

DEFAULT_PIXEL_BUDGET =
2_048

Class Method Summary collapse

Class Method Details

.call(path:, contrast_threshold:, pixel_budget: DEFAULT_PIXEL_BUDGET, on_error: nil) ⇒ Hash

Parameters:

  • path (String)
  • contrast_threshold (Integer)
  • pixel_budget (Integer) (defaults to: DEFAULT_PIXEL_BUDGET)
  • on_error (:raise, nil) (defaults to: nil)

Returns:

  • (Hash)


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
# File 'lib/logosoup/core/feature_measurer.rb', line 18

def self.call(path:, contrast_threshold:, pixel_budget: DEFAULT_PIXEL_BUDGET, on_error: nil)
  payload = ImageLoader.call(path: path, pixel_budget: pixel_budget, on_error: on_error)
  bytes = payload.fetch(:bytes)
  sample_width = payload.fetch(:sample_width)
  sample_height = payload.fetch(:sample_height)
  original_width = payload.fetch(:original_width)
  original_height = payload.fetch(:original_height)

  alpha_only, bg_r, bg_g, bg_b = BackgroundDetector.call(bytes, sample_width, sample_height)

  measured = PixelAnalyzer.call(
    bytes: bytes,
    sample_width: sample_width,
    sample_height: sample_height,
    original_width: original_width,
    original_height: original_height,
    contrast_threshold: contrast_threshold,
    alpha_only: alpha_only,
    bg_r: bg_r,
    bg_g: bg_g,
    bg_b: bg_b
  )

  measured || default_features(original_width, original_height)
end