Class: Despeck::ColourChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/despeck/colour_checker.rb

Overview

Checks if image is black and white or colourized

Constant Summary collapse

PERCENT_THRESHOLD =
99
DE_THRESHOLD =
20

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(image:, **options) ⇒ ColourChecker

Returns a new instance of ColourChecker.



11
12
13
14
15
16
# File 'lib/despeck/colour_checker.rb', line 11

def initialize(image:, **options)
  @image = image
  @image = @image.resize(options.fetch(:resize, 1.0))
  @percent_threshold = options.fetch(:percent, PERCENT_THRESHOLD)
  @de_threshold      = options.fetch(:de,      DE_THRESHOLD)
end

Instance Attribute Details

#de_thresholdObject (readonly)

Returns the value of attribute de_threshold.



6
7
8
# File 'lib/despeck/colour_checker.rb', line 6

def de_threshold
  @de_threshold
end

#imageObject (readonly)

Returns the value of attribute image.



6
7
8
# File 'lib/despeck/colour_checker.rb', line 6

def image
  @image
end

#percent_thresholdObject (readonly)

Returns the value of attribute percent_threshold.



6
7
8
# File 'lib/despeck/colour_checker.rb', line 6

def percent_threshold
  @percent_threshold
end

Instance Method Details

#black_and_white?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/despeck/colour_checker.rb', line 18

def black_and_white?
  euclidean_distance =
    image.colourspace('lch')[1].cast('uchar').percent(percent_threshold)
  euclidean_distance <= de_threshold
end