Class: Kreuzberg::Config::ImagePreprocessing
- Inherits:
-
Object
- Object
- Kreuzberg::Config::ImagePreprocessing
- Defined in:
- lib/kreuzberg/config.rb
Overview
Image preprocessing configuration for OCR
Constant Summary collapse
- VALID_BINARIZATION_METHODS =
%w[otsu sauvola niblack wolf bradley adaptive].freeze
Instance Attribute Summary collapse
-
#auto_rotate ⇒ Object
readonly
Returns the value of attribute auto_rotate.
-
#binarization_method ⇒ Object
readonly
Returns the value of attribute binarization_method.
-
#contrast_enhance ⇒ Object
readonly
Returns the value of attribute contrast_enhance.
-
#denoise ⇒ Object
readonly
Returns the value of attribute denoise.
-
#deskew ⇒ Object
readonly
Returns the value of attribute deskew.
-
#invert_colors ⇒ Object
readonly
Returns the value of attribute invert_colors.
-
#target_dpi ⇒ Object
readonly
Returns the value of attribute target_dpi.
Instance Method Summary collapse
-
#initialize(target_dpi: 300, auto_rotate: true, deskew: true, denoise: false, contrast_enhance: true, binarization_method: 'otsu', invert_colors: false) ⇒ ImagePreprocessing
constructor
A new instance of ImagePreprocessing.
- #to_h ⇒ Object
Constructor Details
#initialize(target_dpi: 300, auto_rotate: true, deskew: true, denoise: false, contrast_enhance: true, binarization_method: 'otsu', invert_colors: false) ⇒ ImagePreprocessing
Returns a new instance of ImagePreprocessing.
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 |
# File 'lib/kreuzberg/config.rb', line 535 def initialize( target_dpi: 300, auto_rotate: true, deskew: true, denoise: false, contrast_enhance: true, binarization_method: 'otsu', invert_colors: false ) @target_dpi = target_dpi.to_i @auto_rotate = auto_rotate ? true : false @deskew = deskew ? true : false @denoise = denoise ? true : false @contrast_enhance = contrast_enhance ? true : false @binarization_method = binarization_method.to_s @invert_colors = invert_colors ? true : false # Validate binarization method return if VALID_BINARIZATION_METHODS.include?(@binarization_method) valid_methods = VALID_BINARIZATION_METHODS.join(', ') raise ArgumentError, "Invalid binarization_method: #{@binarization_method}. Valid methods are: #{valid_methods}" end |
Instance Attribute Details
#auto_rotate ⇒ Object (readonly)
Returns the value of attribute auto_rotate.
530 531 532 |
# File 'lib/kreuzberg/config.rb', line 530 def auto_rotate @auto_rotate end |
#binarization_method ⇒ Object (readonly)
Returns the value of attribute binarization_method.
530 531 532 |
# File 'lib/kreuzberg/config.rb', line 530 def binarization_method @binarization_method end |
#contrast_enhance ⇒ Object (readonly)
Returns the value of attribute contrast_enhance.
530 531 532 |
# File 'lib/kreuzberg/config.rb', line 530 def contrast_enhance @contrast_enhance end |
#denoise ⇒ Object (readonly)
Returns the value of attribute denoise.
530 531 532 |
# File 'lib/kreuzberg/config.rb', line 530 def denoise @denoise end |
#deskew ⇒ Object (readonly)
Returns the value of attribute deskew.
530 531 532 |
# File 'lib/kreuzberg/config.rb', line 530 def deskew @deskew end |
#invert_colors ⇒ Object (readonly)
Returns the value of attribute invert_colors.
530 531 532 |
# File 'lib/kreuzberg/config.rb', line 530 def invert_colors @invert_colors end |
#target_dpi ⇒ Object (readonly)
Returns the value of attribute target_dpi.
530 531 532 |
# File 'lib/kreuzberg/config.rb', line 530 def target_dpi @target_dpi end |
Instance Method Details
#to_h ⇒ Object
560 561 562 563 564 565 566 567 568 569 570 |
# File 'lib/kreuzberg/config.rb', line 560 def to_h { target_dpi: @target_dpi, auto_rotate: @auto_rotate, deskew: @deskew, denoise: @denoise, contrast_enhance: @contrast_enhance, binarization_method: @binarization_method, invert_colors: @invert_colors } end |