GithubHelp home page GithubHelp logo

sketchure's Introduction

Sketchure is an algorithm that takes an image of a sketch taken in poor light conditions and removes light variances on the paper.

On the left are input images taken with a phone and on the right are the images run through the algorithm with default parameters.

Comparison

Algorithm

The algorithm itself is pretty trivial.

  1. Convert image into a color-space that contains luminance values. YUV, YCbCr, YPbYPr, CIELab are all good options here. After comparing different approaches, I got the best results with YCbCr and 8bit precision.
  2. Remove any noise created by the camera; we are assuming that we are in poor light conditions and the cameras are not perfects. For this step I used median filter with 3x3 kernel. Of course something more advanced can be used.
  3. To extract the background we create a copy of the luminance channel and call it base.
  4. Filter base through erode with a kernel size equal to the maximum line widht in pixels. This mostly erases the lines, while preserving the luminance of the paper.
  5. Filter base through blur. During erode it created boxing artifacts, this makes them less visible. It will also smoothen the background tone, since we assume that the paper is not heavily textured.
  6. Calculate the new luminance value with whiteness + (L - B) / (average / whiteness). Where L is the old luminance value, B is the base luminance, average is the average luminance of the base, whiteness is a predefined constant to define the maximum white value.
  7. Optionally desaturate the image.
  8. Convert image back to the original color-space.

There are two reference implementations of the algorithm: cleanup/normalize.go and js/cleanup.js.

There are alternative possibilities to create the base.

By corners: assume that the image is properly cropped and the the lighting transition is smooth. Sample from each corner and interpolate the light values between the four points.

By white points: let the user specify which points are the background image. Sample around those points. Triangulate the points and interpolate between the points.

sketchure's People

Contributors

egonelbre avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.