Cdeblend function by MOmonster


---------------
basic
---------------
	Use import("Cdeblend.avs") in your script and load the filters of this package to be 
	able using this functions.

	required:	- mt_masktools

	version number:	- cdeblend 1.0

	changes from v0.5a:	- different handling with clip2 parameter
				- needs filters to run (masktools)
				- new important parameters (dmode, dthresh, mil...)
				- new detection modes
				- new output modes
				- works also with decimate and so on

----------------
Cdeblend
----------------
	Compared with unblend, deblend or removeblend this function can be a little bit slower (depends
	on the used settings), but it is more tweakable and find more blends. This function can replaces
	the blends in different ways, but it use only duplicates of the clear Frames of the source.

	--------
	Usage
	--------
	code:	progressive (bobbed) source

		Cdeblend(dmode=3, thresh=130)

		------
		or:

		ord = last.getparity() ? 1 : 0

		a = tdeint(mode=1)

		c = leakkernelbob(order=ord).crop(8,8,-8,-8).BilinearResize(480,288)	

		Cdeblend(a, clip2=c, dmode=-4)


	parameters:
		dmode:	The most important parameter of Cdeblend is dmode. Its an integer and
			values between -10 and 10 can be useful, depends on the source. 
			There are three different detection algorythm you can choose:
			dmode < 0	-> the fastest blenddetection. Works good for clean
					   sources with many motion
			dmode > 0	-> the new high quality mode. Its a bit slower, but still
					   fast and will give you good results.
			dmode = 0	-> same as dmode > 0, but without the motioninfluence. Its
					   sometimes the best choice for natural sources.
			That higher the absolut value of dmode (abs(dmode)) is setted, that higher
			is the motioninfluence.	For fluid natural sources 1 or 2 (-1,-2) are good values, 
			for bad motion and animes values till 4 or 5 are useful, for 12fps sources you
			can set it just a little bit higher.
			Default: 0

		omode:	Stands for the output mode. There are five different omodes:
			omode 0 ->	The next frame will be duplicated to avoid a blend. ->default
			omode 1 ->	The previous frame is used instead of a blend.
			omode 2 ->	Use the frame with the smaller possibility to be another blend.
			omode 3 ->	Its a special mode for 12fps sources. It will output only the
					frames with a high clearfactor. Can be tweaked with dthresh.
			omode 4 ->	Does nothing with the source. It just subtitle the clearfactor.
					Smaller values mean a higher blendpossibility.
			Read also dthresh, because this parameter influence directly the omode.

		thresh:	From 0 to 99 its the basic blendthresholding (85-99 is not recommed). Higher 
			values means a stronger detection. Values over 99 call a simple special handling.
			If the current frame has a higher blend possibility than the next and the previous
			and the clearfactor difference is higher than thresh/100-1 (for 150->0.5) its
			detected as a blend. Can be useful for norm conversions. Default: 111
		
		dl:	Detectionlimiting. Its only used for dmode >= 0. If a pixeldifference is not higher
			than this integer, it isnt used for the blenddetection. For animes higher values
			(2-4) are useful and for really good sources zero can be used.	Default: 1

		clip2:	Same as tclip from the previous version, except that it isnt necessary anymore
			to set a clip. But of course it is still useful.
			Use a bobber with low threshold for the detection. If the source is noisy or
			you want to speed up things, you can also soften and resize the clip. A smaller
			detection clip can give a small speed up and bilinear resizing soften the artefacts.
			You should general crop a bobbed clip before.

		momo:	For dmode >= 0:
			The point of no motion. Blended pixel differences will be subtracted from this value
			and clear pixel differences will be added. Because the range is 255, 128 is a good value.
			For the simple blendthresholding (thresh 0-99) and for really blocky sources high 
			values arent so good, here you	should set floats between 4-48.
			For dmode < 0:
			Here its used for simple motion thresholding. You have to set it smaller than 10 to
			activate this feature. For framedifferences smaller than nomo there will be no blends
			detected. This is useful because dmode < 0 dont work so good for really small differences.
			Default: 128

		sd:	Its a boolean. It will be only used for dmode > 0 and enables squaredifferencing
			for the motion influence. Its really useful for animes and low motion scenes.
			If you enable this feature, its recommed to use also the mil value.
			Default: false
	
		mil:	Its a parameter from FixBlendIVTC and have sometimes its use.
			Motion-influence-limiting is the meaning of this parameter and it does what it say.
			This way you can limit the motioninfluence to be used only for low motion scenes.
			Useful values can be between 3 and 30. Default this parameter is nearly unused (100).

		dthresh:The last parameter on the list. It enables the possibility two detect two following
			blends. It stands for the percentage of the blendpossibilities. 
			If two following frames has higher values than this percentage of the both around 
			they are both detected as blends.
			For omode 3 it has a special meaning, because there it works the opposite way and
			test for clear frames this way. This can save some 24fps parts.
			Useful values depends on the dmodes (30-80).
			Default: 0 (not used)