<p>The easiest way to deal with this would be to provide thickness for the edges in the continuous setting. That is, make your edges out of solid capsules/cylinders, then you would not have this issue. Technically, this is is neither a supersampling nor a filtering technique, but rather a reformulation of the problem in the continuous setting. Another equivalent reformulation is considering only the vertices and then your reconstruction function being thick edges between those (using a thick line algorithm).</p>
<p>This doesn't seem to be your setting however? Since you mentioned that you only have the raster (aliased) image already, in which case you have already introduced the error so it is hard to get rid off. If you can &quot;access&quot; the continuous model it is a lot easier to fix. If you cannot, then I could recommend using a different reconstruction filter than the dilation that you are using. For instance you can do a thickening based on distance to pixels (sdf) with a step function. This should remove the issues you are having, at least for the example you showed.</p>

CC BY-SA 4.0
2020-12-22T16:53:21.090Z
Ineed the algorithm is being designed around the presuposition that the inputs are images, not polygons, so i won;t have access to the original information of the lines.
Makogan
CC BY-SA 4.0
2020-12-23T14:31:37.927Z
@Makogan The sdf (in screen space) ought to work then.
lightxbulb
CC BY-SA 4.0
2020-12-22T13:09:26.683Z
2020-12-22T13:09:26.683Z
lightxbulb
<p>I have the following challenge. I am given a black and white image with rasterized lines.
<a href="https://i.sstatic.net/d5k2P.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/d5k2P.png" alt="enter image description here" /></a></p>
<p>Given this input, I want to extend the edges to cover more than one pixel and antialias the edges.</p>
<p>My first attempt was to pass a morphological dilation followed by a gaussian filter. But that straight up did not work, all i got is for the image to look blurry.</p>
<p>I instead tried combining both effects into a single shader and go the following:</p>
<p><a href="https://i.sstatic.net/DuACy.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/DuACy.png" alt="enter image description here" /></a>
<a href="https://i.sstatic.net/V4QmM.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/V4QmM.png" alt="enter image description here" /></a></p>
<p>This is decent, but you can still see a lot of the original aliasing of the edges.</p>
<p>Assuming that I only have the input image, are there any image based / screen space based AA techniques I can use to make the edges look smooth?</p>

CC BY-SA 4.0
2020-12-21T02:17:52.917Z
That isn't aliasing. It's distortion caused by your filtering techniques.
Nicol Bolas
CC BY-SA 4.0
2020-12-21T02:35:32.493Z
It's 100% the aliasing from the original image. The original image is a rasterized line, when the pixels get dilated the pixelation from the original rasterization is dilated, as is. That's what's causing the jaggies in the lines.
Makogan
CC BY-SA 4.0
2020-12-21T02:39:41.890Z
Yes, the original image has aliasing in it, but once you do your amplification, it stops being aliasing (which is a very specific signal processing term referring to a particular artifact that is the result of analog-to-digital conversions below a certain resolution) and is just data. As such, a technique designed specifically to combat *aliasing* specifically cannot fix a thing that is itself not aliasing.
Nicol Bolas
CC BY-SA 4.0
2020-12-21T02:56:01.167Z
Actually it does not stop being aliasing. Aliasing, coming from signal processing, is when a signal is undersampled, such that the sampled signal looks different from the original signal.

A dilation of an alias signaled is itself an aliased signal then, as it fits that defitionion.

Moreover, Antialising techniques in image space and most definitely work for this problem, point in case, a gaussian blur would absolutely reduce the effect, at the expense of contrasted edges (which is exactly what would happen with any other image).
Makogan
CC BY-SA 4.0
2020-12-21T02:57:23.017Z
In short, this image is aliased, and anti aliasing can be used to to fight back the problem. All that is needed is a suitable image based anti aliasing algorithm, differnt from a blur pass.
Makogan
CC BY-SA 4.0
2020-12-21T03:44:50.243Z
"*anti aliasing can be used to to fight back the problem*" No, it can't. *Real* anti-aliasing techniques ultimately boil down to "take more samples" (a Gaussian blur is not "anti-aliasing"). There are no "more samples" because the start of this process is a digital image. You can't create samples where none exist. The most you can do is try to manufacture what the data probably looked like, but that's *not* "anti-aliasing".
Nicol Bolas
CC BY-SA 4.0
2020-12-21T05:40:27.187Z
@NicolBolas It does no one any good to be this pedantic. Techniques that try to repair jaggies in the image after the fact are widely referred to as antialiasing in the industry and literature.
Nathan Reed
CC BY-SA 4.0
2020-12-21T05:56:44.787Z
@NathanReed: That's why it's important to know what you're talking about. Even faux-anti-aliasing techniques likely won't work here because they're designed to *only* add noise to areas that have issues caused by aliasing. Because of the filtering and amplification already applied, what we see in these images don't look like aliasing artifacts, so such techniques are likely to leave them alone. So we're no longer in the realm of any kind of "anti-aliasing" technique; we're in the realm of image reconstruction algorithms.
Nicol Bolas
CC BY-SA 4.0
2020-12-22T12:53:00.953Z
@NicolBolas Aliasing is simply the higher frequency components of the copies in the Fourier domain leaking into the lower frequencies of the copy which we filter out through the reconstruction function. Note that the reconstruction function is included in there. Makogan's reconstruction is a box filter composed with a dilation operation. You're in the exact same setting as the original definition: you have point samples and a reconstruction function. It is aliasing with a different function than the one you are used to, but it is aliasing.
lightxbulb
<rendering><shader><antialiasing><raster-image>
Screen Space anti aliasing?
Makogan
# Screen Space anti aliasing?

(Asked by: username_0 on 2020-12-21)

I have the following challenge. I am given a black and white image with rasterized lines.
[![enter image description here](https://i.sstatic.net/d5k2P.png)](https://i.sstatic.net/d5k2P.png)

Given this input, I want to extend the edges to cover more than one pixel and antialias the edges.

My first attempt was to pass a morphological dilation followed by a gaussian filter. But that straight up did not work, all i got is for the image to look blurry.

I instead tried combining both effects into a single shader and go the following:

[![enter image description here](https://i.sstatic.net/DuACy.png)](https://i.sstatic.net/DuACy.png)
[![enter image description here](https://i.sstatic.net/V4QmM.png)](https://i.sstatic.net/V4QmM.png)

This is decent, but you can still see a lot of the original aliasing of the edges.

Assuming that I only have the input image, are there any image based / screen space based AA techniques I can use to make the edges look smooth?

**Tags:** rendering, shader, antialiasing, raster-image

> **Comments:**
> **username_1**: That isn't aliasing. It's distortion caused by your filtering techniques.  
> **username_0**: It's 100% the aliasing from the original image. The original image is a rasterized line, when the pixels get dilated the pixelation from the original rasterization is dilated, as is. That's what's causing the jaggies in the lines.  
> **username_1**: Yes, the original image has aliasing in it, but once you do your amplification, it stops being aliasing (which is a very specific signal processing term referring to a particular artifact that is the result of analog-to-digital conversions below a certain resolution) and is just data. As such, a technique designed specifically to combat *aliasing* specifically cannot fix a thing that is itself not aliasing.  
> **username_0**: Actually it does not stop being aliasing. Aliasing, coming from signal processing, is when a signal is undersampled, such that the sampled signal looks different from the original signal.  A dilation of an alias signaled is itself an aliased signal then, as it fits that defitionion.  Moreover, Antialising techniques in image space and most definitely work for this problem, point in case, a gaussian blur would absolutely reduce the effect, at the expense of contrasted edges (which is exactly what would happen with any other image).  
> **username_0**: In short, this image is aliased, and anti aliasing can be used to to fight back the problem. All that is needed is a suitable image based anti aliasing algorithm, differnt from a blur pass.  
> **username_1**: "*anti aliasing can be used to to fight back the problem*" No, it can't. *Real* anti-aliasing techniques ultimately boil down to "take more samples" (a Gaussian blur is not "anti-aliasing"). There are no "more samples" because the start of this process is a digital image. You can't create samples where none exist. The most you can do is try to manufacture what the data probably looked like, but that's *not* "anti-aliasing".  
> **username_2**: @username_1 It does no one any good to be this pedantic. Techniques that try to repair jaggies in the image after the fact are widely referred to as antialiasing in the industry and literature.  
> **username_1**: @username_2: That's why it's important to know what you're talking about. Even faux-anti-aliasing techniques likely won't work here because they're designed to *only* add noise to areas that have issues caused by aliasing. Because of the filtering and amplification already applied, what we see in these images don't look like aliasing artifacts, so such techniques are likely to leave them alone. So we're no longer in the realm of any kind of "anti-aliasing" technique; we're in the realm of image reconstruction algorithms.  
> **username_3**: @username_1 Aliasing is simply the higher frequency components of the copies in the Fourier domain leaking into the lower frequencies of the copy which we filter out through the reconstruction function. Note that the reconstruction function is included in there. username_0's reconstruction is a box filter composed with a dilation operation. You're in the exact same setting as the original definition: you have point samples and a reconstruction function. It is aliasing with a different function than the one you are used to, but it is aliasing.  

---

## 1 answers

### Answer by username_3 on 2020-12-22. Score: 2 | Accepted answer

The easiest way to deal with this would be to provide thickness for the edges in the continuous setting. That is, make your edges out of solid capsules/cylinders, then you would not have this issue. Technically, this is is neither a supersampling nor a filtering technique, but rather a reformulation of the problem in the continuous setting. Another equivalent reformulation is considering only the vertices and then your reconstruction function being thick edges between those (using a thick line algorithm).

This doesn't seem to be your setting however? Since you mentioned that you only have the raster (aliased) image already, in which case you have already introduced the error so it is hard to get rid off. If you can "access" the continuous model it is a lot easier to fix. If you cannot, then I could recommend using a different reconstruction filter than the dilation that you are using. For instance you can do a thickening based on distance to pixels (sdf) with a step function. This should remove the issues you are having, at least for the example you showed.

> **Comments:**
> **username_0**: Ineed the algorithm is being designed around the presuposition that the inputs are images, not polygons, so i won;t have access to the original information of the lines.  
> **username_3**: @username_0 The sdf (in screen space) ought to work then.  

---

