Image resizing: what is a “filter”?

I'm trying to understand how image resizing works - please, can someone explain to me what a filter is? Good?

  • Does the filter calculate how much the source pixel contributes to the target pixel?

  • there are filters like "box" and "gaussian", but is there a filter called "bicubic"? Am I confusing two concepts, one of which is the "convolution filter" and ...?

  • Can the same filter be used for scaling and scaling? (it would be nice to see some sample code)

  • Is it advisable to first stretch the image in one dimension, and then in another?

+6
source share
1 answer

When resizing an image, the filter avoids a phenomenon called aliasing . If you try to resize without a filter, the overlay usually appears as unpleasant pixel effects, which are especially noticeable during animation ...

To answer your questions:

  • The filter calculates how much each pixel in the source contributes to each destination. To resize, you need a linear filter, which is quite simple: the filter can be considered as an image in shades of gray; effectively center the filter in the place corresponding to each output pixel, multiply each neighboring pixel by the filter value in this place and add them to obtain the value of the output pixel.

  • All such filters are “convolution filters,” since convolution is the mathematical name for the operation described above. The “box” filter literally looks like a box - each pixel inside the field is weighed equally, and the “Gaussian” filters are more rounded drops, leading to zero at the edge.

  • The most important thing for scaling and scaling is choosing the right size for your filter. In short, you want to scale your filter based on which of the input and output has the lowest resolution. The second important thing is to avoid bad filters: the “box” filter is what you usually get when you try to resize without filtering; The "bilinear" filter provided by the computer graphics hardware provides mediocre scaling, but comes with the wrong size to scale down.

  • For performance reasons, it is desirable to scale images in one dimension and then in another. This means that your filter works much faster: time is proportional to the width of the filter, and not proportional to the area of ​​the filter. All the filters discussed here are “shared”, which means that you can apply them this way.

If you choose a high-quality filter, the exact shape is less critical than you think. There are two classes of good filters: omnipositive, such as Gaussian, which tend to be blurry, and negative-lobed, such as lanczos, which are sharp but can have small side effects. Note that bicubic filters are a category that includes a B-spline, which is positive, and Mitchell and Catmull-Rom, which have negative petals.

+7
source

Source: https://habr.com/ru/post/925554/


All Articles