Log in

View Full Version : deringing


grazieee
5th January 2005, 17:23
Hi

Does anyone know how to do deringing? Please let me know of the algorithm and/or the source code.

Thank you very much.

Regards
Kim Hong

Karyudo
5th January 2005, 20:42
Sweet Jesus, are you about to take some flak. Not the most auspicious of first posts....

(Hint: one of the five blue/purple buttons near the top of this screen is labelled "Search". You might try HQDering and/or BlindDeHalo/BlindDeHalo2)

Ark
5th January 2005, 20:46
I would add mpeg2dec3's BlindPP function too...

Soulhunter
6th January 2005, 02:01
And dont forget ffdshow's post processing... ;)


Bye

krieger2005
6th January 2005, 13:08
Maybe you are try this one:
function CleanEdges(clip c, int "dering_luma", int "dering_floor", bool "use_old_chroma", int "sharpen_cycles", int "blur_cycles", int "thin", bool "mask", int "edgeinfluence"){c
EdgeBias = 16
dering_floor= default(dering_floor,13)
dering_luma = default(dering_luma, 78)
use_old_chroma = default(use_old_chroma,true)
mask=default(mask,false)
diff=default(edgeinfluence,22)

faktor=float(c.height)*float(c.width)/400000.0
sharpen_cycles=default(sharpen_cycles,round(faktor*4))
blur_cycles=default(blur_cycles,round(faktor*4))
thin = default(thin,round(faktor*2))

blurr = deen(rad=3, thrY=30, thrUV=40).hqdn3d(60,60,0,0)

u = c.utoy.blur(1.5).blur(1.5).blur(1.5).temporalsoften(2,255,0,3,2).xsharpen(155)
v = c.vtoy.blur(1.5).blur(1.5).blur(1.5).temporalsoften(2,255,0,3,2).xsharpen(155)
y = c.removeGrain(2).deen(thrY=33, thrUV=37, rad=3).xsharpen(35)

clean= ytouv(u, v, y)
\.hqdn3d(9,3,5,2)
\.RemoveDirt(mthreshold=70, pthreshold=2, tolerance=7)
\.removeGrain(2)
\.UnSharpMask(50,1,0)

sharpy=DeRing_getSharp(blurr,sharpen_cycles)
blurry=DeRing_getBlur(blurr,blur_cycles)

edge1a = YV12subtract( sharpy, blurry)
edge1b = yv12subtract( edge1a,
\ edge1a.unsharpMask(120,1,0),tol=1,wideRange=true )
\ .yv12lut(yexpr="x 128 - abs "+string(dering_floor)+" *")
edge1ba = blurr.FineEdge(EdgeBias)
edge1bb = edge1a.FineEdge(EdgeBias).inflate.inflate.inflate.blur(1)
\ .DeRing_ExpandToThin(thin)
\ .greyscale.Ylevels(19,1.6,dering_luma,0,255)
\ .Blur(1.5)
edge1bc = c.FineEdge(EdgeBias+2)

z=edge1bb
z=YV12LUTxy(edge1ba,z,"x "+string(diff)+" > y x 1.5 * - y ?")
z=YV12LUTxy(edge1bc,z,"x "+string(diff)+" > y x 1.1 * - y ?")
z=FitY2UV(z)

use_old_chroma ? mask ? z : maskedmerge( c, clean, z, Y=3,U=1,V=1, useMMX=true ) :
\ mask ? z : maskedmerge( c, clean, z, Y=3,U=3,V=3, useMMX=true )
}

#------------ Different Help functions -----------------------#
function DeRing_getSharp(clip c, int sharp_cycles){
s1= c.sharpen(0.6)
s2=s1.sharpen(0.6)
s3=s2.sharpen(0.6)
s4=s3.sharpen(0.6)
s5=s4.sharpen(0.6)
sharp_cycles <= 5 ? Select(sharp_cycles-1,s1,s2,s3,s4,s5)
\: DeRing_getSharp(s5,sharp_cycles-5)
return last
}

function DeRing_getBlur(clip c, int blur_cycles){
b1= c.Blur(0.6)
b2=b1.Blur(0.6)
b3=b2.Blur(0.6)
b4=b3.Blur(0.6)
b5=b4.Blur(0.6)

blur_cycles <= 5 ? Select(blur_cycles-1,b1,b2,b3,b4,b5)
\: DeRing_getBlur(b5,blur_cycles-5)
return last
}

function DeRing_ExpandToThin(clip c, int thin){
q=c.LanczosResize(m4(5/float(thin)*c.width),
\m4(5/float(thin)*c.height))
q=q.expand()
q=q.LanczosResize(c.width,c.height)
q=Logic(c,q,"max")

thin <= 5 ? q : DeRing_ExpandToThin(q,thin-5)
return last
}


function FineEdge( clip clp, int "div" )
{
logic( clp.DEdgeMask(0,255,0,255,"5 10 5 0 0 0 -5 -10 -5", setdivisor=true, divisor=div)
\ ,clp.DEdgeMask(0,255,0,255,"5 0 -5 10 0 -10 5 0 -5", setdivisor=true, divisor=div), "max", Y=3,U=1,V=1 )
}

Many Code... I use the following call for a very overcompressed movie:
CleanEdges(40,dering_floor=16, mask=false, thin=10)

If you have blendings use "use_old_chroma=false"

* "dering_luma" in the call-sample above set to 40 is "hardness" of the deringing. Lower values let more deringing (use mask=true to see this)
* "thin" is the thin of dering (bluring near by the edge).
* "dering_floor" with higher values find more edges to dering.
* "mask=true" show you the parts, which were deringing

I should say, that this is a modified version of the dering-algorithm of "Didée's" IIP. The "deblending" i stolen ;) from a thread here somewhere (sorry guys) and build it in because use quite the same technique to reduce chroma-artifacts (reduce by edge-masks).

PS: The most usefull variable is "thin". Here is "thin" 10, so very hard. a value of 3-5 should be ok for cleaning. The script is much slower as Didée's BlindDeHalo but can be used on very hard deringing

krieger205

grazieee
6th January 2005, 17:44
Hi all

Thank you so much for your help!
I've searched for HQdering and BlindDeHalo/BlindDeHalo2.. & i've also looked at the code krieger2005 posted. I wonder what language are these codes written in. C++? Are there any Matlab codes?

And are these codes only for video? What about still images?

Thank you so much again. Hope to hear from you all soon!

Good day
grazie

scharfis_brain
6th January 2005, 17:48
I wonder what language are these codes written in. C++? Are there any Matlab codes?

And I wonder, how you got that idea to post in this forum....

Didée
7th January 2005, 02:57
krieger:

1stly ... if you make use of those "m4" and "Ylevels" functions, it wouldn't hurt to also include them in the posted script, would it :)

Looks like a nice function! Too lazy and tired to try it now, I see everything blurry anyways right now. High time to go to bed.
But browsing the script, it looks somewhat slow - could that be?

Some points to hook in:

Most of the sharpen/blur cascades can be done as well by yv12convolution /w bigger kernels. This ~could~ turn out to be faster, must be tryed out. In any case, it would be much *preciser*: the rounding errors produced by blur()-cascades can get nasty - especially "flat" areas may get some annoying banding from chained blurring, and on the sharpening side, the rounding errors won't exactly help, either.
Considerable CPU time seems to get used by DeRing_ExpandToThin(). I know I know, the dreadful expanding/feathering stuff ... :devil: - A dedicated plugin or an ex|inpand modification would be needed. However: since it's "only" producing a mask, wouldn't bicubicresize (or even bilinear?) be good enough, to gain a little speed?

Prettz
7th January 2005, 04:53
Originally posted by grazieee
Hi all

Thank you so much for your help!
I've searched for HQdering and BlindDeHalo/BlindDeHalo2.. & i've also looked at the code krieger2005 posted. I wonder what language are these codes written in. C++? Are there any Matlab codes?

And are these codes only for video? What about still images?

Thank you so much again. Hope to hear from you all soon!

Good day
grazie
I hate to be so blunt, but do you have any idea what AviSynth is? Here's a website you should have looked at before posting in this forum: www.avisynth.org

Socio
7th January 2005, 13:07
krieger2005,

I tried your script but get an error "there is no function named M4"
and not sure how to fix?

Didée
7th January 2005, 14:33
function m4( float x )
{ return( x<16 ? 16 : int(round(x/4.0))*4) }

function Ylevels(clip clp, int a, float gamma, int b, int c, int d)
{ wicked="x "+string(a)+" - "+string(b)+" "+string(a)+" - / 1 "+string(gamma)+" / ^ "+string(d)+" "+string(c)+" - * "+string(c)+" +"
return( clp.YV12LUT(Yexpr = wicked),U=2,V=2 )
}

krieger2005
7th January 2005, 23:45
Originally posted by Didée
krieger:

1stly ... if you make use of those "m4" and "Ylevels" functions, it wouldn't hurt to also include them in the posted script, would it :)


Too many code... not on the same place (in different scripts) which were included automaticly by Avisynth

Originally posted by Didée
But browsing the script, it looks somewhat slow - could that be?


Yes, it could be... but it is now faster than before. But it should be even faster, with some help ;)

Originally posted by Didée
Most of the sharpen/blur cascades can be done as well by yv12convolution /w bigger kernels. This ~could~ turn out to be faster, must be tryed out. In any case, it would be much *preciser*: the rounding errors produced by blur()-cascades can get nasty - especially "flat" areas may get some annoying banding from chained blurring, and on the sharpening side, the rounding errors won't exactly help, either.


You are absolutly right. I thought also about an other way to do this. But my main question is: Is this needable? I mean maybe a simple "blur(1.5)" and "sharpen(1.4)" do the same job... But as you can see in the script: the strength of "blur" and "sharpen" is cought by the resolution of the clip. So that "blur"-strength is not so hard for "low-resolution"-clips. This is for me logical but give it any effect (hopfully somebody understand what i mean)?

Originally posted by Didée
Considerable CPU time seems to get used by DeRing_ExpandToThin(). I know I know, the dreadful expanding/feathering stuff ... :devil: - A dedicated plugin or an ex|inpand modification would be needed. However: since it's "only" producing a mask, wouldn't bicubicresize (or even bilinear?) be good enough, to gain a little speed?
I never thought about another resizer. I use Lanczos by default but your right. And the Expand-Plugin... For this i must a comiler and so on... now i am too lazy but maybe when this script is ok i do it (when no one does it before). But i know from my expirience, that a "erode"-Filter is slow. And a "multi-erode"-Filter is even slower. So i must look at the code of the mask-tools how they done the "expand"-Function... Maybe this help.

Socio
8th January 2005, 16:44
Originally posted by Didée
function m4( float x )
{ return( x<16 ? 16 : int(round(x/4.0))*4) }

function Ylevels(clip clp, int a, float gamma, int b, int c, int d)
{ wicked="x "+string(a)+" - "+string(b)+" "+string(a)+" - / 1 "+string(gamma)+" / ^ "+string(d)+" "+string(c)+" - * "+string(c)+" +"
return( clp.YV12LUT(Yexpr = wicked),U=2,V=2 )
}

Thanks Didee!

Painkiller
11th October 2007, 16:55
I'm getting An error as i tried to use this , Is anyone kind enough to help.

"There is no function named "UnSharpMask""

I guess this should be included in mask tools.

I tried to use search but to no avail.

:confused: