Class: Despeck::ColourChecker
- Inherits:
-
Object
- Object
- Despeck::ColourChecker
- 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
-
#de_threshold ⇒ Object
readonly
Returns the value of attribute de_threshold.
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#percent_threshold ⇒ Object
readonly
Returns the value of attribute percent_threshold.
Instance Method Summary collapse
- #black_and_white? ⇒ Boolean
-
#initialize(image:, **options) ⇒ ColourChecker
constructor
A new instance of ColourChecker.
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:, **) @image = image @image = @image.resize(.fetch(:resize, 1.0)) @percent_threshold = .fetch(:percent, PERCENT_THRESHOLD) @de_threshold = .fetch(:de, DE_THRESHOLD) end |
Instance Attribute Details
#de_threshold ⇒ Object (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 |
#image ⇒ Object (readonly)
Returns the value of attribute image.
6 7 8 |
# File 'lib/despeck/colour_checker.rb', line 6 def image @image end |
#percent_threshold ⇒ Object (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
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 |