pinterf / mvtools

mvtools plugin for avisynth
155 stars 17 forks source link

suggestion: option for internal levels>tv>pc for better motion vectors #40

Closed lextra2 closed 2 years ago

lextra2 commented 3 years ago

Could you add an internal option for this trick I see used in many degrain scripts ColorYUV(Levels="TV->PC") Maybe a bool precise for super, where true is 0-255 colorspace accuracy and false is 16-235.

pinterf commented 3 years ago

What's the science behind it, other than all luma SAD will be multiplied by 255/219?

lextra2 commented 3 years ago

Supposedly up to 16% better motion vectors 219>255=16.438% (increased calculation space)

QTGMC, SMDegrain, TemporalDegrain2 (and probably more) all make use of this. So I figured it must be an improvement.

pinterf commented 3 years ago

If only that would count than you'd simply set thSAD parameter *1,16 and get the same effect. When you simply stretch the original range, you only achieve a multipled SAD between blocks in the algorithm. Luma is a not linear light, there is an exponential conversion from linear light to the 16-235 range (gamma). SAD is Sum of Absolute Differences. SAD of the very same block will be much lower in the dark areas or at the very bright areas. Even if the object is the same, the only difference that it is lit or not. When it's in the mid-range we are fine with it, motion vectors are found for the given SAD. But let the same block be darker or very bright, it won't reach the thSAD limit at all thus the motion vector will not be found.

I know that Luma Rebuild function which all scripts are using and it has a dark area gain parameter which makes sence along with the wider 8 bit PC range.

If only the range would count then going to 16 bit (which is possible) would solve all our problems because it has a calculation space of 56064 even in TV range.

So I need a proof what exactly produces better (on average! At 1920x1080 we can have 32400 motion vectors, each 8x8 block can have one) motion vectors between video frames.

lextra2 commented 3 years ago

Thanks for the nice explanation. And yeah, I've yet to see proof myself of it being an actual improvement. (But based on the logic of being a bigger space to operate in it sounded logical, not anymore though)