Giter VIP home page Giter VIP logo

pyinpaint's Introduction

PyInpaint

A lightwieght image inpainting tool written in python. Simple and effective tool to remove scratches, bruises and small holes in images. Could be easily integrated at the backend for Flask or Django apps related to image restoration.

Inpainting is a process of image restoration, the idea is to fill the damage, deteriorated or missing part of an image to present a complete image. It can also be used to remove unwanted parts in an image. Deep learning based approaches use GANs to inpaint. This requires significant amount of training. The proposed tool quickly inpaints by solving a PDE on graphs.

Installation

pip install pyinpaint

Usage

  • Command line
pyinpaint --org_img "path/to/original/image" --mask "path/to/mask"
# pyinpaint --org_img  --mask  --ps --k_boundary --k_search --k_patch

The output is an inpainted image at the path of org_img.

  • Python
from pyinpaint import Inpaint
inpaint = Inpaint(org_img, mask)
inpainted_img = inpaint()
#inpaint = Inpaint(org_img, mask, ps)
#inpainted_img = inpaint(k_boundary, k_search, k_patch)

This returns a numpy array inpainted_img.

Results

image image image

Video demonstration

pyinpaint_demo.mp4

This video shows:

  • How to create an inpainting mask in Gimp.
  • How to inpaint using command line.

How it works?

Basically the inpainting is achieved using harmonic extension on a non-local graph created using image to be inpainted. image

  • f(u) is the signal (rgb values) on the node u.
  • \Delta_{w,p} is the weighted graph p Laplacian.
  • A is the area to be inpainted.
  • dA is the area where signal is given as g(u).

For p=2 the solution to the above equation yields non-local means. image

  • w(u,v) is the weight on the edge from node u to v.
  • N(u) is the set of neighbors of node u.
  • d(u) is the degree at node u.

Params description

The following description of the parameters is useful to gain speed-ups and to inpaint low spatial frequency texture images.

Param Description
ps Patch size, it is used for creating the non-local graph. The default value is 7. To gain speed-up try with 3 or 5. Ideally it should be an odd value. For images with low spatial frequency texture, should be kept high like 11, 13 or 15 ...
k_boundary To determine the nodes at the intersection of A and dA. The default is 4. To gain speed-up try changing to 8 or 16.
k_search Determines the region for searching the non-local neighbors of a node. The default is 1000. For large size images it should be increased. To gain speed-up try with 300, 400, 500.
k_patch The KNN value for the non-local graph construction. The default is 5. Try 3 for speed-up. Try larger value to increase the resolution.

pyinpaint's People

Contributors

agitoz 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.