Skip to main content
File added late

1 file was added to this release more than 14 days after its initial publication. Inspect the release files before installing.

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.

Release files for magicinpaint-cpu 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

File added late

1 file was uploaded more than 14 days after the first file in this release.

While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.

We recommend inspecting the release files before installing.

Built distributions (wheels)

Table of built distributions (wheels) for magicinpaint-cpu 1.0.2
File
magicinpaint_cpu-1.0.2-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
magicinpaint_cpu-1.0.2-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
magicinpaint_cpu-1.0.2-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
magicinpaint_cpu-1.0.2-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
magicinpaint_cpu-1.0.2-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details
magicinpaint_cpu-1.0.2-cp38-cp38-win_amd64.whl CPython 3.8 CPython 3.8 Windows x86-64 Details
magicinpaint_cpu-1.0.2-cp37-cp37m-win_amd64.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-64 Details
magicinpaint_cpu-1.0.2-cp36-cp36m-win_amd64.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-64 Details

Total release size: 4.2 MB

Release files / magicinpaint_cpu-1.0.2-cp313-cp313-win_amd64.whl

File added late

This file was uploaded more than 14 days after the first file in this release.

While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.

We recommend inspecting the release file before installing.

Download URL magicinpaint_cpu-1.0.2-cp313-cp313-win_amd64.whl
Size 534.6 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
8f3240f4cccbdc0f745fa9af320fb59adb6dc7245890bd318b07cc5c656a5cb4
BLAKE2b-256 checksum
How to use checksums
52ab5dcb90ef17c599e2adaa46ce4c23bec1d27cb390f17cdf0bfaca83d91782
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.0

Release files / magicinpaint_cpu-1.0.2-cp312-cp312-win_amd64.whl

Download URL magicinpaint_cpu-1.0.2-cp312-cp312-win_amd64.whl
Size 517.4 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
c1be9b7c5e37401c66492ea561ea36596e9c626d1f672110391f14dfb6db3e13
BLAKE2b-256 checksum
How to use checksums
e29392ce1a4087ff48ae64ca97e60b3b176f9bcb5d62950f972a6a09fa64aca2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release files / magicinpaint_cpu-1.0.2-cp311-cp311-win_amd64.whl

Download URL magicinpaint_cpu-1.0.2-cp311-cp311-win_amd64.whl
Size 517.3 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
a5c327b4e1ff4dcda290d66679b2ae57652a7b8fdce5529c3c54f8b9663863f6
BLAKE2b-256 checksum
How to use checksums
92add3919b2689fd37f058c48d55cda8970d7df5bfb09b1740063373dc5ae404
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release files / magicinpaint_cpu-1.0.2-cp310-cp310-win_amd64.whl

Download URL magicinpaint_cpu-1.0.2-cp310-cp310-win_amd64.whl
Size 517.2 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
2cad981b5f9dbec3d601d557b0e327222125533ac933316b8ba3f51a3d017dd5
BLAKE2b-256 checksum
How to use checksums
269ab2699967876f3daa9ac4fc6d191f6390f2625a96834624d293bf0b6a2c11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release files / magicinpaint_cpu-1.0.2-cp39-cp39-win_amd64.whl

Download URL magicinpaint_cpu-1.0.2-cp39-cp39-win_amd64.whl
Size 517.4 kB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
17bbfb515b23123e2d5222874bfa2fe3bdf9af1dd911b02c8fa2d8bc24a630cc
BLAKE2b-256 checksum
How to use checksums
6c0321328e07a8f3f3ccac95416381cfca1d1e72427bd69de43d833a4898c2f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release files / magicinpaint_cpu-1.0.2-cp38-cp38-win_amd64.whl

Download URL magicinpaint_cpu-1.0.2-cp38-cp38-win_amd64.whl
Size 517.2 kB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
adc443689d766ed910d1de58592a6664b779ef0d32092b091306cc9ad8573e8c
BLAKE2b-256 checksum
How to use checksums
4a79c3793f498359d4852699a6b693be0d11bf3e76aab2ab284d8197adcbb62b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release files / magicinpaint_cpu-1.0.2-cp37-cp37m-win_amd64.whl

Download URL magicinpaint_cpu-1.0.2-cp37-cp37m-win_amd64.whl
Size 518.3 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
8048d480edb06b31ec166900741ef2806dca765fda6e501d26e3213e78c2ea5c
BLAKE2b-256 checksum
How to use checksums
42c2242ee2046baa39c75da233d86100df0af7c045e736907a176bd5259deb55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release files / magicinpaint_cpu-1.0.2-cp36-cp36m-win_amd64.whl

Download URL magicinpaint_cpu-1.0.2-cp36-cp36m-win_amd64.whl
Size 518.2 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
a6b6b0e2d6baa0bc383341fa4b092b1a399aba8bdde20fb84c98194c07be4f47
BLAKE2b-256 checksum
How to use checksums
068cdff171940698b49a79a1720f00aa3888853c7fc7ad468e655abb7ab2a5b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release history Release notifications | RSS feed

This release

1.0.2 This release

8 release files

1.0.1

7 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page