This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

[HELP] about grain
#1
Hello, I really like this grain effect made with Avisynth and I want to try it in Vaporsynth, but no matter what I do, I can't add the grain. Does anyone have any ideas?
[Image: XmkFWWGNUaNd]
video = FFmpegSource2("C:\Users\gzr\Downloads\Video\asd.mp4")
video = video.ConvertBits(8).ConvertToYV12()
white_mask = mt_binarize(video, 200).mt_expand().mt_expand().mt_expand().mt_expand().mt_expand().mt_expand().mt_expand().mt_expand().mt_expand().mt_expand().mt_expand()
grain_video = GrainFactory3(video)
sharpened_video = LSFMod(grain_video, strength=255)
result = mt_merge(video, sharpened_video, white_mask)
return result
and as you can see, it looks bad. can i make it look better and ensure that it only applies grain to the white color?
Reply
#2
Avisynth:
video = FFmpegSource2("C:\Users\gzr\Downloads\Video\asd.mp4")
video = video.ConvertBits(8).ConvertToYV12()
white_mask = mt_binarize(video, 200).mt_expand().mt_expand().mt_expand().mt_expand().mt_expand().mt_expand().mt_expand().mt_expand().mt_expand().mt_expand().mt_expand()
grain_video = GrainFactory3(video)
sharpened_video = LSFMod(grain_video, strength=255)
result = mt_merge(video, sharpened_video, white_mask)
return result
Vapoursynth:
(assuming you import or autoload everything you need)
video = core.ffms2.Source(source=r"C:\Users\gzr\Downloads\Video\asd.mp4")
video = core.resize.Bicubic(clip=video, format=vs.YUV420P8, range_s="limited")
white_mask = video
white_mask = core.resize.Bicubic(clip=white_mask, format=vs.GRAY8, range_s="limited")
white_mask = core.std.BinarizeMask(white_mask, 200)
for i in range(11):
  white_mask = white_mask.stdMaximum(white_mask)
grain_video = havsfunc.GrainFactory3(clp=video)
sharpened_video = havsfunc.LSFmod(input=grain_video, strength=255)
result = core.std.MaskedMerge(video, sharpened_video, white_mask)
result.set_output()

Cu Selur

Ps.: don't see any image,..
Reply
#3
Yes, it worked after a bit of effort. Smile I'd like to add one more thing briefly: How do I apply grain to just a single color code? For example, if the color code is RGB 255, how can I apply the grain only to 255? Also, the current script is causing the grain to extend beyond the white areas, which looks bad. Do you have any suggestions for this? Thank you in advance.
Please see the attached example.
https://prnt.sc/B1NAQL8ST9WT
Reply
#4
Quote:Also, the current script is causing the grain to extend beyond the white areas, which looks bad.
Yes, that is what all those
mt_expand().mt_expand().mt_expand().mt_expand().mt_expand().mt_expand().mt_expand().mt_expand().mt_expand().mt_expand().mt_expand()
in Avisynth and:
for i in range(11):
  white_mask = white_mask.stdMaximum(white_mask)
in Vapoursynth will do. Smile
=> remove those parts if that is not what you wanted.

For a specific color mask, use: https://github.com/Beatrice-Raws/VapourSynth-TColorMask instead of BinarizeMask with a threshold.

Cu Selur
Reply
#5
(14.06.2024, 22:18)Selur Wrote: For a specific color mask, use: https://github.com/Beatrice-Raws/VapourSynth-TColorMask instead of BinarizeMask with a threshold.
It seems there might be a version compatibility issue causing it to not work, I'm using the R68.
import vapoursynth as vs
import havsfunc as haf
import TColorMask as tcm
core = vs.core
video = core.ffms2.Source(source=r"C:\Users\gzr\Downloads\asd.mkv")
video = core.resize.Bicubic(clip=video, format=vs.YUV420P8, range_s="limited")
white_mask = tcm.TColorMask(video, colorYUV=(235, 128, 128), threshYUV=(10, 50, 50), show=True)
for i in range(5):
    white_mask = core.std.Maximum(clip=white_mask)
grain_video = haf.GrainFactory3(clp=video, g1str=20, g2str=20, g3str=20)
sharpened_video = haf.LSFmod(input=grain_video, strength=200, Smode=3, Lmode=1, soft=30, edgemode=1)
result = core.std.MaskedMerge(clipa=video, clipb=sharpened_video, mask=white_mask)
result.set_output()
Failed to evaluate the script:
Python exception: No module named 'TColorMask'
Traceback (most recent call last):
File "src\\cython\\vapoursynth.pyx", line 3365, in vapoursynth._vpy_evaluate
File "src\\cython\\vapoursynth.pyx", line 3366, in vapoursynth._vpy_evaluate
File "C:\Users\gzr\Desktop\Avisynth stuff\a\2.vpy", line 3, in
ModuleNotFoundError: No module named 'TColorMask'
Reply
#6
You need to download https://github.com/Beatrice-Raws/VapourS...k/releases and put the dll into your plugins folder, then instead of tcm.TColorMask you use core.tcm.TColorMask.

Cu Selur
Reply
#7
(14.06.2024, 23:41)Selur Wrote: You need to download https://github.com/Beatrice-Raws/VapourS...k/releases and put the dll into your plugins folder, then instead of tcm.TColorMask you use core.tcm.TColorMask.

Cu Selur

Thanks! Looks awesome  [Image: biggrin.png]
https://prnt.sc/86ocu7FHPjOp
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)