Class: OcrFile::ImageEngines::ImageMagick
- Inherits:
-
Object
- Object
- OcrFile::ImageEngines::ImageMagick
- Defined in:
- lib/ocr-file/image_engines/image_magick.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
TODO: Conversion of image types Rotation and detection of skew.
-
#image ⇒ Object
readonly
TODO: Conversion of image types Rotation and detection of skew.
-
#image_path ⇒ Object
readonly
TODO: Conversion of image types Rotation and detection of skew.
-
#save_file_path ⇒ Object
readonly
TODO: Conversion of image types Rotation and detection of skew.
-
#temp_path ⇒ Object
readonly
TODO: Conversion of image types Rotation and detection of skew.
Instance Method Summary collapse
- #bw ⇒ Object
- #convert! ⇒ Object
- #deskew ⇒ Object
- #despeckle ⇒ Object
- #enhance ⇒ Object
-
#initialize(image_path:, temp_path:, save_file_path:, config:) ⇒ ImageMagick
constructor
A new instance of ImageMagick.
- #norm ⇒ Object
- #remove_shadow ⇒ Object
- #save! ⇒ Object
-
#sharpen ⇒ Object
Most likely not going to be configurable because these are aggressive parameters used to optimised OCR results and not the final results of the PDFs.
Constructor Details
#initialize(image_path:, temp_path:, save_file_path:, config:) ⇒ ImageMagick
Returns a new instance of ImageMagick.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ocr-file/image_engines/image_magick.rb', line 10 def initialize(image_path:, temp_path:, save_file_path:, config:) @image_path = image_path @config = config @save_file_path = save_file_path @temp_path = temp_path # Will be available in the next version of MiniMagick > 4.11.0 # https://github.com/minimagick/minimagick/pull/541 # MiniMagick.configure do |config| # # cli_version graphicsmagick? imagemagick7? imagemagick? version # config.tmpdir = File.join(Dir.tmpdir, @temp_path) # end @image = MiniMagick::Image.open(image_path) end |
Instance Attribute Details
#config ⇒ Object (readonly)
TODO: Conversion of image types Rotation and detection of skew
8 9 10 |
# File 'lib/ocr-file/image_engines/image_magick.rb', line 8 def config @config end |
#image ⇒ Object (readonly)
TODO: Conversion of image types Rotation and detection of skew
8 9 10 |
# File 'lib/ocr-file/image_engines/image_magick.rb', line 8 def image @image end |
#image_path ⇒ Object (readonly)
TODO: Conversion of image types Rotation and detection of skew
8 9 10 |
# File 'lib/ocr-file/image_engines/image_magick.rb', line 8 def image_path @image_path end |
#save_file_path ⇒ Object (readonly)
TODO: Conversion of image types Rotation and detection of skew
8 9 10 |
# File 'lib/ocr-file/image_engines/image_magick.rb', line 8 def save_file_path @save_file_path end |
#temp_path ⇒ Object (readonly)
TODO: Conversion of image types Rotation and detection of skew
8 9 10 |
# File 'lib/ocr-file/image_engines/image_magick.rb', line 8 def temp_path @temp_path end |
Instance Method Details
#bw ⇒ Object
44 45 46 47 |
# File 'lib/ocr-file/image_engines/image_magick.rb', line 44 def bw @image.alpha('off') @image.auto_threshold("otsu") end |
#convert! ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/ocr-file/image_engines/image_magick.rb', line 27 def convert! return @image_path unless @config[:image_preprocess] @config[:effects].each do |effect| self.send(effect.to_sym) end save! end |
#deskew ⇒ Object
71 72 73 |
# File 'lib/ocr-file/image_engines/image_magick.rb', line 71 def deskew @image.deskew('40%') # threshold recommended in the docs end |
#despeckle ⇒ Object
75 76 77 |
# File 'lib/ocr-file/image_engines/image_magick.rb', line 75 def despeckle @image.despeckle end |
#enhance ⇒ Object
49 50 51 |
# File 'lib/ocr-file/image_engines/image_magick.rb', line 49 def enhance @image.enhance end |
#norm ⇒ Object
53 54 55 |
# File 'lib/ocr-file/image_engines/image_magick.rb', line 53 def norm @image.equalize end |
#remove_shadow ⇒ Object
65 66 67 68 69 |
# File 'lib/ocr-file/image_engines/image_magick.rb', line 65 def remove_shadow @image.negate @image.lat("20x20+10\%") @image.negate end |
#save! ⇒ Object
37 38 39 40 |
# File 'lib/ocr-file/image_engines/image_magick.rb', line 37 def save! image.write(@save_file_path) @save_file_path end |
#sharpen ⇒ Object
Most likely not going to be configurable because these are aggressive parameters used to optimised OCR results and not the final results of the PDFs
60 61 62 |
# File 'lib/ocr-file/image_engines/image_magick.rb', line 60 def sharpen @image.sharpen('0x4') # radiusXsigma end |