PDA

View Full Version : MDegrainA - anime script


board123
23rd July 2010, 04:42
I'm a newb to MVTools, so pardon me if I've done something catastrophic here. I'm trying to make a specialized MDegrain script that's going to be used exclusive for HD anime content.

The script I have right now works okay, but I'm looking to speed it up a bit. In particular, I'd like to know if there's anything I can do with the MSuper and MAnalyse parameters to make them better suited for anime content. For example, would decreasing search in MSuper be faster and cause minimal quality drop?

Any improvements (speed or quality) for this script would be greatly appreciated.

function MDegrainA ( clip input, int "radius", int "plane", int "thSAD", bool "preblur", \
int "pel", int "sharp", int "blksize", int "overlap", bool "truemotion", \
int "maxr", int "strength", int "dRad")
{
radius = default( radius, 1 ) # Temporal radius to select MDegrain1/2/3
plane = default( plane, 4 ) # 0=Y, 1=U, 2=V, 3=UV, 4=YUV
thSAD = default( thSAD, 400 ) # Threshold for block SAD
pel = default( pel, 2 ) # Motion estimation accuracy. 1=pixel, 2=half pixel, 4=quarter pixel
sharp = default( sharp, 2 ) # Subpixel interpolation
blksize = default( blksize, 8 ) # MAnalyse block size
overlap = default( overlap, blksize/2 ) # MAnalyse block overlap
tm = default( truemotion,true) # Truemotion
preblur = default( preblur, false ) # Use FFT3DFilter to preblur noisy input
maxr = default( maxr, 3 ) # Temporal radius for TTempSmooth
strength= default( strength, 3 ) # Smoothing strength for TTempSmooth
dRad = default( dRad, 3 ) # Spatial radius for deen

src = preblur ? input.TTempSmooth(maxr=maxr, strength=strength) : input

super = src.MSuper(pel=pel, sharp=sharp)
pb_super = preblur ? src.deen("a2d",mode=dRad).deen("a2d",mode=dRad).MSuper(pel=pel, sharp=sharp) : super

vb3 = (radius >= 3) ? MAnalyse(pb_super, blksize=blksize, isb = true, delta = 3, overlap=overlap, truemotion=tm) : BlankClip()
vb2 = (radius >= 2) ? MAnalyse(pb_super, blksize=blksize, isb = true, delta = 2, overlap=overlap, truemotion=tm) : BlankClip()
vb1 = MAnalyse(pb_super, blksize=blksize, isb = true, delta = 1, overlap=overlap, truemotion=tm)
vf1 = MAnalyse(pb_super, blksize=blksize, isb = false, delta = 1, overlap=overlap, truemotion=tm)
vf2 = (radius >= 2) ? MAnalyse(pb_super, blksize=blksize, isb = false, delta = 2, overlap=overlap, truemotion=tm) : BlankClip()
vf3 = (radius >= 3) ? MAnalyse(pb_super, blksize=blksize, isb = false, delta = 3, overlap=overlap, truemotion=tm) : BlankClip()


output = (radius == 1) ? src.MDegrain1(super, vb1, vf1, thSAD=thSAD, plane=plane)
\ : (radius == 2) ? src.MDegrain2(super, vb1, vf1, vb2, vf2, thSAD=thSAD, plane=plane)
\ : src.MDegrain3(super, vb1, vf1, vb2, vf2, vb3, vf3, thSAD=thSAD, plane=plane)

return output
}

board123
23rd July 2010, 22:06
No one's an expert with MVTools? :(

Didée
23rd July 2010, 23:01
No, no experts around.

I'm trying to make a specialized MDegrain script that's going to be used exclusive for HD anime content.
What is the special property that puts it apart from "any other" MDegrain script?
What's the exclusive requirement of Anime - in respect to MDegrain's operation - opposed to reallife footage?
What's thespecial requirement of HD Anime, opposed to SD Anime?

In other words ... in order to solve a problem, the problem must be known at first. What's the specific problem you are trying to solve, which all of the existing solutions, by you, seem to fail at?
___

What springs to my eye:

preblur = default( preblur, false ) # Use FFT3DFilter to preblur noisy input

src = preblur ? input.TTempSmooth(maxr=maxr, strength=strength) : input

Obviously, FFT3DFilter !=! ttempsmooth


Also, preblur is affecting the source directly, with a temporal filter. Then, for motion search only, you do more smoothing via Deen in spatial mode. That's neither wrong or right (since there is no natural law for that) ... but usually, it is done exactly the other way round. Temporal smoothing for the motionsearch clip (since temporal fluctuations is what can lead MAnalyse to falsely interpret as spatial motion; whereas spatial smoothing is of little to no help in this respect), and eventually some spatial smoothing on the source, kind of a fallback solution for parts where no motion match is found.


All in all, I don't know what to advise. The goal (i.e. the special problem to solve) is not clear, and in your current script I see nothing that would open a way to new horizons.

Keep waiting, by chance some (Anime) expert might come around with better ideas.

board123
23rd July 2010, 23:30
What is the special property that puts it apart from "any other" MDegrain script?
I'd like to hardcode some of the parameters, or set suitable default values, that make it optimized for general anime content. If possible, I'd like to prioritize speed over quality as long as the quality trade-off is small or negligible.


What's the exclusive requirement of Anime - in respect to MDegrain's operation - opposed to reallife footage?
There are less fine details in anime than in real life footage, so one could possibly use more "generous" settings with regards to detail retention. I'm not sure which of the many MSuper/MAnalyse parameters affect detail retention when you pass their vectors over to MDegrain. For example, what exactly is a "hierarchical level" in MSuper?


What's thespecial requirement of HD Anime, opposed to SD Anime?
Spatial parameters. Fine details are not packed as closely in HD content as they are in SD content, so for example, maybe I can increase the radius for deen when I do a preblur.


In other words ... in order to solve a problem, the problem must be known at first. What's the specific problem you are trying to solve, which all of the existing solutions, by you, seem to fail at?

Single pass FFT3DFilter causes banding, so I'm trying to use an alternative denoiser. There is no specific noisy clip I'm trying to fix; I'm simply putting together a general denoiser that I can call whenever I want a motion compensated denoise for anime.

I like MDegrain for the fact that it's intrinsically motion compensated, and the speed/quality is quite good. dfttest w/ motion compensation is pretty good, but it's horribly slow.


preblur = default( preblur, false ) # Use FFT3DFilter to preblur noisy input

src = preblur ? input.TTempSmooth(maxr=maxr, strength=strength) : input

Obviously, FFT3DFilter !=! ttempsmooth
That's a typo. I used to preblur here with FFT3DFilter, but found deen in spatial mode to be both better and faster at smoothing the vector search clip while leaving lines intact. FFT3DFilter, even with sigma>14, still left too much detail, not to mention it's a lot slower than deen.


Also, preblur is affecting the source directly, with a temporal filter. Then, for motion search only, you do more smoothing via Deen in spatial mode. That's neither wrong or right (since there is no natural law for that) ... but usually, it is done exactly the other way round. Temporal smoothing for the motionsearch clip (since temporal fluctuations is what can lead MAnalyse to falsely interpret as spatial motion; whereas spatial smoothing is of little to no help in this respect), and eventually some spatial smoothing on the source, kind of a fallback solution for parts where no motion match is found.
Are you saying spatial smoothing has very little effect on motion search? Even if it rubs out almost all the noise?

What I did to arrive at this preblur solution was to find a noisy clip and apply different filters to it until I found a solution that gives a "flat" image. I thought the goal of preblur was to pass a clip to MSuper/MAnalyse that's as "clean" as possible. Is that not the correct approach?


All in all, I don't know what to advise. The goal (i.e. the special problem to solve) is not clear, and in your current script I see nothing that would open a way to new horizons.
There is no special problem to solve as I'm just trying to find good parameters to use for a relatively standard MDegrain procedure that's optimized for anime content. Think of this as an exercise to find the appropriate defaults for the "anime" setting in MC_Spuds, but using a much simpler filter chain.