-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible bug in resampler #182
Comments
For further bug isolation and easier step-by step walking through code tried to lower number of samples in resizer's input as much as possible: 1 sample (230 at field of 16) input retrives kernel itself image output (acting as delta-function input to filter, Size x 8, taps=20). And ringing at its edges masks the bug. The minimum good bug visible input is 3 non-zero samples (for 1d horizontal resampler and taps 10..20),(127,230,127): It shows how sincs (3 sincs waves from 3 non-zero input samples) sum already good converges/balances to zero close enough to samples position. But something buggy happens at the edges of truncated sincs. May the resampler engine losts some members of kernel at the very edges of processing so the very edges of sum lost ability to converges to zero and stays in small negative values. Script is
So comes the easiest (temporal) bugfix or at least workaround - just truncate resampler's sums a bit so we will get good converged central output. Like perform taps=20/support=20 processing and use only 16..18 output max which are not buggy. |
Have finally spend more time with checking this bug in debugger. It looks caused with combined reasons: At the edges if image buffer bug is not exist because current resampling program simply copy 'taps' (or may be 2x taps) number of edge samples of image buffer and supply resampler with static input (the changing is kernel shifted samples) untill it travels on taps (or 2x taps) distance from frame edge. So at that places if we have 'convergible' samples at resampler;s input it always output correct. But then convolution 'reading frame' starts to travel from image buffer edge it, at some step, losts for example 1 of 3 input sample required for exact convergence of 3 sinc input_samples-weighted sum and we got an error in output. If this error > 1/255 for 8-bit encoding we got 'ghost' output error and it follows image object at 'taps' distance. The most of other resize kernels are weighted to almost or full zero at the edge of kernel so this error falls below 1/255 and not visible at output. So I see 2 ways of workarounding: Kernel func:
Header
In addition to 'ghosting' effect outside object's image the old SincResize has also 'grid' effect at high levels inside object:
The new method fixes this too. |
It looks like some error on some edge-conditions in calculations. At least it simply reproductible in SincResize: Given input image data as 'ideal video/image point' for example defined with 2D cross-sections as (16),27,132,235,132,27,(16) samples (not gamma-corrected, linear, 16..235 video levels coded) sequence and 2D full (sinc-interpolated using radius-vector) 5x5 array
We can set its values in 'ms-paint' to get image-formatted file:
1point_27_132.zip
And load into avisynth and SincResize:
With above Crop() parameters output image size is 1032x904 and output shows 4 errors artifacts (marked with circles)
If we lower resizer input image size the bug looks like disappear and output is clear:
To make bug much more visible it can be added
Levels(0, 1, 25, -300, 255)
The distance to buggy output samples from center of filter depends on 'taps' parameter. With taps=10
Version 3.6.1 has it too. Attempt to SetMaxCPU("none") does not helps.
First reported at https://forum.doom9.org/showthread.php?p=1919151#post1919151
The text was updated successfully, but these errors were encountered: