Log in

View Full Version : DeFreqChroma4E : DFC4E


TheProfileth
15th February 2011, 01:36
This being my the 4th attempt at trying to make a filter using avisynth, I decided to go with a simple approach and ended up yielding very good results. I would like criticism and feedback and hopefully ways to improve the filter.
Thank you as always for your feedback


#DeFreqChroma4Ever
#version 4E
#Release candidate
#Full working params and everything
#thr and thr2 are the amount that the clips being compared are allowed to change
#blurlevel allows you to change what blur type is being used
#practical values are 11,12,19,20 <- that is ascending order of strength
#strong add a very fast high pass noise remover which helps with compression by a great amount
#only side effect is slight blurring, and maybe some detail loss but usually not
#pref and postf are true false triggers for wether or not to use a pre or post filter
#prefiltering tends to keep the most detail (when sharpening at least) but hurts compression
#params1 goes to prefilter and params2 goes to postfilter correct param input looks like
#prefilter="filtername" and then fill in the parameters with params="what ever they should be"
#only issue is if there are quotes will fix this eventually
#while postfiltering tends to be the best average option which is why I have it on default
#chroma calls nlmeanscl to do some nice chroma filtering for you and then merge that clip in at the end
#if nlmeanscl works for you then you should be fine, otherwise just use a different filter after or before to filter chroma
#
#Credits
#Didee for Flux5frames and Tmedian and SBR and for the original idea that sparked this
#http://forum.doom9.org/showthread.php?p=1127757#post1127757 <-- that
#Nikos for bringing my attention to it
#Thank you Kassandro for making removegrain and removegraint
#Nephilis for the sharpening mode which I modded for compatibility and have called SFM5
#Thank you Torque,Telepathic,Light,Sashamaru,Evilliveshere, Chevy787 and for their support and help testing
#
#
#
#
#Changelog
#Version 4E
#Added parameters to combine all 3 modes
#Added blurlevel
#Added pre and post filter params
#Added chroma toggle
#Added strong mode toggle
#Changed thr so that it can be independently set for the first and second
#Borrowed a sharpening script from MCGRMultiSE, and modded it to work with better compatibility
#great job on that Nephilis
#
#
#
#
#
#Version 4
#Optimized a small amount increased strength
#
#
#
#Version 3
#Safer and more accurate and with different modes, but in separate avsi files
#
#
#
#Version 2
#Faster more accurate and safer
#still more of a blur than anything
#
#
#
#Version 1 was interested in script found on doom9
#Slight modifying
#
#
#
#

function DFC4E(clip, int "thr",int "thr2",bool "strong",bool "chroma",float "blurlevel",bool "PreF", string "prefilter", string "params1"\
,bool "PostF", string "postfilter", string "params2"){
thr = default(thr,4)
thr2 = default(thr2,thr)
blurlevel default( blurlevel, 12 )
PreF = default( PreF , false )
PostF = default( PostF , true )
chroma = default( chroma , true )
strong = default( strong , true )
prefilter= Default(prefilter, "sfm5")
postfilter= Default(postfilter, "sfm5")
c=clip

params1 = Default(params1, prefilter=="sfm5" ? "Sstr=1,Slimit=6" : "")
prefiltered = Eval("c." + prefilter + "(" + params1 + ")")


prefilt = PreF ? prefiltered : c

c2=prefilt
f = c2.removegrain(blurlevel,0)
t = c2.Flux5framesT()
chr = chroma ? c.nlmeanscl(plane=3,h=0.5,hc=0.5,b=1) : c

f1=mt_LutXY(f,t,"x "+string(thr)+" + y < x "+string(thr)+" + x "+string(thr)+" - y > x "+string(thr)+" - y ? ?",U=2,V=2)
f2=temporalrepair(f1,c,mode=1)

params2 = Default(params2, postfilter=="sfm5" ? "Sstr=1,Slimit=6" : "")
postfiltered = Eval("f2." + postfilter + "(" + params2 + ")")


pstfilt = PostF ? postfiltered : f2
str = strong ? pstfilt.sbr : pstfilt.removegrain(1,0)


final=mt_LutXY(c,str,"x "+string(thr)+" + y < x "+string(thr2)+" + x "+string(thr2)+" - y > x "+string(thr2)+" - y ? ?",U=2,V=2)

rep=repair(c,final,mode=18).mergechroma(chr)
return(rep)
}
File and dependencies
http://www.mediafire.com/?o7cktjyx92ods56

Hopefully this time I won't disappoint Didee
(well I can always dream can't I)

Edit: Here are some comparison shots
http://screenshotcomparison.com/comparison/28666
http://screenshotcomparison.com/comparison/28667

Gavino
15th February 2011, 10:45
try {
Prewparams = Eval(prefilter + "(c, " + params1 + ")")
}
catch(err_msg) {
Prewoparams = Eval(prefilter + "(removegrain(0)")
}

prefiltered = (params1=="") ? Prewoparams: Prewparams
There's something wrong with your logic here as (depending on the try) either Prewoparams or Prewparams is undefined, and that is independent of params1 being empty. Also, removegrain is called without a clip and there is an unmatched bracket.
Perhaps what you mean is
try {
prefiltered = Eval(prefilter + "(c, " + params1 + ")")
}
catch(err_msg) {
prefiltered = Eval(prefilter + "(c.removegrain(0))")
# or perhaps just prefiltered = c.removegrain(0) ???
}
Similarly for postfiltering.

Didée
15th February 2011, 13:30
There's something wrong with your logic here

Compare to "HQdering.avs" by mf, dating back to year 2003:

######
##
## HQDering v0.1 by mf
##
## Applies derining by using a smart smoother near edges (where ringing occurs) only.
##
## Usage: Import("HQDering-v0.1.avs")
## HQDering()
##
####

function HQDering(clip input, int "strength", int "overall", string "smoother", string "params") {

strength = Default(strength, 255) # strength, 0-255
overall = Default(overall, 0) # overall smoothing, 0-255
smoother = Default(smoother, "Deen") # filter that smooths
#params = default defined below # filter parameters - use Chr(34) for quotes

defaultnull = Default(params, "")
defaultdeen = Default(params, Chr(34)+"a3d"+Chr(34)+", 4, 15, 15, 20")

params = (smoother=="Deen") ? defaultdeen : defaultnull

try {
smoothedwparams = Eval(smoother + "(input, " + params + ")")
}
catch(err_msg) {
smoothedwoparams = Eval(smoother + "(input)")
}
smoothed = (params=="") ? smoothedwoparams : smoothedwparams

input.EdgeMask(3, 255, 255, 255, "sobel", Y=3, V=1, U=1)
normalmask = last

[ ... ]


Un- or related, for those studying old scripts based on MaskTools-v1:

YV12Layer(clip1,clip2,"mul")

nowaydays is achieved with

mt_lutxy(clip1,clip2,"x y * 255 /")

Gavino
15th February 2011, 14:08
Compare to "HQdering.avs" by mf, dating back to year 2003:
try {
smoothedwparams = Eval(smoother + "(input, " + params + ")")
}
catch(err_msg) {
smoothedwoparams = Eval(smoother + "(input)")
}
smoothed = (params=="") ? smoothedwoparams : smoothedwparams
Ah, I was thinking the purpose of the 'try' (in TheProfileth's code) was to detect invalid parameters being supplied and fall back to some default. It seems from mf's code it is just a clumsy way of handling the case of no parameters. That entire code block could be written simply as:
smoothed = Eval("input."+smoother+"("+params+")")
In TheProfileth's code, it's not clear to me what is the intended result when params is empty, and what clip removegrain(0) is applied to there. The code as posted is clearly wrong as removegrain is called without a clip and there is an unmatched bracket.

TheProfileth
16th February 2011, 00:30
sorry for the delayed response
I only used that because it is the only thing I had on hand that could be used to allow user input parameters and check for invalid parameters, if there is an alternative way to allow that to happen I would be happy to change it.
Besides that issue are there any function abnormalities with the actual performance of this filter that you can find/see?
also let me get those comparisons

Gavino
16th February 2011, 00:59
I only used that because it is the only thing I had on hand that could be used to allow user input parameters and check for invalid parameters, if there is an alternative way to allow that to happen I would be happy to change it.
The thing is, it doesn't work with invalid parameters.
What do you actually want the function to do when params is
a) empty, or
b) invalid for the specified (or defaulted) pre- or post-filter

TheProfileth
16th February 2011, 01:00
The thing is, it doesn't work with invalid parameters.
What do you actually want the function to do when params is
a) empty, or
b) invalid for the specified (or defaulted) pre- or post-filter

alright let me try that, in the mean time here is a nice collection of comparison shots
http://screenshotcomparison.com/comparison/28666
http://screenshotcomparison.com/comparison/28667
Edit:
ok I changed them to empty and took out all the excess removegrain(0), I remeber why I put those in now
(silly me)
During the beginning stage of when I was making the filter I was getting syntax errors so I decided to put removegrain(0) in just to make things a bit easier to keep track of, I forgot to remove them after I was done.
let me update the script
Edit2: alright link updated with newest version

Gavino
16th February 2011, 01:58
defaultnull = Default(params1, "")
defaultsfm5 = Default(params1, "Sstr=1,Slimit=6")

params1 = (prefilter=="sfm5") ? defaultsfm5 : defaultnull

try {
Prewparams = Eval(prefilter + "(c, " + params1 + ")")
}
catch(err_msg) {
Prewoparams = Eval(prefilter + "")
}

prefiltered = (params1=="") ? Prewoparams: Prewparams
That's still not right, as there is no clip being passed to the prefilter in the code in red.
I think you can replace all the code above by:
params1 = Default(params1, prefilter=="sfm5" ? "Sstr=1,Slimit=6" : "")
prefiltered = Eval("c." + prefilter + "(" + params1 + ")")

Similarly for the postfilter code with c, prefilter and params1 replaced by with f2, postfilter and params2.

TheProfileth
16th February 2011, 02:53
alright let me try that

TheProfileth
16th February 2011, 06:29
Alright I changed it and fixed a tiny error that I missed before, should be fine now.

Gavino
16th February 2011, 11:08
should be fine now.
There are still a couple of errors:
prefiltered = (params1=="") ? Prewoparams: Prewparams
That line should have been removed.

prefiltered = Eval("f2." + postfilter + "(" + params2 + ")")
should be assigning to postfiltered.

Since the function doesn't work at all in this form, it looks like you never tested it, or more likely you just screwed up when editing the post.

TheProfileth
17th February 2011, 01:08
There are still a couple of errors:
prefiltered = (params1=="") ? Prewoparams: Prewparams
That line should have been removed.

prefiltered = Eval("f2." + postfilter + "(" + params2 + ")")
should be assigning to postfiltered.

Since the function doesn't work at all in this form, it looks like you never tested it, or more likely you just screwed up when editing the post.
No I have tested it plenty, I think you are right because using the version I have pasted does not work.
BTW
it REQUIRES the dependencies in the mediafire link because it calls like 5 other scripts.
Let me fix those errors that you mentioned and update the download link
btw thanks a lot Gavino for helping with this and giving feedback I really appreciate it.
edit: alright the version I have up works fine now and I have updated the download link
Edi2: I should probably leave chroma off on default as I suppose most people do not have nlmeanscl, still deciding on that, because hopefully people will read the info in the script before they try to run it