GetOptimalKernelWidth1D: when the given radius is zero, it calculates a one-dimenional blur for radius = 2, 3, ... until "value" is less than 1/2^Q, where Q=8, 16, 32 or 64, so "value" is effectively zero. I assume "value" is the tail end of the bell-shaped Gaussian curve. In other words, it finds the minimum width of the kernel that doesn't lose any data. If the kernel were larger, the new entries would be zero. This minimum depends on the Q-number and whether HDRI is used.
GetOptimalKernelWidth2D does the same, but for two-dimensional squares, and the tail end is measured at the corner of the square. So this will "clip" values at the edges (which I think is a bad idea; see below).
We can do the similar job at the command level, by making a single white pixel in a large black field, blurring with a given sigma (eg 1), trimming, and finding the dimension. I do this at Q8, Q16 and Q32, all integer (not HDRI), and Q32 HDRI.
Code: Select all
f:\web\im>c:\cygwin64\home\Alan\iminst8i\bin\convert xc:White -bordercolor Black -border 100 -gaussian-blur 50x1 -auto-level -trim +repage info:
xc:White XC 5x5 8-bit sRGB 0.109u 0:00.114
f:\web\im>c:\cygwin64\home\Alan\iminst16i\bin\convert xc:White -bordercolor Black -border 100 -gaussian-blur 50x1 -auto-level -trim +repage info:
xc:White XC 9x9 16-bit sRGB 0.109u 0:00.113
f:\web\im>c:\cygwin64\home\Alan\iminst32i\bin\convert xc:White -bordercolor Black -border 100 -gaussian-blur 50x1 -auto-level -trim +repage info:
xc:White XC 13x13 32-bit sRGB 0.125u 0:00.119
f:\web\im>c:\cygwin64\home\Alan\iminst32f\bin\convert xc:White -bordercolor Black -border 100 -gaussian-blur 50x1 -auto-level -trim +repage info:
xc:White XC 17x17 32-bit sRGB 0.108u 0:00.114
We can compare this to the kernel made by Q32 HDRI with "-gaussian-blur x1", when the radius isn't given:
Code: Select all
f:\web\im>%IMDEV%convert xc:White -bordercolor Black -border 100 -define showkernel=1 -gaussian-blur x1 -auto-level -trim +repage info:
Code: Select all
Kernel "Gaussian" of size 13x13+6+6 with values from 0 to 0.159155
The corner values are zero, but no other values are.
If we repeat the previous but with "-gaussian-blur Rx1" where R=1, 2, 3, ... we need R=9 to prevent any clipping. This gives a square kernel 19x19, but the first and last rows and columns are exactly zero, so the kernel is effectively only 17x17. This is the same result as the white pixel on black field test, for Q32 HDRI.
I conclude that the calculation IM makes for the radius in "-gaussian-blur x1" is too aggressive; the kernel is smaller than it should be.