Log in

View Full Version : BlindDeHalo() - removal of Edge Enhancement artefacts


Pages : [1] 2

Didée
7th April 2004, 13:04
Hello folks,

once more I did a little scripting, and came up with a procedure that seems quite usable to remove those ugly bright and dark halos from edge enhancement.

One important warning beforehand:

Be careful when using other functions of MaskTools before this script,
or when calling it before iiP() !!!

The MaskTools currently are a little tricky to use - I'll explain this further below.


First, the script:

# BlindDeHalo - v0.1
#
# This script removes the light & dark halos from too strong "Edge Enhancement"
# Adaption of the parameters has to be done manually for each source, the function is not adaptive.
#
# Needed Plugins: MaskTools.dll >= 1.4.15
# undot.dll
#

function BlindDeHalo( clip clp, int "strength", int "radius_x", int "radius_y", float "darkamount", string "mode", float "maskblur", bool "fullframe" )
{
strength = default( strength, 80)
radius_x = default( radius_x, 2)
radius_y = default( radius_y, 2)
darkamount = default( darkamount,1.0)
mode = default( mode, "soft")
maskblur = default( maskblur, 1.0)
fullframe = default( fullframe, false)
modus = mode=="hard" ? "hardlight" : "softlight"

ox = clp.width
oy = clp.height
rx = sqrt(radius_x)
ry = sqrt(radius_y)

clp
edge=Dedgemask(0,255,0,255,"6 10 6 10 -64 10 6 10 6",setdivisor=true,divisor=64).levels(2,0.5,6,0,255,false).undot#.coloryuv(analyze=true)#

blur1 = bicubicresize(int((ox/rx)/4 +.5)*4,int((oy/ry)/4 +.5 )*4,-1.0,1.0).lanczosresize(ox,oy)
blur2 = bicubicresize(int((ox/rx)/4 +.5)*4,int((oy/ry)/4 +.5 )*4, 1.0,0.0).lanczosresize(ox,oy)

diff = YV12subtract(blur1,blur2)

overlay(diff,diff,mode="hardlight").levels(0,1.0,255,88,168,false)

darkamount == 1.0 ? NOP : overlay(last,last.levels(0,1.0,128,int(128-128*darkamount),128,false),mode="lighten")
overlay(last,last.levels(0,1.0,255,128+strength,128-strength,false)) # levels reversed: no more "invert" in below overlay()

overlay(clp,last.greyscale.blur(maskblur),mode=modus)
fullframe ? NOP : MaskedMerge(clp,last,edge.deflate.expand.blur(1.58).inflate,useMMX=true)

return(last)
}
#


The most basic usage is as simple as: BlindDeHalo()

However, there are several parameters to adjust the filtering, and you definetly want to setup those parameters manually for each source.

Basically, the following is what is going on:

- The script does not reckognize any halos in the source! It simply looks for hard edges, and reduces the contrast in their neighborhood.

- A gaussian blurred (well, sort of that) version of the clip is subtracted from a sharpened version. This delivers a mask that is suited for the given purpose.

- Then, the source clip is "Softlighted" by this mask, et voilà ...


Parameter description

strength [int]
The overall strength of contrast reduction around hard edges. Default is 80, usuable range is 0 - 128.

radius_x, radius_y [int] [int]
This is [similar to] the radius of a gaussian blur. These radii must be adjusted to match the "thickness" of the halos in your source. Default is 2, usable range is from 2 to about 5.

Note: A radius of 1 disables the processing in the corresponding direction. E.g. for VHS-caps, setting radius_y=1 and radius_x=3|4|5 should be the right thing. (Didn't test this myself.)

darkamount [float]
With this parameter, the removing of dark halos can be reduced. A value of 1.0 will treat both bright and dark halos equally, 0.5 will process dark halos with only half the strength, 0.0 will disable the processing of dark halos.
Explanation: Theroretically, bright & dark haloing should be always equal. But I encountered some sources where the bright halos seemed to be much stronger than the dark ones, and so I implemented this parameter.
Moreover, generally bright halos are more distracting than dark ones. So it might be a good idea to process the dark ones a little weaker, to retain more overall contrast in the clip.
Default is 1.0 however, as this gives the fastest processing speed ;)

mode [string]
This can be either "soft" or "hard", and simply decides wether to use 'softlight' or 'hardlight' in the final 'overlay()' command.
Default is "soft". You might try "hard" along with some lower values for "strength" - dunno if this may turn out useful somewhere.

maskblur [float]
This simply tells how strong the lightmask will be blurred. Stronger blurring will keep a little more sharpness in the clip, but will reduce the halo removal a little.
Default is 1.0, range is 0.0 - 1.58. Play and see for yourself.

fullframe [bool]
This is mainly a bug-workaround for a specific strangeness in the current MaskTools.
"false" is (or should be) the best setting regarding IQ. But if set to false, the YV12LUT command from MaskTools will work *no more* after calling BlindDeHalo! This is poison for e.g. iiP() ...
Set it to "true" if you need YV12LUT() after calling BlindDeHalo(), or if you're going to use it as pre-processor for iiP. (I will integrate it in the near future into iiP, anyway).


IMHO, this function can be set up to be way more effective against halos than e.g. using unfilter(-,-) -- better removal of halos, less damage to fine details and overall sharpness.

However, my testing so far was not very extensive: Your experiences, suggestions and flames are welcome.

(BTW, this script is *fast*, compared to Didée's usual standard: a 16:9 704*432 frame gets processed at ~10 fps on my XP1800.)

Have fun

- Didée

Zarxrax
7th April 2004, 13:15
Awesome work! I never found unfilter terribly effective against halos, so its very nice to see another option.

DarkNite
8th April 2004, 09:41
Thank you for including the darkamount parameter. That was a really nice touch followed by an all too true explanation.

I look forward to seeing BlindDeHalo's features included in iiP. Not that it wasn't good enough already. :D

Soulhunter
8th April 2004, 21:02
Thx! ;]

Mug Funky
9th April 2004, 10:29
nice stuff. i've got to eat before i fall over (yeah... i use the computer while standing :confused: ), but i will check out on some DV footage, and maybe later with r4 Akira (or did i lend that to someone?) which is very good apart from being obviously sharpened.

digitize
9th April 2004, 17:55
Perhaps this is just me being an idiot, not sure. I have masktools 1.4.2 (b/c i have an athlon xp), yet I get an error because it doesn't recognize Dedgemask, any idea.

Manao
9th April 2004, 22:48
Yep : get the latest version of the masktools :

http://www.geocities.com/manao47/Filters/

digitize
10th April 2004, 13:26
Yep I read the required version incorrectly (read it as 1.4.1.5, rather than 1.4.15) thanks for posting the link.

mf
10th April 2004, 14:11
Decimal versioning is much more logical, just look at mfToon :D.

kilg0r3
10th April 2004, 15:04
I know this a lame question ... How are the speeds compared to an unfiltered encode?

Didée
10th April 2004, 18:24
kilg0r3:

Bad boy, you are ;) -- I could swear to have read this question already before, but a few posts further above ;) /*me waves finger*/

Well, what holds you back from playing 1000 frames once with, once without BlindDeHalo, and compare for yourself?

But okay ... let me put it this way: it's roughly 3.5 times slower than Convolution3D_YV12.

Was that helpful in any way now? :D

You won't expect realtime performance from a script that uses

- 4 resizers
- a subtract operation
- an EdgeMask
- 3~5 different overlay()'s

won't you.

- Didée

DeepDVD
17th August 2004, 02:51
WOW Didée!

Nice work.

In a team with your newest iiP-version (i know, it's not projected to fix animes ;) but it bring me back some details of my old VHS-anime that no filter could do as good before!)

and

mf's Toon-Function (that had force me to seek for a solution for his coronamask-haloing :angry: ... somebody have a try bringing him back on his scratchboard programming out his errors ;))

I get a very good version out of my VHS-Rip-DivX ...

I hope, the preversion of mf's correction ( not a new version :devil: ) will be gold soon... let's hope all together :D


so far

Didée
17th August 2004, 07:49
Originally posted by DeepDVD
the preversion of mf's
Hihi ... I know I should read "pre-version", but somehow I'm forced to read "perversion". Language is a funny thing.

Think of LimitedSharpen() (http://forum.doom9.org/showthread.php?s=&postid=532809#post532809), though. Sometimes, on some sources, I prefer it over iiP, or even use it as pre- or postproc for it (with softer iiP settings). Depends on circumstances, as usual.

- Didée

FlimsyFeet
10th December 2004, 12:32
So... and this is probably a lame question...

Is it better to crank up the sharpness at the source, and capture oversharp, then use BlindDeHalo() to remove the edge enhancement, or is it better to capture a bit softer to begin with then use LimitedSharpen() afterwards?

It's something I plan to test out for myself I just wondered what the opinions of the experts were.

Socio
10th December 2004, 13:54
Awesome Didee!

So I understand the correct use, it would be better to run this after IIP if you are using it but before LimitedSharpen if you using it?

Didée
10th December 2004, 16:00
Ooops ... I found something on my HD:

function BlindDeHalo2( clip clp, float "rx", float "ry", int "strength", bool "interlaced" )
{
rx = default( rx, 3.00 )
ry = default( ry, 3.00 )
strength = default( strength, 125 )
interlaced = default( interlaced, false )

function m4(float x) {return(x<16?16:int(round(x/4.0))*4)}

i = interlaced==false ? clp : clp.separatefields()
oxi=i.width
oyi=i.height
mm2=yv12lutxy(i.expand().blur(.8).expand(),i.inpand.blur(.8).inpand(),yexpr="x y - 2 *")
RR=string((rx+ry)/2.0)
ST=string(float(strength)/100.0)
sm1= i.bicubicresize(m4(oxi/rx),m4(oyi/ry)).bicubicresize(oxi,oyi,1.0,.0)
sm1d=yv12lutxy(i,sm1,yexpr="x y - 18 "+ST+" / "+RR+" / / 128 +")
sm1d=overlay(sm1d,sm1d,mode="hardlight")
clean=yv12lutxy(i,sm1d,yexpr="x y 128 - -").mergechroma(i)
clean1=maskedmerge(i,clean,mm2.expand.blur(1.58).expand .levels(32,1.0,255,0,208,false))
interlaced?clean1.weave():clean1
return last
}


rx,ry [float] - the [assumed] radius at which the EE formerly was done
strength [int] - hmh, I forgot what this is for ;) - but I remember it should be between 0 and 200
interlaced [bool] - either for interlaced sources, or for progressive ones where the EE was applied on a field-basis, not on a frame-basis

A setting of (2.0,2.0,100) will do almost no harm even to a source that doesn't have any EE.
A setting of (3.25,3.25,150) should let vanish even very strong EE that was formerly applied at a radius of 3.

Don't forget the MaskTools v1.5.5 (http://manao4.free.fr/MaskTools-v1.5.5.dll), in case anyone doesn't have them yet ...


Synthetic example:

http://img83.exs.cx/img83/7900/bdhbefore0rp.jpg

http://img83.exs.cx/img83/5599/bdhafter5ev.jpg

http://img83.exs.cx/img83/1403/bdhoriginal0jw.jpg

Socio
10th December 2004, 18:57
Very Cool!

You would simply call it is like this correct?

BlindDeHalo2(2.0,2.0,100)

Going to test this out later today!

Soulhunter
10th December 2004, 19:03
Nice!


Bye

Socio
11th December 2004, 00:19
I tried to test the first one and got a script error;
"MaskedMerge does not have a named argument "Use MMX""

I am using Masktools 1.5.5 so I am not sure what is causing it.

Second version seems to be working, doing a test run now.

Edit: I removed the "useMMX=true" from the first script and it seems to be working, running a test now.

Chainmax
11th December 2004, 00:21
Soulhunter: maybe BlindDeHalo2(3.25,3.25,150) will spare me of having to use exorcist on that crappy video I sent you a while ago :).

Soulhunter
11th December 2004, 14:47
Originally posted by Chainmax

Soulhunter: maybe BlindDeHalo2(3.25,3.25,150) will spare me of having to use exorcist on that crappy video I sent you a while ago :).

Just try it... ;)

Guess it blows all halos away !?!


Bye

dbzgundam
11th December 2004, 21:05
Just... Wow.

It eliminated all the halos on all of my EE'ed discs (That I tested), and even helped TV rips of anime! :eek:

Soulhunter
13th December 2004, 00:33
Yeah, its like... magic !!!
BlindDeHalo2(3,3,200).LimitedSharpen()
http://img32.exs.cx/img32/2658/magic0my.png

Bye

Didée
13th December 2004, 03:30
:) :)


But don't you think that's the story's end: christmas is still to come ... ;)

Wilbert
13th December 2004, 17:20
@Soulhunter,

Such a nice girl :) Why do you blur her so much with the result that you can hardly seen her face anymore?

Kagura
13th December 2004, 20:00
*snickers*

Blurring something so badly that you have to call a sharpener to recover details? That doesn't sound like good filtering. Maybe you should try toning down the strength of dehalo.

Off topic: Limitedsharpen is best as smode = 1

Soulhunter
13th December 2004, 20:27
@ Wilbert

Well, its was only a "remove all the halos" test...

Guess BlindDeHalo2(3,3,150) would be already enough !?!

Take a closer look @ the source, imo it looks already very blurry...

The sharpness is mainly "virtual" and caused by the edge-enhancement !!!

Originally posted by Kagura

Blurring something so badly that you have to call a sharpener to recover details? That doesn't sound like good filtering. Maybe you should try toning down the strength of dehalo.

Nah, this sounds like -> BlindDeHalo2 does the opposite of LimitedSharpen... :sly:

BlindDeHalo2 removes halos, but LimitedSharpen sharpens without producing halos !!!


Bye

Chainmax
13th December 2004, 23:44
Wow, the last picture looks so much more natural than the first one :eek:. Was that really just BDH2 and LS at work? :eek: :eek:

P.S: there is too much smoothing going on though, it's especially noticeable in the necklace (or whatever that thing around her neck is called).

Socio
14th December 2004, 00:03
Soulhunter

You should try that pic again with the fist BlindDeHalo Didee posted I like that one little better does not seem blur or soften near as much.

ObiKenobi
14th December 2004, 01:51
Your new version is quite nice. I use it in conjunction with HQDering, which seems to get rid of some of the dark halos that BlindDeHalo misses, and I get quite nice results.

Source:
http://img72.exs.cx/img72/446/Original.png

HQDering(255) & BlindDeHalo2(2.5,2.5,100)
http://img72.exs.cx/img72/3908/HQDeringBlindDeHalo.png

Soulhunter
14th December 2004, 03:26
@ Wilbert, Kagura, Chainmax, Socio...

Source
http://img96.exs.cx/img96/4816/01source2yr.png

Source + EE
http://img96.exs.cx/img96/5357/01ee9cq.png

Source + EE + BlindDeHalo2
http://img96.exs.cx/img96/9468/01blinddehalo2331409or.png

Bye

Kagura
14th December 2004, 05:32
Now that's more like it. =P

Corran
14th December 2004, 05:37
Except now her eyelids are pink. :P

Soulhunter
14th December 2004, 06:10
Originally posted by Corran

Except now her eyelids are pink. :P

Mainly coz BlindDeHalo2 dont processes the chroma, but the sharpening does... ;)

http://img123.exs.cx/img123/3608/source9zw.pnghttp://img123.exs.cx/img123/8431/sharp0bp.png


Bye

Didée
14th December 2004, 10:25
Soulhunter:

Thanks for holding up :)
Next time I need a varlet to rage against some windmills, I'll call ya ... :D

BTW, poor Jeanette shows _severe_ bad'n ugly oversharpening, and there's not too much left hiding behind the artefacts... Is that an "original" source, or did you add some enhancement manually?


Wilbert, Kagura:

You should give a 2nd thought on the topic. Know the story about the mathematician that inspected the two only barber shops in a small village, found one shop dirty&ugly with the barber's hair terribly dressed, the other shop bright & clean with the barber having his hair in perfect shape, and then went to the ugly shop to get his hair done ... ? ;)

I fully understand your reactions: "Okay, halos might be gone - but it looks so unimpressing afterwards, has so little contrast..." - and IMO that's exactly how it has to be: First remove the "wrong" sharpening, but keep what's behind the artefacts. Then (eventually) go on and make a better enhancement than the original one.

To find a (too short) explanation about what's the actual problem and what's my opinion about it, as well as an example of what BlindDH2 basically is trying to achieve, please look here (http://mf.onthanet.nl/forum/index.php/topic,133.msg1207.html#msg1207) (Morpheus' pictures are the deal).


To convince yourself, make this little experiment:

a = anysource()
b = a.UnsharpMask(127,3,0)
c = b.BlindDeHalo2(3.1,3.1,110) # around these values ... fork a little around
a = a.subtitle("orig")
b = b.subtitle("enhanced")
c = c.subtitle("BlindDeHalo2")

interleave(a,b,c,a)

Soulhunter
14th December 2004, 18:54
Originally posted by Didée

BTW, poor Jeanette shows _severe_ bad'n ugly oversharpening, and there's not too much left hiding behind the artefacts... Is that an "original" source, or did you add some enhancement manually?

I enhanced the halos with some "slight" sharpening !!!

Unfortunately some of my tv channels really look like this... :(

But thats mainly caused by the very bad analog signal I receive !!!


Bye

Kagura
14th December 2004, 19:31
Didée, I wasn't insulting blinddehalo. Rather, I merely thought that Soulhunter used too strong values in reducing halos on his first two pics.

SirCanealot
17th December 2004, 20:17
Has anyone got any suggested settings or advice for using this on anime?
I can get it to remove SOME of the halos, but it does as much damage to random high-contrast parts of the picture as it does EE removal.

Thanks all.

I'll post some screenies and what settings I'm trying if anyone wants - I'm really having little luck with anime and this :/

State of Mind
17th December 2004, 21:41
Can someone give me a direct download link for this filter, please? I wish to test it on some DV footage.

Soulhunter
17th December 2004, 21:55
Originally posted by State of Mind

Can someone give me a direct download link for this filter, please?

Its a function... (http://forum.doom9.org/showthread.php?s=&threadid=74003#post579853) ;)

Save it as avs n' import it in ya scripts !!!


Bye

dvwannab
17th December 2004, 22:09
Originally posted by State of Mind
Can someone give me a direct download link for this filter, please? I wish to test it on some DV footage.

Hi State of Mind!! Glad you took my advice and come over here. These guys are fantastic arent they? This is place to play with, test and learn avisynth. I am gonna be testing this new filter also.
Good luck. To use BlindHalo2, you have to copy the code (link above) and paste into wordpad and save as blindhalo2.avs. Then use import command. Ex.

Loadplugin("C:\avisynth\filters\xxxx.dll")
Import("C:\avisynth\filters\blindhalo2.avs")

Also need MaskTools 1.5.5.

State of Mind
18th December 2004, 02:33
To use BlindHalo2, you have to copy the code (link above) and paste into wordpad and save as blindhalo2.avs. Then use import command. Ex.

What link?

Socio
18th December 2004, 03:43
Originally posted by SirCanealot
Has anyone got any suggested settings or advice for using this on anime?
I can get it to remove SOME of the halos, but it does as much damage to random high-contrast parts of the picture as it does EE removal.

Thanks all.



Try the first BlindDeHalo Didee posted, top page #1 instead of BlindDeHalo2.

ObiKenobi
18th December 2004, 04:48
Originally posted by State of Mind
What link?

Soulhunter's post at the bottom of the first page.

Soulhunter
18th December 2004, 18:35
Originally posted by ObiKenobi

Soulhunter's post at the bottom of the first page.

Bottom of 2nd page... ;)

EDIT: At least with the default "Posts per Thread" settings !!!


Bye

ObiKenobi
18th December 2004, 23:10
Originally posted by Soulhunter
Bottom of 2nd page... ;)


Bye

Well for me it's the first page. :p

Soulhunter
19th December 2004, 00:02
Originally posted by ObiKenobi

Well for me it's the first page. :p

Ok, Ive edited my last post... ;)


Bye

Blue_MiSfit
29th December 2004, 08:40
Awesome script didee! Works extremely well on the film "Human Stain" that displays horrendous edge enhancement haloing.

BlindDeHalo(2,2,100)
Preserves sharpness much better than
UnFilter(-20,-20)

Well done, though it took me awhile to get the proper versions of the BlindDeHalo / MaskTools in order :) Speed isn't bad at all, 6-10fps on my A64 @ 2.34GHz with a 960x480 (lanczos4resized) encode in the firstpass for xvid 1.1.

Very nice :)

~misfit

BlackMetal
21st January 2005, 10:28
Hi, I'm trying to use BlindDeHalo2, but I get the following error:
Script error: there is no function named "overlay"

I've tried with MaskTools 1.5.1, 1.5.5, 1.5.6 and -p4-5.
Does anyone know what's wrong?

Manao
21st January 2005, 10:31
It's not a filter of the masktools, but of avisynth. What is your avisynth version ?