|
10 | 10 | <li>Create an edge map using the high frequency signal from the image</li> |
11 | 11 | <li>Have a long aside about array notation in Julia</li> |
12 | 12 | </ol> |
13 | | -<p>This is a natural follow-up to my <a href="http://learningjulia.com/2017/02/24/blurring-and-manipulation.html">blurring computation from a previous exercise</a>, since the Sobel operator is just a different kind of kernel. But it is also a common kernel needed in image manipulation, so I can compare my implemenation timing to the implementation in the <a href="https://github.com/JuliaImages/ImageFiltering.jl">ImageFiltering.jl</a> package. After timing the built-in functions, I won't even try to time my own implemenation...</p> |
| 13 | +<p>This is a natural follow-up to my <a href="https://learningjulia.com/2017/02/24/blurring-and-manipulation.html">blurring computation from a previous exercise</a>, since the Sobel operator is just a different kind of kernel. But it is also a common kernel needed in image manipulation, so I can compare my implemenation timing to the implementation in the <a href="https://github.com/JuliaImages/ImageFiltering.jl">ImageFiltering.jl</a> package. After timing the built-in functions, I won't even try to time my own implemenation...</p> |
14 | 14 | <h2 id="Setup">Setup<a class="anchor-link" href="#Setup">¶</a></h2><p>First things first, let's set up for manipulating images.</p> |
15 | 15 |
|
16 | 16 | </div> |
@@ -123,7 +123,7 @@ <h2 id="Setup">Setup<a class="anchor-link" href="#Setup">¶</a></h2><p>First |
123 | 123 | <h2 id="Sobel-kernels">Sobel kernels<a class="anchor-link" href="#Sobel-kernels">¶</a></h2><p>The first thing we'll try doing is manually running a Sobel image kernel on the input image. The <a href="https://en.wikipedia.org/wiki/Sobel_operator">Sobel operator</a> is basically an approximation of derivatives in the <code>X</code> and <code>Y</code> directions of the image. The theory is that if there is a high gradient magnitude, there is an edge in that location. The way you compute the Sobel operator is to convolve this kernel:</p> |
124 | 124 | $$K_x = \begin{bmatrix} 1 & 0 & -1 \\ 2 & 0 & -2 \\ 1 & 0 & -1 \end{bmatrix}$$<p>in the <code>X</code> direction, and</p> |
125 | 125 | $$K_y = \begin{bmatrix} 1 & 2 & 1 \\ 0 & 0 & 0 \\ -1 & -2 & -1 \end{bmatrix}$$<p>in the <code>Y</code> direction. Note how they are just transposes of each other.</p> |
126 | | -<p>Practically, to compute the kernel, we need to iterate over the output image. As we discussed in <a href="http://learningjulia.com/2017/02/24/blurring-and-manipulation.html">a previous post</a>, when transforming one image into another, you need to iterate over the output image, and for each pixel, find the pixels from the input image needed to compute that particular pixel. In the case of the Sobel kernel, we need to iterate over the output twice - once for the <code>X</code> direction, which needs 9 pixels for the computation, and once for the <code>Y</code> direction computation, which also needs 9 pixels.</p> |
| 126 | +<p>Practically, to compute the kernel, we need to iterate over the output image. As we discussed in <a href="https://learningjulia.com/2017/02/24/blurring-and-manipulation.html">a previous post</a>, when transforming one image into another, you need to iterate over the output image, and for each pixel, find the pixels from the input image needed to compute that particular pixel. In the case of the Sobel kernel, we need to iterate over the output twice - once for the <code>X</code> direction, which needs 9 pixels for the computation, and once for the <code>Y</code> direction computation, which also needs 9 pixels.</p> |
127 | 127 | <h2 id="The-imfilter-function">The <code>imfilter</code> function<a class="anchor-link" href="#The-imfilter-function">¶</a></h2><p>To apply image kernels, I am going to use the <code>imfilter</code> function from JuliaImages: <a href="http://juliaimages.github.io/latest/function_reference.html#ImageFiltering.imfilter">http://juliaimages.github.io/latest/function_reference.html#ImageFiltering.imfilter</a>. Rather than manually trying to implement out-of-bounds implementations or worrying about applying a dot product / convolution, let's just use the builtins.</p> |
128 | 128 | <p>Another awesome feature of the JuliaImages library is the ability to pad the input according to 4 rules:</p> |
129 | 129 | <ol> |
|
0 commit comments