Skip to content

Commit f9b5427

Browse files
authored
Merge pull request #204 from datacarpentry/30-kernel-shape
explain motivation for kernel size/shape exercises
2 parents 6900150 + 440b058 commit f9b5427

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

episodes/06-blurring.md

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ background of the image ends and the object begins.
3232

3333
When we blur an image, we make the color transition from one side of an edge in the image to another
3434
smooth rather than sudden. The effect is to average out rapid changes in pixel intensity. A blur is
35-
a very common operation we need to perform before other tasks such as
36-
[thresholding]({{ page.root }}/07-thresholding). There are several different blurring functions
35+
a very common operation we need to perform before other tasks such as
36+
[thresholding]({{ page.root }}/07-thresholding). There are several different blurring functions
3737
in the `skimage.filters` module, so we will focus on just one here, the *Gaussian blur*.
3838

3939
> ## Filters
@@ -224,11 +224,11 @@ The first two parameters to `skimage.filters.gaussian()` are the image to blur,
224224
`image`, and a tuple defining the sigma to use in y- and x-direction,
225225
`(sigma, sigma)`. The third parameter `truncate` gives the radius of the kernel
226226
in terms of sigmas. A Gaussian function is defined from -infinity to +infinity, but
227-
our kernel (which must have a finite, smaller size) can only approximate the real function.
227+
our kernel (which must have a finite, smaller size) can only approximate the real function.
228228
Therefore, we must choose a certain distance from the centre of the function where we stop
229229
this approximation, and set the final size of our kernel. In the above example, we set
230230
`truncate` to 3.5, which means the kernel size will be 2 * sigma * 3.5. For example,
231-
for a `sigma` of 1.0 the resulting kernel size would be 7, while for a
231+
for a `sigma` of 1.0 the resulting kernel size would be 7, while for a
232232
`sigma` of 2.0 the kernel size would be 14. The default value for `truncate` in scikit-image is 4.0.
233233
234234
The last parameter to `skimage.filters.gaussian()` tells skimage to interpret our image, that has three
@@ -247,7 +247,14 @@ plt.show()
247247
248248
> ## Experimenting with sigma values (10 min)
249249
>
250-
> Try running the code above with a range of smaller and larger sigma values.
250+
> The size and shape of the kernel used to blur an image can have a
251+
> significant effect on the result of the blurring and any downstream analysis
252+
> carried out on the blurred image.
253+
> The next two exercises ask you to experiment with the sigma values of the kernel,
254+
> which is a good way to develop your understanding of how the choice of kernel
255+
> can influence the result of blurring.
256+
>
257+
> First, try running the code above with a range of smaller and larger sigma values.
251258
> Generally speaking, what effect does the sigma value have on the
252259
> blurred image?
253260
>
@@ -264,9 +271,9 @@ plt.show()
264271
265272
> ## Experimenting with kernel shape (10 min - optional, not included in timing)
266273
>
267-
> Now, try running the code above with different sigmas in the y and x direction.
274+
> Now, what is the effect of applying an asymmetric kernel to blurring an image?
275+
> Try running the code above with different sigmas in the y and x direction.
268276
> For example, a sigma of 1.0 in the y direction, and 6.0 in the x direction.
269-
> What is the effect on the blurred image?
270277
>
271278
> > ## Solution
272279
> >
@@ -282,9 +289,20 @@ plt.show()
282289
> > plt.show()
283290
> > ~~~
284291
> > {: .language-python}
292+
> >
285293
> > ![Rectangular kernel blurred image](../fig/rectangle-gaussian-blurred.png)
286-
> > This produces a kernel that is rectangular instead of square. Notice that the image
287-
> > is much more blurred in the x direction than the y direction.
294+
> >
295+
> > These unequal sigma values produce a kernel that is rectangular instead of square.
296+
> > The result is an image that is much more blurred in the x direction than the
297+
> > y direction.
298+
> > For most use cases, a uniform blurring effect is desirable and
299+
> > this kind of asymmetric blurring should be avoided.
300+
> > However, it can be helpful in specific circumstances e.g. when noise is present in
301+
> > your image in a particular pattern or orientation, such as vertical lines,
302+
> > or when you want to
303+
> > [remove uniform noise without blurring edges present in the image in a particular orientation](https://www.researchgate.net/publication/228567435_An_edge_detection_algorithm_based_on_rectangular_Gaussian_kernels_for_machine_vision_applications).
304+
> >
305+
> >
288306
> {: .solution}
289307
{: .challenge}
290308

0 commit comments

Comments
 (0)