omicronpersei wrote:
: > First, a Gaussian is a low-pass filter
:
: We create a kernel at a width that starts with a minimum of 3 pixels and
: walk out until we drop below the threshold of one pixel numerical accuracy:
:
: for (width=5; ;)
: {
: normalize=0.0;
: for (v=(-width/2); v <= (width/2); v++)
: {
: for (u=(-width/2); u <= (width/2); u++)
: {
: alpha=exp(-((double) u*u+v*v)/(2.0*sigma*sigma));
: normalize+=alpha/(2.0*MagickPI*sigma*sigma);
: }
: }
: v=width/2;
: value=exp(-((double)
v*v)/(2.0*sigma*sigma))/(MagickSQ2PI*sigma)/normalize;
: if ((long) (QuantumRange*value) <= 0)
: break;
: width+=2;
: }
: width-=2;
:
: Next we compute the kernel as follows:
:
: normalize=0.0;
: for (v=(-((long) width/2)); v <= (long) (width/2); v++)
: {
: for (u=(-((long) width/2)); u <= (long) (width/2); u++)
: {
: alpha=exp(-((double) u*u+v*v)/(2.0*sigma*sigma));
: kernel[i]=(double) (-alpha/(2.0*MagickPI*sigma*sigma));
: if ((width < 3) || (u != 0) || (v != 0))
: normalize+=kernel[i];
: i++;
: }
: }
: kernel[i/2]=(double) ((-2.0)*normalize);
:
: and finally we convolve the kernel over each pixel of the image to generate
To whomever "omicronpersei" is (John C.?) thanks very much for pulling
this from the IM source. I do not follow every detail of the above,
but it appears that what ends up in kernel[] is a normalised, spatially
truncated, negative-going Gaussian with the central coefficient
modified to be a positive going impulse. Thus the convolution
implements something like
y = G*x = (d-g)*x = d*x - g*x = x - g*x
where:
`y' is the sharpened image,
`x' is the input,
`G' is your final kernel,
`d' is a Kronecker "delta" function, i.e. a spike at the
Origin with zero samples elsewhere,
`*' is the convolution operator, and
'g' is a postive going version of the kernel you construct before the
final modification of kernel[i/2].
I.e. `g' would be
kernel[i]=(double) (+alpha/(2.0*MagickPI*sigma*sigma));
Note the change of "-alpha" to "+alpha".
The final expression, x - g*x, is essentially an unsharp mask (neglecting
some scale factors).
I hope my understanding is correct. Please let me know if I've
missed the boat.
Regards,
Dean
Dean S. Messing
Sr. Scientist
Display Algorithms & Visual Optimization Lab
Information Systems Technologies Dept.
Sharp Laboratories of America
_______________________________________________
Magick-users mailing list
[email protected]
http://studio.imagemagick.org/mailman/listinfo/magick-users