sekrit-twc/zimg

Question about the bilinear filter used in chroma subsampling

dreifachstein opened this issue · 3 comments

The 444 to 420 conversion uses a 3-tap (1/4, 1/2, 1/4) horizontal filter and a 4-tap (1/8. 3/8/ 3/8, 1/8) vertical filter for chroma_sample_loc=left.
The 4-tap vertical filter is quite unexpected. Is this intentional?

in:  x0 x1 x2 x3 x4 x5
out:   y0    y1    y2

y1 = w1 * x1 + w2 * x2 + w3 * x3 + w4 * x4
w1 = w4
w2 = w3
w2 = 3 * w1
w1 + w2 + w3 + w4 = 1
==> w1 = 1/8, w2 = 3/8, w3 = 3/8, w4 = 1/8

Where is the issue?

I was expecting the bilinear subsampling step to use 3-tap horizontal and 2-tap vertical with weights derived from pixel coverage.

As you can see in the diagram, there are four input samples between y0 and y2, thus four weights contribute to the value of y1.