Using PIL to fill empty image space with nearby colors (aka inpainting)

前端 未结 3 1471
一个人的身影
一个人的身影 2021-02-02 02:25

I create an image with PIL:

\"example

I need to fill in the empty space (depicted as black). I coul

相关标签:
3条回答
  • 2021-02-02 02:46

    You can also create the mask with the function CreateImage(), for instance:

    inpaint_mask = cv.CreateImage(cv.GetSize(im), 8, 1)
    
    0 讨论(0)
  • 2021-02-02 02:50

    Depending on how you're deploying this application, another option might be to use the Gimp's python interface to do the image manipulation.

    The doc page I linked to is oriented more towards writing GIMP plugins in python, rather than interacting with a background gimp instance from a python app, but I'm pretty sure that's also possible (it's been a while since I played with the gimp/python interface, I'm a little hazy).

    0 讨论(0)
  • 2021-02-02 03:00

    A method with nice results is the Navier-Stokes Image Restoration. I know OpenCV has it, don't know about PIL.

    Your example:

    enter image description here enter image description here

    I did it with Mathematica.

    Edit

    As per your reuquest, the code is:

    i = Import["http://i.stack.imgur.com/uEPqc.png"];
    Inpaint[i, ColorNegate@Binarize@i, Method -> "NavierStokes"]
    

    The ColorNegate@ ... part creates the replacement mask. The filling is done with just the Inpaint[] command.

    0 讨论(0)
提交回复
热议问题