Log in

View Full Version : Why are the cthresh and mthresh parameters in TFM separate??


Katie Boundary
13th February 2017, 09:46
cthresh = "is this pixel interlaced?"
mthresh = "should this pixel be deinterlaced?"

Seems to me like they should have been one parameter :/

PirateIce
16th February 2017, 05:37
Hey I'm pretty new to this stuff but I think I can answer your question as Im learning TIVTC right now as well.

The documentation is here: http://avisynth.nl/index.php/TIVTC/TFM

cthresh does control the sensitivity if a pixel is seen as "interlaced"/combed, and then if the number of "interlaced" pixels is over the MI setting in one block of a frame, the whole frame is considered as "interlaced." So from this we can get that changing cthresh and the MI number is more about detecting interlaced frames overall and not at all about deciding how to handle those individual pixels, so you would adjust these settings if combed frames were getting through without having to change how you handle the actual deinterlacing at all.

Mthresh is very different.
Mthresh is not a threshold of a combed pixel detection as Cthresh is, Mthresh is just a raw pixel difference between frames, so that right there should explain they are not at all supposed to be the exact same thing.
If you want to see what I mean look at the metrics section, Cthresh is running this check:
d1 = c - b;
d2 = c - d;
if ((d1 > cthresh && d2 > cthresh) || (d1 < -cthresh && d2 < -cthresh))
{
if (abs(a+4*c+e-3*(b+d)) > cthresh*6) it's combed;
}
Unlike Mthresh, just taking the difference and seeing if its over threshold.

Mthresh is only used for motion adaptive deinterlacing (setting PP > 4) so you can change this number without affecting whether or not a frame is detected as needing deinterlacing, instead you are changing how the individual pixels are handled, ie, if they are seen as static or motion, you have already determined the whole frame is interlaced, so now you are just deciding to take certain pixels from the combed frame and certain pixels from the deinterlaced clip, its not a question of combed, its a question of static or not for the motion adaptive deinterlacer.

PirateIce
16th February 2017, 05:45
Definitons are not correct.
cthresh is for interlaced pixel detection, those pixels go over MI number, frame is interlaced.
Mthresh is for the motion detection ONLY for the motion adaptive deinterlacer. So, for an interlaced frame, WITHOUT motion adaptive deinterlacing, all pixels are pulled from the deinterlaced clip, WITH motion adaptive deinterlacing Mthresh determines which pixels are MOVING and therefore should be pulled from the deinterlaced clip.

Cthresh is a number in the combed/"interlaced" frame detection code:
d1 = c - b;
d2 = c - d;
if ((d1 > cthresh && d2 > cthresh) || (d1 < -cthresh && d2 < -cthresh))
{
if (abs(a+4*c+e-3*(b+d)) > cthresh*6) it's combed;
}
Mthresh is the threshhold for simple difference of the pixel between frames to determine if it is static or not.
Hope this helps.

ndjamena
17th February 2017, 09:01
cthresh would be used to detect if a particular area/frame is interlaced, mthresh would be used to detect if a particular pixel is interlaced. Obviously once you've decided an area is interlaced, you can go to town on the pixels... common sense really.

PirateIce
17th February 2017, 09:09
Those parameters are not used in the same kind of equation from what I can tell from http://avisynth.nl/index.php/TIVTC

youre right about cthresh it is the threshold if the pixel is interlaced when placed in the combed/"interlaced" frame detection, by default this one:
d1 = c - b;
d2 = c - d;
if ((d1 > cthresh && d2 > cthresh) || (d1 < -cthresh && d2 < -cthresh))
{
if (abs(a+4*c+e-3*(b+d)) > cthresh*6) it's combed;
}

whereas Mthresh is not "should this pixel be deinterlaced" it is actually just a simple difference between pixels to indicate moving or static, so it is ONLY used by the motion adaptive deinterlacer (PP>4) so its actually "should this (already assumed interlaced) pixel be considered static or moving" to determine HOW the motion adaptive deinterlacer grabs the new pixel, but once again, Mthresh is the difference between pixels, whereas Cthresh is a value in the comb detection above, so they do not need to be the same and you might need to change the sensitivity of Cthresh if a frame is not being detected as interlaced, whereas Mthresh would only be touched to change HOW certain frames are deinterlaced IF you use the motion adaptive deinterlacing.

Katie Boundary
20th February 2017, 09:22
its actually "should this (already assumed interlaced) pixel be considered static or moving" to determine HOW the motion adaptive deinterlacer grabs the new pixel, ... Mthresh would only be touched to change HOW certain frames are deinterlaced

Can you clarify?

PirateIce
23rd February 2017, 22:12
im just reprhasing this part from the tivtc docs
mthresh -

Sets the motion (pixel difference) threshold for deinterlacing when using motion
adaptation (PP > 4). As said, it is simply a pixel difference threshold between
frames... if under mthresh then a pixel is considered static, if over mthresh it is
considered moving.


I'm not well versed on how motion adaptive deinterlacing works but I believe it is deciding to only grab pixels from the deinterlaced clip (aka clip2) if there is motion as the static parts usually dont have as many combing artifacts, so the resultant frame has pixels from clip1 and clip2. Also I'm not sure but I assume there are still fully deinterlaced video sections.