Log in

View Full Version : Nagao filter


lindewell
24th June 2007, 11:45
Anyone knows if the Nagao filter which uses Symmetric Nearest Neighbors method exists for avisynth or any similar filter.
It removes noise but keep edges.

wonkey_monkey
24th June 2007, 17:23
The most I can easily discover about this filter is:

Calculate the variance of 9 sub-windows within a 5 x 5 moving window
Output pixel is the mean of the sub-window with the lowest variance


It sounds easy to code... do you have a link to any before/after samples?

David

lindewell
24th June 2007, 20:25
There is Lena :

http://www.lrde.epita.fr/~palma_g/olena/html/lena256_pgm.png

http://www.lrde.epita.fr/~palma_g/olena/html/oln_convol_nagao_256.png

Didée
24th June 2007, 21:28
Well ... it removes noise, but what is it good for?

Just for fun:

minblur(1) # MinBlur is included in MCBob
limitedsharpenfaster(ss_x=1.0,strength=1000,smode=1,radius=2,overshoot=0)

http://img131.imageshack.us/img131/5313/minblurlsfkf3.png (http://imageshack.us)

Not exactly the same, but quite similar characteristics. Median filters look like median filters do look ...

lindewell
24th June 2007, 21:48
Thanks, the results are pretty good.

McBob is not a plugin, how do I use this user defined function, sorry i'm noob at avs.

Didée
24th June 2007, 23:03
Ah ... from scratch:

Save as LimitedSharpenFaster.avs (http://avisynth.org/mediawiki/upload/2/2d/LimitedSharpenFaster.avs)

Save as MinBlur.avs: function MinBlur(clip clp, int r, int "uv")
{
uv = default(uv,3)
uv2 = (uv==2) ? 1 : uv
rg4 = (uv==3) ? 4 : -1
rg11 = (uv==3) ? 11 : -1
rg20 = (uv==3) ? 20 : -1
medf = (uv==3) ? 1 : -200

RG11D = (r==1) ? mt_makediff(clp,clp.removegrain(11,rg11),U=uv2,V=uv2)
\ : (r==2) ? mt_makediff(clp,clp.removegrain(11,rg11).removegrain(20,rg20),U=uv2,V=uv2)
\ : mt_makediff(clp,clp.removegrain(11,rg11).removegrain(20,rg20).removegrain(20,rg20),U=uv2,V=uv2)
RG4D = (r==1) ? mt_makediff(clp,clp.removegrain(4,rg4),U=uv2,V=uv2)
\ : (r==2) ? mt_makediff(clp,clp.medianblur(2,2*medf,2*medf),U=uv2,V=uv2)
\ : mt_makediff(clp,clp.medianblur(3,3*medf,3*medf),U=uv2,V=uv2)
DD = mt_lutxy(RG11D,RG4D,"x 128 - y 128 - * 0 < 128 x 128 - abs y 128 - abs < x y ? ?",U=uv2,V=uv2)
clp.mt_makediff(DD,U=uv,V=uv)
return(last)
}

Get the noted Plugins (i.e. save the corresponding DLLs from the archives), and use

LoadPlugin("path\to\RemoveGrain.dll") # http://home.arcor.de/kassandro/RemoveGrain/RemoveGrain.rar
LoadPlugin("path\to\mt_masktools.dll") # http://manao4.free.fr/masktools-v2.0a30.zip
LoadPlugin("path\to\MedianBlur.dll") # http://avisynth.org/warpenterprises/files/medianblur_25_dll_20050119.zip
LoadPlugin("path\to\WarpSharp.dll") # http://avisynth.org/warpenterprises/files/warpsharppackage_25_dll_20031103.zip

Import("path\to\MinBlur.avs")
Import("path\to\LimitedSharpenFaster.avs")

xyzSource("YourSource.ext")

MinBlur(1)
LimitedSharpenFaster(ss_x=1.0,strength=1000,smode=1,radius=2,overshoot=0)

Still I wonder, do you have a special reasoning for using something like what we see in the posted pictures? If the task is to remove noise while maintaining good image quality, then this is a rather poor strategy ... other noise filters do the job so much better. (Almost ANY other noise filter.)

lindewell
24th June 2007, 23:35
Thanks for the code, I have no special usage for this, I thought it was a good denoising filter.