Selur's Little Message Board

Full Version: about grain
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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]
Code:
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?
Avisynth:
Code:
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)
Code:
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,..
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
Quote:Also, the current script is causing the grain to extend beyond the white areas, which looks bad.
Yes, that is what all those
Code:
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:
Code:
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
(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.
Code:
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'
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
(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