Skip to main content

Image Inpaint Library

Project description

Introduction

MagicInpaint is image processing Python library for high quality image reconstruction and inpaint. It is available for the GPU and CPU. There is also and image processing tool using the library available here - https://github.com/antonmilev/MagicInpainter.

To install MagicInpaint for GPU:

pip install magicinpaint-gpu

To test if MagicInpaint is installed:

import magicinpaint as mi
mi.version()

Normally, this should print the version and the application type:

MagicInpaint 1.01 (gpu)

To install MagicInpaint for CPU:

pip install magicinpaint-cpu

:warning:Please Note:
For the GPU version to work you need to have NVIDIA GPU card and correctly installed CUDA driver (GTX or RTX)!

Inpaint with MagicInpaint

To use MagicInpaint for image files with cv2:

import numpy as np
import magicinpaint as mi
import os,sys
import cv2

# check magicinpaint version
print(mi.version())

img_path = '08_beach1.jpg'
mask_path = '08_beach1_mask.png'
out_path = '08_beach1_inpaint.png'

img = cv2.imread(img_path)
if img is None:
    print('Can not open image:', img_path)
    exit() 

mask = cv2.imread(mask_path, cv2.IMREAD_GRAYSCALE)
if mask is None:
    print('Can not open mask:', mask_path)
    exit() 

mi.inpaint(img, mask, 15, mi.InpaintGPUfast, verbose = True) 

cv2.imshow('dst', img)
cv2.imwrite(out_path, img)
cv2.waitKey(0)
cv2.destroyAllWindows()

Output:

Noise Pixels:       20221
Image Pixels:       495650
Radius:             15
Inpaint Method:     GPU Fast
TFLOPS:             28.8950
Starting Inpaint.....
Press ESC to cancel
----10%----20%----30%----40%----50%----60%----70%----80%----90%----100%
Inpainting Completed
Inpaint time:       21375.00 ms
Saving output image....

Use without OpenCV:

There is also a method that allows to process image files directly (supported image extensions are JPG,BMP,PNG):

import magicinpaint as mi

# check magicinpaint version
print(mi.version())

img_path = 'test/cloth1_red1.png'
mask_path = 'test/cloth1_mask.png'
out_path = 'results_mi/cloth1_inpaint_mi_GPUfast_r10.png'

mi.inpaint_file(img_path, mask_path, out_path, 30, mi.InpaintGPUfast, verbose = True) 

Desription of the function arguments:

  • image_file - path to color image file, supported formats JPG,BMP,PNG
  • mask_file - path to mask black-white image file, 0-valid pixels, 255- noise pixels to remove
  • out_path - path to output image file, if None result is saved in image file with appended string "onpaint"
  • rad - inpaint radius, limited to 64
  • method - inpaint method, see below
  • verbose - print details, by default is False

Function outputs True if sucessful, otherwise False. The smae

Inpaint with OpenCV

To use OpenCV inpaint see https://docs.opencv.org/3.4/df/d3d/tutorial_py_inpainting.html:

Inpaint with cv2.INPAINT_NS:

import numpy as np
import cv2 

img_path = 'test/08_beach1.png'
mask_path = 'test/08_beach1_mask.png'
out_path = 'results_cv2/08_beach1_inpaint_cv2_NS_r30.png'

img = cv2.imread(img_path)

if img is None:
    print('can not open image:', img_path)
    exit() 

mask = cv2.imread(mask_path, cv2.IMREAD_GRAYSCALE)
dst = cv2.inpaint(img,mask,30,cv2.INPAINT_NS)
cv2.imshow('dst', dst)
cv2.imwrite(out_path, dst)
cv2.waitKey(0)
cv2.destroyAllWindows()

Inpaint with cv2.INPAINT_TELEA:

import numpy as np
import cv2

img_path = 'test/cloth1_red1.png'
mask_path = 'test/cloth1_mask.bmp'
out_path = 'results_cv2/cloth1_inpaint_cv2_Telea_r30.png'

img = cv2.imread(img_path)

if img is None:
    print('can not open image:', img_path)
    exit() 

mask = cv2.imread(mask_path, cv2.IMREAD_GRAYSCALE)
dst = cv2.inpaint(img,mask,30,cv2.INPAINT_TELEA)
cv2.imshow('dst', dst)
cv2.imwrite(out_path, dst)
cv2.waitKey(0)
cv2.destroyAllWindows()

OpenCV inpaint methods are faster but works well only for small scratches and line defects.

Inpaint methods

Following MagicInpaint methods are available:

  • InpaintCPU - this is the default inpaint method if GPU with CUDA is missing. Results can be worse and this method would be too slow so is not recommended for images with high resolution and large noise area.

  • InpaintGPU - this is the most precise GPU method, however for high resolution is also too slow

  • InpaintGPUfast - this is the recomended GPU method for real-life photos, results can be very little worse but perfomance can rise more than 500 percents

Limitations

  • Curently the library is avaliable and tested only for Windows and Python versions Python 3.6 - Python 3.12
  • Inpaint radius is limited to 64
  • For very large image resolutions above 4K and large noise area inpaint can be too slow

For more details see: https://github.com/antonmilev/MagicInpainter.

Future Work

In comming releases there would be several improvements:

  • GPU performance - several optimizations are possible for the GPU to work even faster, also search algorithms can be greately improved

  • Images with larger resolution Optimization algorithms used in MagicInpainter 3.0 become sometimes too slow and unstable for images with high resolution (in these cases Zoom In/Out buttons can be used). One other limitation is that inpaint radius can not exceed 64 pixels.

  • Processing several images and video MagicInpainter 3.0 is currently limited to single photos.

  • Use AI and deep learning to speed up algorithms and optimal inpaint radius selection Assist inpaint algorithms with AI for classification, automation of algorithms type and optimal radius size selection. Used here inpaint algorithms can be combined with various neural networks models, especially in the cases when inpaint involves complicated features and big resolution, speed can be also significantly improved.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

magicinpaint_gpu-1.0.2-cp313-cp313-win_amd64.whl (773.4 kB view details)

Uploaded CPython 3.13Windows x86-64

magicinpaint_gpu-1.0.2-cp312-cp312-win_amd64.whl (748.0 kB view details)

Uploaded CPython 3.12Windows x86-64

magicinpaint_gpu-1.0.2-cp311-cp311-win_amd64.whl (748.0 kB view details)

Uploaded CPython 3.11Windows x86-64

magicinpaint_gpu-1.0.2-cp310-cp310-win_amd64.whl (747.9 kB view details)

Uploaded CPython 3.10Windows x86-64

magicinpaint_gpu-1.0.2-cp39-cp39-win_amd64.whl (748.1 kB view details)

Uploaded CPython 3.9Windows x86-64

magicinpaint_gpu-1.0.2-cp38-cp38-win_amd64.whl (747.8 kB view details)

Uploaded CPython 3.8Windows x86-64

magicinpaint_gpu-1.0.2-cp37-cp37m-win_amd64.whl (749.2 kB view details)

Uploaded CPython 3.7mWindows x86-64

magicinpaint_gpu-1.0.2-cp36-cp36m-win_amd64.whl (748.9 kB view details)

Uploaded CPython 3.6mWindows x86-64

File details

Details for the file magicinpaint_gpu-1.0.2-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for magicinpaint_gpu-1.0.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 8c47766720a374f644b9c1d6cf3f550ccf7392ca41019c51902b6837c60c67da
MD5 79a79d71252439e97c079346d3bb66cb
BLAKE2b-256 2c2384be54f082b7b08586715f014b3ce40ce94df62de004daad942c73717ad4

See more details on using hashes here.

File details

Details for the file magicinpaint_gpu-1.0.2-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for magicinpaint_gpu-1.0.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 1acf0f31c6609a8cb1735d0d35665a69e33c3b1b13f4eeb8c242decd5e92c791
MD5 c7c6666d35af45fa9f234eba0a92a80b
BLAKE2b-256 d3fcbd77c7b91c578603e4975d64367d6ccc6303128bca04fda965781475e934

See more details on using hashes here.

File details

Details for the file magicinpaint_gpu-1.0.2-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for magicinpaint_gpu-1.0.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 47b3564fc2e75fe87519bb882022bc5ea4a8d8df56f471b8f2a5ca1ce235a23b
MD5 ee630cbef4b35af6a5747e87aefa0b6d
BLAKE2b-256 010e8329dae96a168cb98c8b6273da846a6ce9a9f7ae0216d7ed828b9aa02645

See more details on using hashes here.

File details

Details for the file magicinpaint_gpu-1.0.2-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for magicinpaint_gpu-1.0.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a1c230142710f0c0995f7dfb0c99c6e90d5b2d240e75253aefaea4fb4825b833
MD5 9422a591199dfb24307d3c370eeeeed2
BLAKE2b-256 02b1d63dce7c625f5c4a80917256083cefb6b01b1e4b670710e4979edd8cefb9

See more details on using hashes here.

File details

Details for the file magicinpaint_gpu-1.0.2-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for magicinpaint_gpu-1.0.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 723f5242c5db302f207b1b86b11f16e47b278f05364cd4560e5faace5d8a0a4f
MD5 7dc10f72b9552781fc87e949b0842a29
BLAKE2b-256 fe6987b350ab674cf140717807611ab2b79a7a3fa806c31f8f53b59eaf03efa2

See more details on using hashes here.

File details

Details for the file magicinpaint_gpu-1.0.2-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for magicinpaint_gpu-1.0.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 a94e1cee3a135020d103a12637cdf035c11bb93ae88423d4e6f610ce5af0cb2b
MD5 15df854f48fc0e2c5ea827704bccb5b6
BLAKE2b-256 26a19543f57fdb45a386b0f22229926831a46e40b476bd4ada055b8056e342a8

See more details on using hashes here.

File details

Details for the file magicinpaint_gpu-1.0.2-cp37-cp37m-win_amd64.whl.

File metadata

File hashes

Hashes for magicinpaint_gpu-1.0.2-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 b7941beabc119563e963905ddd850e547f2b8996eac3be529a142dd39425129f
MD5 520cba352421fe419491e0ccc3891c4c
BLAKE2b-256 a120ea60f92dbd9f9993d57f808bfa8bd70a3ad8174366719caff863cbd7da55

See more details on using hashes here.

File details

Details for the file magicinpaint_gpu-1.0.2-cp36-cp36m-win_amd64.whl.

File metadata

File hashes

Hashes for magicinpaint_gpu-1.0.2-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 ae703c26d38d9aa04f609aca50f14f2111008da3e1364da50271113c2c8714aa
MD5 0390dd429bce5f7783207aa748d3f3ae
BLAKE2b-256 11a9146eca04d3de88b8842d024face8561533c6dc91d2cbe02399fb10b2770c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page