UNPKG

fv

Version:

FormVision is a node.js library for extracting data from scanned forms

11 lines (10 loc) 525 B
// Generated by CoffeeScript 2.3.1 // Remove background with guessed font size. Always returns a color image. module.exports = function(image, fontWidth, fontHeight) { var backgroundMask, foreground; // Computes the background by closing glyphs and convolving. backgroundMask = image.toGray().close(fontWidth, fontHeight).convolve(fontWidth * 1.33, fontHeight * 1.33).invert(); backgroundMask = backgroundMask.add(backgroundMask); foreground = image.toColor().add(backgroundMask.toColor()); return foreground; };