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.
This plugin is designed to work with AviSynth 2.5 and is able to process YUY2 and YV12 colorspace clips.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2, as published by the Free Software Foundation in June 1991 (see 'GNUGPLv2.txt').
There is no guaranty that the rights of third parties (including software patents) are not infringed upon by the execution or distribution of this program. Referring to section 8 of the General Public License, any use of this program (including all activities mentioned in section 0 and including execution) is restricted to countries where any of these activities do not infringe upon any such rights of third parties. It lies with the user to verify the compliance of his or her use (especially concerning but not limited to distribution) of this program with the rights of any third parties in the respective countries or regions.
This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License 2 along with this program; if not, write to the
The mathematical formulars in this document require a HTML 4.0 compatible browser to be displayed correctly.
You need the file AVSShock.dll in your working directory. To load the plugin, your script should start with the following line:
LoadCPlugin("AVSShock.dll")
Shock
(clip Clip,
int "Steps",
float "Strength",
bool "Canny",
float "Blur",
int "BlurSize")
Shock
applies the Shock Filter to the clip given.
(2∗BlurSize+1)×(2∗BlurSize+1)
matrix.
(Default: Ceil(2∗Blur)
).
If BlurSize is zero, the blurring step is
completely ommited and computation will be considerably
faster.
This script opens a video file and applies the Shock Filter to sharpen it:
LoadPlugin("AviSynth_C.dll") LoadCPlugin("AVSShock.dll") AVISource("MyMovie.avi") ConvertToYUY2 Shock(3)
This script gives you more control over the sharpening process:
LoadPlugin("AviSynth_C.dll") LoadCPlugin("AVSShock.dll") AVISource("MyMovie.avi") ConvertToYV12 Shock(10,0.3,True,4.0,5)The result will be a more accurate Shock Filter (ten iterations with a step size of 0.3) and the Canny edge detector will be used on a stronger blurred image.
If your clip as already YUY2 or YV12, you can ommit the color space conversion. E.g., this is the case when you load a clip with the well-known DGIndex.dll plugin:
LoadPlugin("DGIndex.dll") LoadPlugin("AviSynth_C.dll") LoadCPlugin("AVSShock.dll") MPEG2Source("AnotherMovie.d2v") Shock(3)
In the following Du denotes the gradient of a gray level image u:R2→R, and D2u its Hessian. The two-dimensional Shock Filter equation for a gray level image u as stated by Osher and Rudin in [OR,(3.1)] reads:
The Laplacian Δu vanishes on edges of the image u (so-called Marr-Hildreth edge-detector). A probably more sophisticated method of edge detection is the Haralick-Canny edge-detector (as proposed in [OR,(3.2d)]). Here the Laplace operator is replaced by the second derivative in the direction of the gradient:
Inspired by [OR,(3.2b)] we can replace u by a convolution with a Gaussian convolution kernel Gs with standard deviation s in both edge-detectors:
The Strength argument is taken into account by using an appropriate convex combination of the original value and the new value of each pixel. Values outside the image (needed by the convolution and the morphological operations) are generated by mirroring the image at the border.
[OR] | Stanley Osher, Leonid Iakov Rudin: Feature-Oriented Image Enhancement Using Shock Filters, SIAM Journal on Numerical Analysis, 27(4), pp. 919-940, 1990. |
2006.12.19 | Initial Version. |
2007.01.04 |
|
2007.01.25 |
|
2007.02.19 |
|
2008.02.23 |
|