Skip to content

Conversation

RunDevelopment
Copy link
Member

While using chainner's Threshold node to sharpen some upscaled text, I noticed that the AA is quite sharp. This is generally good, but I would have liked a bit more smoothness in this case.

This PR adds an extra_smoothness parameter to binary_threshold. extra_smoothness can be used to control the strength of a sub-pixel blur applied to the AA. Well, that's what it does conceptually. Under the hood, this is actually implemented by simply extending the range of the bilinear kernels that are used to get the threshold area. Doing the blur like this has 2 advantages:

  1. There is no performance overhead (* see below). The integration we use to get the area of a bilinear kernel doesn't care how much area the kernel covers.
  2. The blur is higher quality. This isn't a pixel-based blur. Instead of re-sampling an already sampled image (the pixels), we are just changing which area we sample per pixel from the infinitely precise mathematical representation of the thresholded image.

Example:
image


While the new smoothness doesn't impact performance, it did highlight an old bug. binary_threshold only applies AA to pixels that need it. This is done via an edge detection, but this edge detection didn't flag edges correctly. This bug was barely noticeable before, but it is very obvious for high smoothing values.

Unfortunately, the fix wasn't free. Depending on the image, binary_threshold is now between 5% and 20% slower with AA enabled. Not a problem IMO, but a performance regress nonetheless.

@RunDevelopment RunDevelopment changed the title Add smoothness option threshold anti-aliasing Add smoothness option for threshold AA Apr 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant