Closed Selur closed 1 year ago
Thanks, the wiki has been corrected.
Thanks for looking into it, I changed my code to:
##### INPAINTING CODE START
mask = core.imwri.Read(["C:/Users/Selur/Desktop/logo.png"])
mask = core.std.BinarizeMask(mask,threshold=16)
mask = core.resize.Bicubic(clip=mask, format=vs.YUV420P8, matrix_s="470bg", range_s="limited", dither_type="error_diffusion")
import cv2
import muvsfunc_numpy as mufnp
import numpy as np
def inpaint_core(img, mask, radius=1, flags=cv2.INPAINT_NS):
return cv2.inpaint(img, mask, inpaintRadius=radius, flags=flags)
inpainting = mufnp.numpy_process([clip, mask], inpaint_core, radius=1, flags=cv2.INPAINT_NS)
clip = core.std.MaskedMerge(clip, inpainting, mask)
##### INPAINTING CODE END
Now, the output is not broken, but now the filter doesn't seem to do anything.
Cu Selur
clip = core.resize.Bicubic(clip, format=vs.RGB24, matrix_in_s="470bg")
mask = core.std.ShufflePlanes(mask, [0], vs.GRAY)
inpainting = mufnp.numpy_process([clip, mask], inpaint_core, radius=1, flags=cv2.INPAINT_NS, input_per_plane=False, output_per_plane=False)
Using:
##### INPAINTING CODE START
# convert clip to RGB
clip = core.resize.Bicubic(clip, format=vs.RGB24, matrix_in_s="470bg")
# build mask
mask = core.imwri.Read(["C:/Users/Selur/Desktop/logo.png"])
mask = core.std.BinarizeMask(mask,threshold=16)
mask = core.resize.Bicubic(clip=mask, format=vs.YUV420P8, matrix_s="470bg", range_s="limited", dither_type="error_diffusion")
mask = core.std.ShufflePlanes(mask, [0], vs.GRAY)
# apply inpainting
import cv2
import muvsfunc_numpy as mufnp
import numpy as np
def inpaint_core(img, mask, radius=1, flags=cv2.INPAINT_NS):
return cv2.inpaint(img, mask, inpaintRadius=radius, flags=flags)
inpainting = mufnp.numpy_process([clip, mask], inpaint_core, radius=1, flags=cv2.INPAINT_NS, input_per_plane=False, output_per_plane=False)
clip = core.std.MaskedMerge(clip, inpainting, mask)
##### INPAINTING CODE END
It does not do anything (aside from converting to RGB).
Seems like something is missing.
Got it!
The
mask = core.resize.Bicubic(clip=mask, format=vs.YUV420P8, matrix_s="470bg", range_s="limited", dither_type="error_diffusion")'
needs to be removed! :)
Using:
##### INPAINTING CODE START
# convert clip to RGB
clip = core.resize.Bicubic(clip, format=vs.RGB24, matrix_in_s="470bg")
# build mask
mask = core.imwri.Read(["C:/Users/Selur/Desktop/logo.png"])
mask = core.std.BinarizeMask(mask,threshold=16)
mask = core.std.ShufflePlanes(mask, [0], vs.GRAY)
# apply inpainting
import cv2
import muvsfunc_numpy as mufnp
import numpy as np
def inpaint_core(img, mask, radius=1, flags=cv2.INPAINT_NS):
return cv2.inpaint(img, mask, inpaintRadius=radius, flags=flags)
inpainting = mufnp.numpy_process([clip, mask], inpaint_core, radius=1, flags=cv2.INPAINT_NS, input_per_plane=False, output_per_plane=False)
clip = core.std.MaskedMerge(clip, inpainting, mask)
##### INPAINTING CODE END
it works:
Related question: Why the clip = core.std.MaskedMerge(clip, inpainting, mask)
call?
Comparing inpainting
with clip = core.std.MaskedMerge(clip, inpainting, mask)
there doesn't seem to be a difference.
Yes, MaskedMerge
could be removed.
Okay, thanks! :)
Now I just need to get it working better. :)
Thanks for the help. :)
Anyway, for your original script, it should be
mask = core.resize.Bicubic(clip=mask, format=vs.YUV420P8, matrix_s="470bg", range_s="limited", dither_type="error_diffusion")
mask = core.std.BinarizeMask(mask,threshold=128)
# and then
# inpainting = mufnp.numpy_process([clip, mask], inpaint_core, radius=1, flags=cv2.INPAINT_NS)
I'm not getting it, using:
##### INPAINTING CODE START
import cv2
import muvsfunc_numpy as mufnp
import numpy as np
def inpaint_core(img, mask, radius=1, flags=cv2.INPAINT_NS):
dst = np.empty_like(img)
cv2.inpaint(img, mask, inpaintRadius=radius, flags=flags)
return dst
mask = core.imwri.Read(["C:/Users/Selur/Desktop/logo.png"])
mask = core.resize.Bicubic(clip=mask, format=vs.YUV420P8, matrix_s="470bg", range_s="limited", dither_type="error_diffusion")
mask = core.std.BinarizeMask(mask,threshold=128)
inpainting = mufnp.numpy_process([clip, mask], inpaint_core, radius=1, flags=cv2.INPAINT_NS)
clip = core.std.MaskedMerge(clip, inpainting, mask)
##### INPAINTING CODE END
in the original script still gives me the color mess.
Same when using the updated inpaint_core:
##### INPAINTING CODE START
import cv2
import muvsfunc_numpy as mufnp
import numpy as np
def inpaint_core(img, mask, radius=1, flags=cv2.INPAINT_NS):
return cv2.inpaint(img, mask, inpaintRadius=radius, flags=flags)
mask = core.imwri.Read(["C:/Users/Selur/Desktop/logo.png"])
mask = core.resize.Bicubic(clip=mask, format=vs.YUV420P8, matrix_s="470bg", range_s="limited", dither_type="error_diffusion")
mask = core.std.BinarizeMask(mask,threshold=128)
inpainting = mufnp.numpy_process([clip, mask], inpaint_core, radius=1, flags=cv2.INPAINT_NS)
clip = core.std.MaskedMerge(clip, inpainting, mask)
##### INPAINTING CODE END
##### INPAINTING CODE START
import cv2
import muvsfunc_numpy as mufnp
import numpy as np
def inpaint_core(img, mask, radius=1, flags=cv2.INPAINT_NS):
return cv2.inpaint(img, mask, inpaintRadius=radius, flags=flags)
mask = core.imwri.Read(["C:/Users/Selur/Desktop/logo.png"])
mask = core.resize.Bicubic(clip=mask, format=vs.YUV420P8, matrix_s="470bg", range_s="limited", dither_type="error_diffusion")
mask = core.std.BinarizeMask(mask,threshold=128)
inpainting = mufnp.numpy_process([clip, mask], inpaint_core, radius=1, flags=cv2.INPAINT_NS)
clip = core.std.MaskedMerge(clip, inpainting, mask)
##### INPAINTING CODE END
That's the same code I posted,...
Then just use the rgb approach.
okay, I'll stick with the RGB variant.
Looking at OpenCV-Python:](https://github.com/WolframRhodium/muvsfunc/wiki/OpenCV-Python-for-VapourSynth) I wanted to try to use the sample from here
to test the inpainting.
Not really knowing what I'm doing, I tried with:
It's not crashing, but the output:
isn't what I was hoping for. From the looks of it, there is some color space issue.
-> Would be nice if someone could post an example with the given clip&logo how to use inpainting. :)
Thanks!