Log in

View Full Version : Help converting old avisynth function


Katherine1
11th February 2022, 22:31
Hey,
I'm currently working on converting a few scripts to vapoursynth for a few reasons, (more familiar with python, easier to set up environment thanks to AUR, some vapoursynth plugins like VSGAN, etc.), and I've basically got everything ported over except this one function.

This function does a quick and dirty removal of most of the green color gamut. It does this because it's being used on some old video from those first-generation camcorders that would get those bright blobs of color in bright spots of the image. The video in question has bright green blobs. Funny thing is that the color gamut of VHS at that time is so limited that actual greens in the image remain fine while the unnatural greens from that artifact just get desaturated.

Anyway, the issue I've run into with this function is that basically none of the functions it uses exist in vapoursynth. Is there a good way to do this in vapoursynth? Is there a plugin or group of plugins that could accomplish this?

Here is the function:
function removeAllGreen(clip a) {
gmask = Overlay(a.UtoY().invert(), a.VtoY().Invert(), mode="multiply").BilinearResize(a.width, a.height).ColorYUV(off_y=-65).ColorYUV(gain_y=3000)
return Overlay(a, Tweak(a, sat=0.0), mask=gmask) # overlay original with greyscale, only where green
}

Selur
12th February 2022, 12:27
no direct solution, but some hints, that might help:

Overlay is ported in havsfunc (https://github.com/HomeOfVapourSynthEvolution/havsfunc)
Tweak is ported in adjust (https://github.com/dubhater/vapoursynth-adjust)
ColorYUV needs to be converted to some std.Lut call
UToY/VToY/* can be done through std.ShufflePlanes calls


Cu Selur

poisondeathray
12th February 2022, 20:02
It's too bad vapoursynth is less mature than avisynth and missing some common functions

A different approach would be to mask a certain range of the green channel in RGB, using a luma mask such as mwlmask

The results are slightly different , and you won't get the same results from a G channel derived mask - but you can adjust the range, feather the edges (blur the mask) if you need to . (Another useful tool missing is Masktools2)


eg. test source
https://upload.wikimedia.org/wikipedia/commons/thumb/8/8a/Color_circle_%28RGB%29.svg/1024px-Color_circle_%28RGB%29.svg.png

removeAllGreen
https://i.postimg.cc/fy7s88Gm/removeallgreen.png

mwlmask l1 = 180
https://i.postimg.cc/g22pKqNL/mwlmask-180.png

mwlmask l1 = 220
https://i.postimg.cc/vm1dJ8RQ/mwlmask-220.png

AVS

ImageSource("1024px-Color_circle_(RGB).svg.png")
ConvertToPlanarRGB()
ConvertBits(16)
ConvertToYUV444(matrix="rec709")
removeAllGreen


VPY

clip = core.imwri.Read(r'1024px-Color_circle_(RGB).svg.png')
y = core.resize.Bicubic(clip, format=vs.YUV444P10, matrix_s="709")
nosat = adjust.Tweak(y, sat=0, coring=False)
g = core.std.ShufflePlanes(clip, planes=1, colorfamily=vs.GRAY)
gm = mwlmask(g, l1=220, h1=255)
gm = core.fmtc.bitdepth (gm, bits=10, fulls=True, fulld=True)
ov = haf.Overlay(y, nosat, mask=gm)
#ov = core.resize.Bicubic(ov, format=vs.RGB24, matrix_in_s="709")
ov.set_output()