Box filters for image processing

This online calculator allows you to process the image with the selected box filter, or use your own box filter.

The online calculator below allows you to apply a box filter to an image. To do this, the handbook Box filters introduces several well-known filters: for sharpening, edge detection, blurring, anti-aliasing or smoothing, embossing, and gaussian blurring. You can immediately apply them to the image and see the result. Also, the calculator displays the kernel matrix and the multiplier of the selected box filter. In addition, you can set your own box filter - by specifying the kernel matrix and the multiplier. As an example, I use a box filter that selects vertical lines in the image. Filter operation can be applied separately for each channel of the RGB model: red, green, and blue. You can read more about box filters under the calculator.

PLANETCALC, Box filters for image processing

Box filters for image processing

Source image
  • Drag files here
Kernel
 
Multiplier
 
Source image
 
Result
 

Box filters

Box filters are a kind of filter used in image processing. If we describe the box filter at the everyday level, then it can be described as calculating a new pixel value based on the values ​​of the surrounding pixels. Mathematically speaking, each filter is a special case of a discrete convolution of a two-dimensional function over another two-dimensional function.

< f*g > (i,j) = \sum_{l=n_0}^{n_1} \sum_{k=m_0}^{m_1} f(i-l, j-k) \cdot g(l, k)

If we decipher the formula above, it turns out that to calculate the new value of a pixel with coordinates (i, j) , all pixels are taken in some neighborhood from i - n0 to i - n1 horizontally and from j - m0 to j - m1 vertically, the value of each of them is multiplied by some function g, usually constant, the results of the multiplication are summed up and the result of the summation is assigned to the pixel (i, j) . The result is often normalized, for example, by dividing the sum by the area of the neighborhood (number of pixels taken for the summation). This can be shown by introducing a factor of 1/A in front of the sum in the formula above.

Let's look at the example of the simplest averaging filter. Our task here is to average the pixel value over neighboring pixels. The neighborhood of a pixel is a 3x3 square centered on the pixel itself. To average the pixel value, you need to sum the values ​​of all 9 pixels falling into the square and normalize by dividing by the area of the square - 9.

Thus, we can say that our function g is constant:
g=\frac{1}{9}
and write down the convolution operation as follows, taking out the factor 1/9.

< f*g > (i,j) =\frac{1}{9}\sum_{l=-1}^{1} \sum_{k=-1}^{1} f(i+l, j+k)

Box filters are usually written as a matrix, where the matrix itself is referred to as the box filter kernel. For our averaging filter, the record will be like this:

\frac{1}{9}\left[\begin{matrix} 1&1&1\\1&1&1\\1&1&1\end{matrix}\right]

Using different kernels, including those with zero and negative coefficients, you can get quite interesting effects, which is demonstrated by the calculator above.

URL copied to clipboard
Creative Commons Attribution/Share-Alike License 3.0 (Unported) PLANETCALC, Box filters for image processing

Comments