Improved antialiased mean reduction #1300
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This improves the output of
Canvas.line
using an antialiasedmean
reduction.Example code:
Image produced, before and after this PR:
and zoomed in by a factor of 3 (before and after):
Before this PR a
mean
reduction was implemented by dividing asum
reduction by acount
reduction. If you imaginesum("value")
where all the value are 1 then thesum
andcount
produce identical results with larger values at the middle of lines and smaller antialiased values at the edges. Dividing one by the other therefore loses the antialiasing.This PR changes the
mean
to be asum
divided by a new reduction_count_ignore_antialiasing
and the latter, as the name suggests, ignores the antialiasing factor. Hence the result produced is antialiased.It isn't actually quite that simple as at the edges of joins artifacts were produced where the line goes over itself. Pixels where this occurred are visited twice, the second time with a larger antialiasing factor. Now when this occurs both of the antialiasing factors are passed to
Reduction.append
functions so that the reduction can better deal with it. There is no change to the low-level antialiasing code which has always calculated both values, but now both values are used rather than just one.