Log in

View Full Version : MaskDetail for VapourSynth


MonoS
15th December 2014, 19:32
I ported MaskDetail by Chibi_Goku to vapoursynth.
https://github.com/MonoS/VS-MaskDetail

The original code can be found here http://recensubshq.forumfree.it/?t=64839203


It was just a function hacked together to use invks/debilinear in openings/endings/anime with 1080 text.
It just does inverse kernel downscale and re-upscale with the same kernel, ideally there should be no differences, if there are it's pretty likely that there was parts with different resolutions.
So, the idea is to calculate does differences, create a "smart" mask, and use it to merge a sharp invks resize (for the upscaled part) with a normal downscale (for the text/credits), keeping the best of both works.

This is useful for upscaled material that you want to downscale to the original resolution using the kernel inversion method, but there are detail at higher resolution in the frame.

Usage

src = core.lsmas.LWLibavSource("")
mask = MonoS.MaskDetail(src, 1280,720)
noalias = core.fmtc.resample(src, 1280,720,kernel="blackmanminlobe", taps=5)
Y = core.fmtc.resample(src, 1280,720,kernel="bilinear", invks=True, invkstaps=4, taps=4, planes=[3,1,1])
masked = core.std.MaskedMerge(Y, noalias, mask)

final = core.std.Splice([ core.std.Trim(Y,0,1000), core.std.trim(masked, 1001,2000),.....])

final.set_output()


I'll try to make a proper readme if someone will be interested [because this function is very specific]

Reel.Deel
15th December 2014, 20:01
I saw this on pastebin yesterday. A proper readme is never a bad thing. Thanks for porting this function :)

Myrsloik
15th December 2014, 20:35
I'm not familiar with the original script so I shall only comment on the python for now.

1. I believe the built in ValueError exception is appropriate here so you don't have to define your own.

2. Why put the function into a class? It just requires more typing to use. I think you should ditch the class completely.

3. In python you usually use None as the default value for arguments. Like this:

def MaskDetail(..., cutoff=None, ...)
...
if cutoff is None:
cutoff = 17990
else:
cutoff = cutoff * 65535/255

MonoS
15th December 2014, 21:22
Thanks Myrsloik for the advice, i've never used python since three days ago and so i don't know how to properly use it.

I'll correct those in my next commit.

If someone can check if i ported it correctly i'll be very grateful :D

Sapo84
16th December 2014, 01:37
This function create a inverse mask of the higher frequencies in a frame.

It wasn't really created with that idea in mind (btw, I'm Chibi).
It probably does a bad job at that.

It was just a function hacked together to use invks/debilinear in openings/endings/anime with 1080 text.
It just does inverse kernel downscale and re-upscale with the same kernel, ideally there should be no differences, if there are it's pretty likely that there was parts with different resolutions.
So, the idea is to calculate does differences, create a "smart" mask, and use it to merge a sharp invks resize (for the upscaled part) with a normal downscale (for the text/credits), keeping the best of both works.

To give an example.
One Off with Blackman resize (blurry)
http://www.cbland.net/hitchhiker/OFblackman5.png

One Off with Debilinear (ugly aliasing on the text)
http://www.cbland.net/hitchhiker/OFnotmasked.png

One Off with masked Debilinear (much better)
http://www.cbland.net/hitchhiker/OFmasked.png


I never really posted that function anywhere because I always felt that a real lowpass filter would be able to produce a much better mask, but:
1) It worked for what I needed
2) There are no easy to use lowpass filter in avisynth
3) I'm lazy

MonoS
16th December 2014, 19:55
Hi Sapo/Chibi, i edited my first post with your explanation.

I never understood what the script exactly did, so not finding you on IRC i thought a bit and wrote that "higher frequency" thing, we are both lazy :D

--------------
Also DarkSpace made some fix to my version, his/her change was already pulled to my repo.
He/She got rid of the 8/16 bit limitation and used a better syntax