Skip to content

Commit

Permalink
Add solutions for part 02 (#8)
Browse files Browse the repository at this point in the history
* Add solutions for part 02

* Tweak solution
  • Loading branch information
lagru authored Aug 26, 2024
1 parent 35856fd commit 989ab90
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tutorial/02_image_filtering.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ Look up the documentation of `scipy.ndimage.convolve`. Apply the same convolutio
# Solution here
```

```python
%load solutions/02_exercise_1.py
```

<!-- #region slideshow={"slide_type": "slide"} -->
### A difference filter
<!-- #endregion -->
Expand Down Expand Up @@ -739,10 +743,18 @@ vertical_kernel.shape
# Solution here
```

```python
%load solutions/02_exercise_3a.py
```

```python
# Solution here
```

```python
%load solutions/02_exercise_3b.py
```

<!-- #region editable=true slideshow={"slide_type": "slide"} -->
### Sobel edge filter
<!-- #endregion -->
Expand Down
9 changes: 9 additions & 0 deletions tutorial/solutions/02_exercise_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Solution for exercise 1
import scipy as sp

smoothed_with_scipy = sp.ndimage.convolve(noisy_signal, mean_kernel11, mode="reflect")

fig, ax = plt.subplots()
ax.plot(smooth_signal11same, label="padding with zeros")
ax.plot(smoothed_with_scipy, label="mode reflect")
ax.legend()
9 changes: 9 additions & 0 deletions tutorial/solutions/02_exercise_3a.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Solution for exercise 3a
horiz_kernel = vertical_kernel.T

gradient_horiz = ndi.correlate(pixelated.astype(float),
horiz_kernel)

fig, ax = plt.subplots(ncols=2)
ax[0].imshow(gradient_vertical, cmap="gray");
ax[1].imshow(gradient_horiz, cmap="gray");
6 changes: 6 additions & 0 deletions tutorial/solutions/02_exercise_3b.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Solution for exercise 3b
gradient = np.sqrt(gradient_vertical**2 + gradient_horiz**2)

fig, ax = plt.subplots()
im = ax.imshow(gradient, cmap="gray");
fig.colorbar(im)

0 comments on commit 989ab90

Please sign in to comment.