[wiki:libpipi << back to libpipi] = Gaussian filtering = The usual way to create a Gaussian kernel is to evaluate a Gaussian function at the center of each cell: k[i][j] = exp(-(i²+j²)/2σ) This usually works well, except when the kernel is thin (σ < 1). It gets worse when using our generalised kernel: k[i][j] = exp(-((i×cosθ-j×sinθ-dx)²+(j×cosθ+i×sinθ-dy)²)/2σ) {{{ #!html
TODO interpolate the Gaussian integral on more points, eg. 5×5 (currently libpipi does it at the central point and at 8 additional points in the neighbourhood). }}} === Code === * [/browser/libpipi/trunk/pipi/filter/blur.c] * [/browser/libpipi/trunk/pipi/filter/convolution_template.h] * [/browser/libpipi/trunk/pipi/filter/convolution.c] = Median filtering = There are several ways to optimise a median filter. The first idea is an approximation, based upon the assumption that the median of subset medians is close to the median of the whole set. It can already be simulated by doing `--median 5x0 --median 0x5` in `pipi`, so there is no real point in studying this specific optimisation. The second idea is to optimise the median selection. The most naive method is to bubble-sort the neighbourhood values and select the middle point, which has complexity O(n²). Improving on the sort algorithm by using eg. heapsort or quicksort, reduces the complexity to O(n.log2(n)). But since we’re only interested in the median and not in ordering the rest of the data, we can use an efficient median selection algorithm. This operation can be done in fewer than 3n tests ![1] but the practical implementation is extremely complex. === Code === * [/browser/libpipi/trunk/pipi/filter/median.c] === Links === * [http://coding.derkeiler.com/Archive/General/comp.programming/2004-10/0289.html Sliding median filter] * [http://iris.usc.edu/Vision-Notes/bibliography/twod268.html A shitload of papers about median filtering and its derivatives] === References === * ![1] Uri Zwick, [http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.5.2770 Selecting the median], In Proceedings of the 6rd Annual ACM-SIAM Symposium on Discrete Algorithms (1995) = Dilate / erode = Erosion and dilation already work, but only for nearest pixels. {{{ #!html
TODO each pixel couple test is done twice. There seems to be an opportunity for improvement there. }}} {{{ #!html
TODO implement "dilate by X" (Manhattan distance). }}} {{{ #!html
TODO implement "dilate by X" (Euclidian distance). }}} === Code === * [/browser/libpipi/trunk/pipi/filter/dilate.c] === Links === * [http://ostermiller.org/dilate_and_erode.html Efficiently Implementing Dilate and Erode Image Functions]