Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > VapourSynth

Reply
 
Thread Tools Search this Thread Display Modes
Old 15th December 2014, 19:32   #1  |  Link
MonoS
Registered User
 
Join Date: Aug 2012
Posts: 203
MaskDetail for VapourSynth

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

Quote:
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
Code:
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]

Last edited by MonoS; 7th July 2018 at 08:13. Reason: Fixed MaskedMerge line
MonoS is offline   Reply With Quote
Old 15th December 2014, 20:01   #2  |  Link
Reel.Deel
Registered User
 
Join Date: Mar 2012
Location: Texas
Posts: 1,669
I saw this on pastebin yesterday. A proper readme is never a bad thing. Thanks for porting this function
Reel.Deel is offline   Reply With Quote
Old 15th December 2014, 20:35   #3  |  Link
Myrsloik
Professional Code Monkey
 
Myrsloik's Avatar
 
Join Date: Jun 2003
Location: Kinnarps Chair
Posts: 2,575
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:

Code:
def MaskDetail(..., cutoff=None, ...)
...
				if cutoff is None:
					cutoff = 17990
				else:
					cutoff = cutoff * 65535/255
__________________
VapourSynth - proving that scripting languages and video processing isn't dead yet
Myrsloik is offline   Reply With Quote
Old 15th December 2014, 21:22   #4  |  Link
MonoS
Registered User
 
Join Date: Aug 2012
Posts: 203
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

Last edited by MonoS; 15th December 2014 at 21:24.
MonoS is offline   Reply With Quote
Old 16th December 2014, 01:37   #5  |  Link
Sapo84
Registered User
 
Join Date: May 2008
Posts: 40
Quote:
Originally Posted by MonoS View Post
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
Sapo84 is offline   Reply With Quote
Old 16th December 2014, 19:55   #6  |  Link
MonoS
Registered User
 
Join Date: Aug 2012
Posts: 203
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

--------------
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
MonoS is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 00:31.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.