Log in

View Full Version : New sharpening plugin: Shock Filter


AMSS0815
19th February 2007, 22:05
Hi everybody,

finally I managed to create my first AviSynth plugin. This is the abstract (from the filter docu file):
This Shock Filter sharpens edges of images by applying erosions or dilations depending on the sign of the Laplacian (or the so called Haralick-Canny edge detector).
Common sharpening algorithms often evolve the heat equation backwards (so called Gabor algorithm). This is done by convoluting the image with a mask with negative weights (like AviSynths build-in Sharpen function does). As this method violates a so called maximum principle (values of pixels calculated may be outside the value range of the original image), instabilities arise after some iterations, which can be observed as high oscillations.
This filter uses a morphological approach: In each iterations step, pixels are replaced by one of their neighbors. To avoid sharpening noise, a blurred version of the image is used only for the choice of each neighbor. This way high oscillations can be avoided even on large scales.

Warning: It is likely that this plugin violates U.S. Patent 5.664.513 (http://www.patentstorm.us/patents/5644513.html). As a consequence, any distribution and/or use is prohibited in the U.S. For details see the documentation file coming with the plugin. Any infingement might be prosecuted by the patent holders.
Because of this I don't have the heart to publish this filter in this forum. Instead it is published in the German doom9 forum. I encourage everyone outside the U.S. to go to the Shock filter thread (http://forum.gleitz.info/showthread.php?p=321585#post321585) there and download and try it.

If you have some comments on this plugin (technically or legally), please don't hesitate and post it here - every comment is wellcome!

Here are some problems I came across during the development:
I'm using Kevin Atkinsons great C-Plugin-Interface, and the file AviSynth_C.dll is needed for the plugin to operate. As far as I understand this file isn't needed in newer versions of the C-Interface. When I simply replace AviSynth_C.lib with AviSynth.lib that comes with the latest AviSynth version (and modify the Makefile accordingly), gcc gives me a couple of errors like AVSShock.obj(.text+0x1e):AVSShock.c: undefined reference to `_imp__avs_add_function@20'. Has anyone any experiences in compiling plugins with gcc?
Is malloc/free the correct way to allocate/free memory needed inside the GetFrame function?


I hope publishing in the German forum and discussing in the English forum does not violate any forum rules. I apologize otherwise :o

Best regards,
AMSS

HeadBangeR77
19th February 2007, 23:46
Sh**, if I register to Gleitz, I won't have time left for my real life. :D
Anyway, thanks for the info, at least I am willing to check how it works in practice.

cheers,
HDBR77

Terranigma
20th February 2007, 00:33
thanks for the new sharpening filter. I'll see how this baby does with a few test clips. :sly:

JarrettH
20th February 2007, 06:03
Can't wait to see the results and the 10 pages of discussion to follow :devil:

AMSS0815
20th February 2007, 11:06
Hi,Sh**, if I register to Gleitz, I won't have time left for my real life. :DThat's no problem: You don't have to register to download the file (At least I can download at the moment without logging in and without any cookies :D ).
:thanks: for checking practicability.

AMSS

Mug Funky
20th February 2007, 12:06
interesting results!

it's quite slow though :) i'll be sticking to limitedsharpen or seesaw for now i think.

makes for some nice upsizing. this could be good for the anime buffs out there.

krieger2005
21st February 2007, 23:51
For my taste this simple script work good on upsized real-life content:
i=last
mm2=yv12lutxy(i.expand().blur(.8).expand(),i.inpand.blur(.8).inpand(),yexpr="x y - 2 *")
clean=i.Shock(strength=.4, steps=3).Blur(1.15)
maskedmerge(i,clean,mm2.expand.blur(1.58).expand .levels(32,1.0,strength,0,208,false))

My integration of "Shock" in LimitedSharpen give not that good result like the function above.

Didée
22nd February 2007, 13:25
My integration of "Shock" in LimitedSharpen
What exactly was that - did you just use Shock as the sharpener within LS?
If so, that is (should be) wasted effort: LS is cutting-away the overshoot of a sharpener. But Shock does not overshoot, so why put it into LS?

krieger2005
22nd February 2007, 14:22
What exactly was that - did you just use Shock as the sharpener within LS?
yes.
If so, that is (should be) wasted effort: LS is cutting-away the overshoot of a sharpener. But Shock does not overshoot, so why put it into LS?
Just because of the mask. For natural content Shock is too heavy. But it make clear edges (without haloing). So i want just a function which make good and clear edges without to make a mosaik-image.

BTW: I just noticed the script above does not work as good as i thought... In general the Edges are to sharp for real content. And for Anime also i think. Maybe the add of an "antialiasing" option could give better results (you see in the script above i used blur).

Dreassica
24th February 2007, 19:20
Tried it on some anime content, and i agree with Krieger. It tends to make a mosaic out of the picture quite easy, an antialiasing option may be nice then. Effect does have soem similarities to certain linedarkening methods.

AMSS0815
6th March 2007, 19:42
Hi,

it's quite slow though :)
I'm on learning SSE right now, but it might take some time before I get productive. The code is currently pure C and compiled for i386. Best speed gain is given by switching the pre-blur off (but then noise is enhanced as well):sly:.

It tends to make a mosaic out of the picture quite easy, an antialiasing option may be nice then.
Did I get this right: Mosaic are the staircases on diagonal edges. (That is, what I think, anti-aliasing should avoid ..?) I never implemented an anti-aliasing-algorithm before, I will think about it...

The only way to avoid these staircases I see right now is applying Shock to an upsized image (what reduces speed terribly, of course:():
BilinearResize(2*Width,2*Height).Shock.ReduceBy2

Anyway, thanks for trying - I hope there will be a new version soon.

Regards,
AMSS

MfA
6th March 2007, 19:52
Mosaic means that the image becomes piecewise constant. Blending pixels with their neighbors rather than replacing them entirely might help (known as inverse diffusion).

AMSS0815
23rd February 2008, 16:04
Hi everybody,

I updated AVSShock to version 2008.02.23. Main change is the removal of AviSynth_C.dll. Thanks to Fizick, this file isn't necessary anymore (Plugin is still loaded with LoadCPlugin). Further (minor) changes are listed in the help file. The file is attached to the original post in the german doom9 forum (http://forum.gleitz.info/showpost.php?p=321585&postcount=5).

Please note the possible patent violation described in the original post of this thread.

Have fun,
AMSS

Ignus2
3rd March 2008, 23:38
In case you still need any, I have aplenty of XP with gcc+avisynth_c, I developed all my stuff with that. Works like a charm.

Here is an example I put together some time ago, commented out as best I could: http://forum.doom9.org/showthread.php?p=917740#post917740

--
Greets,
I.

yup
11th March 2008, 08:18
Hi AMSS0815!
Main area for this plugin animation or computer graphics? I try for my analog capture and get very segregating image. May be exist parameter set for different type source parameter set? For my analog capture more satisfied results at step=1, and strength=0.25, increase strength give segregated image.
with kind regards yup.

AMSS0815
21st March 2008, 13:17
Hi yup,Main area for this plugin animation or computer graphics? [...] For my analog capture more satisfied results at step=1, and strength=0.25, increase strength give segregated image.No. I didn't have any special application in mind, just everything which is blurred. Thanks for the feedback! Yes, it's a pretty strong sharpener. Maybe you can restrain it by increasing the Blur option, or changing the Canny option.

Good luck! AMSS

mgh
23rd March 2008, 14:06
which is better-step=5 and strength =0.05
or -step=1 and strength=0.25?
or are they equivalent?

yup
23rd March 2008, 16:03
Hi mgh!
Read documentation. Output this sharpener is solution for partial differential equation. Product strength and step is time distance between initial data and solution, but if step increase also increase solution accuracy, and sharpener quality.
yup.