6

画像のサイズ変更がどのように機能するかを理解しようとしています。「フィルター」が何に適しているかを誰かに説明してもらえますか?

  • フィルターは、ソース ピクセルがデスティネーション ピクセルにどれだけ寄与するかを計算しますか?

  • 「ボックス」や「ガウス」などのフィルターがありますが、「バイキュービック」というフィルターはありますか?ここでは、「畳み込みフィルター」と ... という 2 つの概念を混在させますか?

  • アップスケーリングとダウンスケーリングの両方に同じフィルターを使用することは可能ですか? (これのサンプルコードを見るのは本当に素晴らしいことです)

  • 最初に画像を 1 つの次元で引き伸ばしてから、別の次元で引き伸ばすことが望ましいですか?

4

1 に答える 1

8

In image resizing, the filter avoids a phenomenon called aliasing. If you try to resize without a filter, aliasing typically manifests as obnoxious pixellated effects, which are especially visible when animated...

To answer your points:

  • The filter does calculate how much each source pixel contributes to each destination. For resizing, you want a linear filter, which is pretty simple: the filter can be viewed as a small grayscale image; effectively, you center the filter over a location corresponding to each output pixel, multiply each nearby pixel by the filter value at that location, and add them up to get the output pixel value.

  • All such filters are "convolution filters", because convolution is the mathematical name for the operation described above. A "box" filter literally looks like a box -- every pixel within the box is weighted equally, while "gaussian" filters are more roundish blobs, feathering towards zero at the edge.

  • The most important thing for upscaling and downscaling is to choose the right size for your filter. Briefly, you want to scale your filter based on whichever of the input and output has the lowest resolution. The second most important thing is to avoid bad filters: the "box" filter is what you usually get when you try to resize without filtering; a "bilinear" filter as provided by computer graphics hardware yields mediocre upscaling, but is supplied at the wrong size for downscaling.

  • For performance reasons, it is desirable to scale images in one dimension and then the other one. This means your filter runs much faster: in time proportional to the filter width, instead of proportional to the filter area. All the filters discussed here are "separable", which means you can apply them in this way.

If you choose a high-quality filter, the exact form is less critical than you might think. There are two classes of good filters: all-positive ones like "gaussian" which tend to the blurry side, and negative-lobed ones like "lanczos" which are sharp, but may yield slight ringing effects. Note that "bicubic" filters is a category, which includes "B-spline" which is all-positive, and "Mitchell" and "Catmull-Rom" which have negative lobes.

于 2012-09-17T22:22:15.393 に答える