<p>Standard blur removes high frequency content from the signal, whereas edge detection usually look into high frequency to detect edges. Be careful on how much blurring to apply to ensure that you don't lose desirable edges. The goal of blurring is to perform <strong>noise reduction</strong>, so the best would be to come up with a model of the noise present in your images and what your desired edges looks like (their frequency, orientation, what caused them: shading on a smooth object, shadows, etc.) and tailor your blur filter to remove the noise but not the edges.</p>

<p>Seems like you want to implement an edge detector into a shader. Be sure to check what are the sources of noise in your image. For example, if you are displaying pure lambertian surfaces, chances are that there is virtually no noise in your data, so you don't need to apply a smoothing filter before detecting edges.</p>

<p>Also, instead of using a standard gaussian blur, you could look into <a href="https://en.wikipedia.org/wiki/Edge-preserving_smoothing" rel="nofollow">edge-preserving filters</a> like the bilateral filter. It is much slower, but is good to remove noise without altering too much the edges.</p>

<p>If you are performing filtering and edge detection through convolutions (the standard way of doing it), it doesn't matter if you do one before another, as convolutions are commutative, meaning $a*b = b*a$, where $*$ is the convolution operator, $a$ being the edge detector and $b$ the smoothing kernel.</p>

<p>On non-associative operations (like the bilateral filter), you must ask yourself the question "what is the goal of this operation?" Basically, blurring before the edge detection will diminish the image noise while blurring after will give you blurred edges (potentially caused by noise) instead of sharp edges. The same edges will be found, though, but the blurred one will be less precise. It depends on what you want to achieve: it could be interesting for art, but it just removes interesting information for signal analysis.</p>

<p>Not sure what "applying an edge to a color buffer" means; is the goal to perform <a href="https://en.wikipedia.org/wiki/Edge_enhancement" rel="nofollow">edge enhancement</a>?</p>

CC BY-SA 3.0
2016-09-05T17:21:48.097Z
Oh, I see. I would have answered differently if I knew what you were trying to achieve, as what I said was mainly for pixel shading on colors (I am more a computer vision person than graphics...). Have you seen this related question? http://answers.unity3d.com/questions/60155/is-there-a-shader-to-only-add-an-outline.html (First answer has a link to a code example)
Soravux
CC BY-SA 3.0
2016-09-05T09:55:45.350Z
2016-09-05T09:55:45.350Z
Soravux
<p>To reduce noise of edge detection the norm seems like it is to apply a blur. However, is it generally better to apply the blur to the input of the edge detection. The input in my case being the depth and normal GBuffers in which I compare neighbouring pixels.<br>
Or is it better to blur the output of the edge detection, e.g. a greyscale image of edge strength, before I use that to apply some edge to a colour buffer?</p>

CC BY-SA 3.0
2016-08-25T13:16:41.583Z
Updated question for clarification
Syntac_
<image-processing><blur><edge-detection>
Is it better to blur the input or output of an edge detection shader for noise reduction?
Syntac_
# Is it better to blur the input or output of an edge detection shader for noise reduction?

(Asked by: username_0 on 2016-08-25)

To reduce noise of edge detection the norm seems like it is to apply a blur. However, is it generally better to apply the blur to the input of the edge detection. The input in my case being the depth and normal GBuffers in which I compare neighbouring pixels.  
Or is it better to blur the output of the edge detection, e.g. a greyscale image of edge strength, before I use that to apply some edge to a colour buffer?

**Tags:** image-processing, blur, edge-detection

> **Comments:**
> **username_0**: Updated question for clarification  

---

## 1 answers

### Answer by username_1 on 2016-09-05. Score: 2 | Accepted answer

Standard blur removes high frequency content from the signal, whereas edge detection usually look into high frequency to detect edges. Be careful on how much blurring to apply to ensure that you don't lose desirable edges. The goal of blurring is to perform **noise reduction**, so the best would be to come up with a model of the noise present in your images and what your desired edges looks like (their frequency, orientation, what caused them: shading on a smooth object, shadows, etc.) and tailor your blur filter to remove the noise but not the edges.

Seems like you want to implement an edge detector into a shader. Be sure to check what are the sources of noise in your image. For example, if you are displaying pure lambertian surfaces, chances are that there is virtually no noise in your data, so you don't need to apply a smoothing filter before detecting edges.

Also, instead of using a standard gaussian blur, you could look into [edge-preserving filters](https://en.wikipedia.org/wiki/Edge-preserving_smoothing) like the bilateral filter. It is much slower, but is good to remove noise without altering too much the edges.

If you are performing filtering and edge detection through convolutions (the standard way of doing it), it doesn't matter if you do one before another, as convolutions are commutative, meaning $a\*b = b\*a$, where $\*$ is the convolution operator, $a$ being the edge detector and $b$ the smoothing kernel.

On non-associative operations (like the bilateral filter), you must ask yourself the question "what is the goal of this operation?" Basically, blurring before the edge detection will diminish the image noise while blurring after will give you blurred edges (potentially caused by noise) instead of sharp edges. The same edges will be found, though, but the blurred one will be less precise. It depends on what you want to achieve: it could be interesting for art, but it just removes interesting information for signal analysis.

Not sure what "applying an edge to a color buffer" means; is the goal to perform [edge enhancement](https://en.wikipedia.org/wiki/Edge_enhancement)?

> **Comments:**
> **username_1**: Oh, I see. I would have answered differently if I knew what you were trying to achieve, as what I said was mainly for pixel shading on colors (I am more a computer vision person than graphics...). Have you seen this related question? http://answers.unity3d.com/questions/60155/is-there-a-shader-to-only-add-an-outline.html (First answer has a link to a code example)  

---

