[cairo] image downsampling quality
spitzak at gmail.com
Thu Jan 2 14:01:34 PST 2014
I think there is some confusion here.
Unless there is a saved intermediate image that is reused for more than
one transform, there should be only one filter.
To do a transform, this filter starts out as a continuous field in the
output space, centered on the desired output pixel. This field is then
inverse-transformed to input space. This will rotate, scale, and
translate the filter by an arbitrary non-integer amount (the fraction
will be different for each output pixel!)
The input image is then multiplied by this filter and the resulting sum
is the value of that output pixel.
For reconstruction filters it is by definition correct to treat the
input image as impulses in the centers of the pixels. Therefore the
value to multiply by is the value of the transformed filter at the
center of each input pixel.
There is no way around this. To produce a single output pixel there must
be exactly one weight applied to each input pixel. This weight is going
to depend on the scaling factor and on the fractional result of the
inverse transform. Using more than one filter is not going to fix this,
all you can do is blur the incorrect result of the first filter.
I think there may be some confusion with mipmapping, which indeed
applies two filters. The first is to create the mipmap plane. Although
all the rules above apply to this transform, it is usually an integer
down-scale with no rotation, which does make a single set of filter
weights reusable. This mipmap plane is then sampled with a second
filter, where all the rules I describe above apply, including the
unavoidable fact that there are different sets of weights for each
output pixel. However it is in effect always being up-scaled, therefore
a bilinear filter is always used. Applying two transforms is always
going to produce more blurring than a single transform, you cannot avoid
this, and trying to use sync or sharpening to fix it is futile. And all
of this is a total waste of time unless the mipmap is saved and reused
for further transforms.
Søren Sandmann wrote:
> Krzysztof Kosiński <tweenk.pl at gmail.com> writes:
>> Impulse sampling is always used when the given dimension is upscaled.
>> For downscaling, it seems that Lanczos3 is used for both sampling and
>> reconstruction. Should Lanczos3 sampling be used together with box
>> reconstruction in that case?
> For downscaling an image using Lanczos sampling, I'd use impulse
More information about the cairo