# 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.

### 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.

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 - n _{0}* to

*i - n*horizontally and from

_{1}*j - m*to

_{0}*j - m*vertically, the value of each of them is multiplied by some function

_{1}*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:

and write down the convolution operation as follows, taking out the factor 1/9.

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:

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

#### Similar calculators

**

**PLANETCALC, Box filters for image processing

## Comments