View Full Version : Gimp NL Filter as AviSynth Filter?
mjgoeke
5th January 2009, 18:31
I'm playing around with different sharpening filters, and in the past have found the Gimp's NL Filter to be one of the best.
I looked around for an AviSynth filter implementation of it, but haven't seen one yet (and I'm generally pretty good at searching.)
Perhaps someone who knows could point me in the right direction?
Here's some information about Gimp's Non Linear Filter:
http://docs.gimp.org/en/plug-in-nlfilt.html
(I'm primarily interested in the "sharpen" function of it, but the other modes may also prove useful)
A snippet from the above link:
"Derived from the Unix pnmnlfilt program, it joins smoothing, despeckle and sharpen enhancement functions. It works on the whole image, not on the selection.
This is something of a swiss army knife filter. It has 3 distinct operating modes. In all of the modes each pixel in the image is examined and processed according to it and its surrounding pixels values. Rather than using 9 pixels in a 3x3 block, it uses an hexagonal block whose size can be set with the Radius option."
It would appear the source code for the filter is here (on sourceforge)
http://gimp.sourcearchive.com/documentation/2.6.3/nl-filter_8c-source.html
(http://gimp.sourcearchive.com/documentation/2.6.3/nl-filter_8c-source.html)
As for usage (for those with the Gimp) I generally us the edge enhance mode, with the alpha high (think 0.90 to 0.98) and the radius low (think 0.35 to 0.45)
Thanks in advance for your help!
-M
mikeytown2
5th January 2009, 20:57
Interesting, I've never used the NL filter in gimp before. It's grayed out on png's but available on jpg's. For video purposes, I'm guessing this wouldn't be a fast filter; around 10fps on HD source.
Looking at the source (http://www.sfr-fresh.com/unix/misc/gimp-2.6.4.tar.gz:a/gimp-2.6.4/plug-ins/common/nl-filter.c), they haven't split the code from the GUI yet, or at least put in into 2 separate files. Overall it looks a little bit harder to do then the Color Balance (http://forum.doom9.org/showthread.php?t=139361) clone that me and Gavino coded.
mjgoeke, have you ever written a computer program before?
mjgoeke
5th January 2009, 21:16
NL Filter doesn't seem to work on layers with transparency (my guess)
Try flattening the image first.
mjgoeke
5th January 2009, 21:22
Heh, maybe I should read your whole reply before responding...
I'm familiar enough with programming, but being a good programmer, I'm lazy enough to ask the knowledgeable people if someone's already done the footwork (and debugged it - the key part) before I go off on some misdirected adventure ;)
I've never messed with writing AviSynth filters before, so I'd have to get up to speed before I could convert it over faithfully.
(yeah, I'm probably too lazy - never used to be - I just want to get high quality sharpening for realtime playback of Dvds)
-M
Sagekilla
5th January 2009, 21:24
It sounds like nothing more than a glorified convolution filter with a nonstandard sampling grid. I could be wrong though, I only briefly looked through the source code to see if I could get an idea of whats going on.
The real good stuff sounds more like the actual sharpening routines rather than hex vs square grid.
mjgoeke
5th January 2009, 22:01
@Sagekilla - hmm, it appears you're correct - when R = 1 it's not giving me anything over a standard 3x3 sharpen convolution matrix...
Guess this won't help for sharpening after resize then...
Hmm, I am doing some sharpening before resize though... and it's suffering from haloing pretty bad.
I'm primarily impressed with NL Filter's ability to sharpen at the per-pixel (not rescaled) level for images, it seems to do a good job of pulling out details for sharpen radius of < 1.
Maybe I'll go find a simple convo filter, or a avisynth filter writing tutorial and pull this thing over...
So long as I can get it fast enough to use in realtime.
Sagekilla
6th January 2009, 04:47
If you want good sharpening without haloing: LimitedSharpenFaster. It can run at real time I believe, especially if you use ss_x = 1.0.
mjgoeke
6th January 2009, 21:30
I started going down the LimitedSharpen path before, but didn't finish gathering it's prerequisites.
I've gotten them all now (I think). It looks like there are a few undocumented* tricks though, maybe someone could hold my hand through this.
I've downloaded MaskTools 1.5.8 and MaskTools 2.0a36 (the latest) per the dependencies list at wiki page mentioned at bottom of my post.
I've also downloaded WarpSharp 2.5, and RemoveGrain 1.0pre-release.
My intuition tells me I should search each of the archives for dll files and deposit them into my Program Files\AviSynth\Plugins\ folder.
After this, I download LimitedSharpenFaster.avs, rename it with an .avsi extention, and place it in the same folder as the rest of the plugins.
From here, it looks like I should be able to tick the 'AviSynth' check box in ffdShow, and type away (for starters) LimitedSharpenFaster() in the code box area, and watch 'er zip with the defaults.
So long as I stay away from the VMR9 renderer (stick with "Overlay"?), my saturation should stay intact.
I'm not at the system I'm going to test this stuff on, so I'm documenting this here, in case I run into problems (or if someone notices the error of my ways before I go try it).
Anywho, I'll letcha know if anything blows up.
/me is open to suggestions.
Thx,
-M
*undocumented in aviSynth's LimitedSharpen wiki entry
p.s. Found a hand to hold -
http://forum.doom9.org/showthread.php?t=115727
mjgoeke
8th January 2009, 00:52
Ok, I messed around with LimitedSharpenFaster a bit (using primarily the default mode 3, and played with mode 4 a bit too), and it's not quite giving me what I'm looking for...
Comparing it against swScaler sharpen, I'm favoring the swScaler one.
I tried to find the theory behind swScaler's sharpen, but I can't seem to find any info on it.
It looks like it's part of the FFMpeg library, in swscale.c, but from there, I can't make out what technique it's using for sharpening...
If anyone has some background on swscale's sharpen method I'd be very interested.
I'll continue to play with LimitedSharpenFaster (and check out what other people are using for settings on the forums)...
I'm also toying with the idea of converting over the NL filter into an aviSynth script.
If I don't, well, looks like I got OT then, eh?
-M
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.