Log in

View Full Version : Hacking Kerneldeint to output a motion(comb)-mask instead of a deinterlaced video?


scharfis_brain
22nd March 2004, 23:24
Like the Title says.


Is someone able to modify the kerneldeinterlacer of neuron2 in a way, that it puts out only the motionmask it uses internally?

This would greatly help us building our own deinterlacers with AVISynth.

I've already tried the smartdeinterlace-masks prvided via mpeg2dec.dll.
But I ma not satisfied with its quality....

Si
23rd March 2004, 00:28
Have you tried to use the map=true and just filter out the non-highlighted areas?

Haven't done it myself but I'd have thought a script guru like yourself could do it :)

regards
Simon

Si
23rd March 2004, 00:55
source=AVISource("D:\DS9.00.avi")
k=KernelDeInt(source,order=1,sharp=false,twoway=true,map=true)
bw=tweak(k,0,0,coring=false)
map=Levels(bw,234,1,235,16,235,coring=false)
stackhorizontal(source,k,map)
return last


should give you a good start - seems to work with one of my caps but might not work in all situations

regards
Simon

scharfis_brain
23rd March 2004, 01:56
Oh kewl.

Didn't even know that this map-parameter exists.
It wasn't mentioned in the kerneldeint-doc...


Many thanks.
I'll try that!

scharfis_brain
23rd March 2004, 02:15
hrmpf.
shit.

kerneldeint's mask is bad for my purposes...

I was confused, I meant dgbob.
dgbob hasn't a parameter called map.

btw. I've got the map extracted successfully with this sequence:

levels(0,1,255,0,128)
kerneldeint(order=1,map=true)
greyscale()
levels(254,1,255,0,255)

So I want to redefine my question.

Is someone able to modify dgbob putting out inly its comb-mask?

Si
23rd March 2004, 09:28
Very dirty hack before going to work (uncommented what looked like debugging show map lines)

Download it from (right-click as save as)here (http://www.geocities.com/siwalters_uk/swdgbob.txt)

Hope I was lucky :)

regards
Simon

mf
23rd March 2004, 13:06
Yeah, I've isolated KernelDeint's map too, but as it's KernelDeint, it shows the map for 2 frames instead of 1. I've also been interested in DGBob's mask instead, most namely to compare it with my isolated-combs mask, since comparing it to FieldDeint's mask was pretty useless (FieldDeint has old crappy metrics I discovered).

scharfis_brain
23rd March 2004, 14:55
hey, your swdgbob works pretty well, after I found out how to separate the comb mask properly. (the mask is inverted)

now I have to find out how to align this mask to my video.
for now I've not been able to do so. Its always leaving some dots and combs :(

But its just a matter of time to find the correct placement....


btw. I really hate to make functions general-compatible to TFF and BFF.
Its always cracking my brain....

Guest
25th March 2004, 04:17
Originally posted by scharfis_brain
Didn't even know that this map-parameter exists.
It wasn't mentioned in the kerneldeint-doc...
Huh? I see this in the documentation:

map (true/false, default false) This parameter, when set to true, shows the areas that are "moving" as determined by the threshold parameter and which will be kernel-deinterlaced. Use this parameter to assist in tweaking the threshold parameter.

BTW, the source code for dgbob is available for hacking. :D

scharfis_brain
25th March 2004, 15:18
something must be wrong with this mask. It doesn't touch every comb on the video :(

I always get some dots or remaining lines.

Si
25th March 2004, 20:42
Well 2 reasons for that
1. My hack is wrong (quite possible - I just guessed at Don's debuggging code and re-inserted it). I haven't analysed the code in any way to see if this is valid. However, if it is giving most of the motion map then I'm probably right :)

2. Even the motion map master himself can't work miracles:p There will always be pixels that your eyeball will say are in motion, but a filter will decide they are not.

One way of compensating for this might be to blur or dilate (whatever the term is) the map so that it covers a slightly bigger number of pixels. It'll still miss some but you can't win thme all.


regards

Simon
PS I think PFR gives a motion map of sorts - it might be better than Don's (oink oink flap flap :p )

regards

Simon

scharfis_brain
7th April 2004, 12:47
everthing I tested wasn't optimal:

swdgbob.dll
puts out a luma-only motionmask, this means I have to separate the chroma & luma first and then call my mask-extraction 3 times...

simon, can you change the modified dgbob.dll that it:
- puts out a motionmask including the chroma test (very important on blended and very colored sources)
- only returns the mask, no underlaying video.
- mask without stripes

kerneldeint.dll
as stated before, kerneldeints mask seems to be a mix of two following mask, making it unusable for building an own deinterlacer.
can this be fixed?

pfr.dll
your mask seems to be stable on static detail but has large holes on moving objects.
it seems that it doesn't check chroma on movement...

mpeg2dec.dll
this mask has too much enlarged motion-areas, this means sometimes a blocky-effect occurs
it doesn't detect slow moving borders
it has no chroma test

my own masking in AVS
I hate it: slow, affected by every noise and supressed static detail badly affects motion detection
thats why I give up building my own mask in AVS.

mf
8th April 2004, 13:02
Originally posted by scharfis_brain
my own masking in AVS
I hate it: slow, affected by every noise and supressed static detail badly affects motion detection
thats why I give up building my own mask in AVS.
Aw man, now you challenged me. *sigh* I don't like doing this, but it seems I'll have to go make myself a comb mask function.

mf
8th April 2004, 14:00
Here it is.

function CrappyCombMask(clip inputyv12) {

inputyv12.AssumeFrameBased().Unfilter(0, 100)
blargh = last

YV12Subtract(inputyv12, blargh).Greyscale().Deen("a3d", 4, 10, 0, 30)
wsubtracted = last

Levels(0, 1, 127, 0, 255)
test1 = last

wsubtracted
Invert()
Levels(0, 1, 127, 0, 255)
test2 = last

Overlay(test1, test2, mode="darken")
test3 = last

#inputyv12.SeparateFields().EdgeMask(3, 255, 255, 255, "sobel", Y=3, V=1, U=1).Weave().Blur(0, 1).Greyscale().Levels(0, 1, 35, 0, 255) #.Invert()
#fieldedges = last

inputyv12.MotionMask(thY1=0, thY2=255, y=3,u=1,v=1)
Levels(0, 1, 25, 0, 255, false)
GreyScale()
SeparateFields()
septest3 = last
septest3.SelectOdd()
septest4 = last
septest3.SelectEven()
septest5 = last
Overlay(septest4, septest5, mode="lighten")
TomsMoComp(0, -1, 0)
Binarize() #.Invert()
GreyScale()
motion = last

Overlay(test3, motion, mode="Lighten").Invert().Binarize().Greyscale()
SeparateFields()
septest = last
septest.SelectOdd()
septest1 = last
septest.SelectEven()
septest2 = last
Overlay(septest1, septest2, mode="darken")
TomsMoComp(0, -1, 0).Invert()


}

mf, bringing you crappy AVS filters since spring 2003

scharfis_brain
10th April 2004, 15:18
hrmpf... I hate bringing bad news, but:

this mask is unusable for my purposes, too. :(

it is masking too much in temporal.

you should test it on progressive input (with interlaced YV12), too.
then it should give a motionmasked output with this:

crappycombmask()

and should out NO masking

on doubleweave().selectodd().crappycombmask()

and vice versa with phase-shifted-progressive streams.

this is not the case with your mask.

try to compare your mask with that one provided via mpeg2dec.dll

(btw. I need a fullframerate mask, thats why i am mentioning the dblwv.scltodd. - combo)

Dreassica
10th April 2004, 15:34
Theres a rreason why he called the function crappycombmask()
;)

mf
10th April 2004, 15:44
Originally posted by scharfis_brain
and should out NO masking

on doubleweave().selectodd().crappycombmask()
this is not the case with your mask.
Of course it outputs masking, there's interlacing. What else did you expect?

scharfis_brain
10th April 2004, 16:52
did you do some tests on progressive video WITHOUT any combs?
then it should not create a comb-mask on moving parts, but it still does :(

mf
10th April 2004, 16:58
Originally posted by scharfis_brain
did you do some tests on progressive video WITHOUT any combs?
then it should not create a comb-mask on moving parts, but it still does :(
It does, on the edges yeah. It's an inherent flaw of my method. Feel free to find out a way to fix it though ;).

Also, at times, it doesn't catch combing at all. Hence the name "crappy" :D. But at least it isn't bothered by noise.

scharfis_brain
12th April 2004, 11:10
for now, I am using the mpeg2dec.dll comb mask and a helper- mask that is created within avisynth...

but another thing:

I need to manipulate the direction of the onewaykernel of kerneldeint.

if the twoway parameter =true, then kerneldeint creates its interpolation using the previous and next field.

if it is false, it only uses the previous field for building the interpolated data.

but for many sources, I need the interpolation be based on the next field.

a simple

separatefields().reverse().weave().kernelbob().reverse()
did this job (kernel-reversal), but messed up the deinterlacing, because it now also takes the non-combed image-information from the false fields :(

maybe simon could do such kind of hack into kerneldeint?!?

just like changeing the twoway-parameter to:

twoway=0 using both fields.
twoway=-1 using prev. field
twoway=1 using next field

I really need this feature, because this gives a really great quality-increase when doing a field matching...

Si
12th April 2004, 16:17
maybe simon could do such kind of hack into kerneldeint?!

I think we are going from quick map hack to proper feature request for neuron2 :)

regards
Simon

scharfis_brain
12th April 2004, 20:01
yes, I know, but neuron2 seems to be very busy, thus having no time for us :(