Browse code
initial version
fiddlerwoaroof authored on 23/05/2016 23:36:00
Showing 1 changed files
Showing 1 changed files
... | ... |
@@ -0,0 +1,16 @@ |
1 |
+import numpy as np |
|
2 |
+from PIL import Image, ImageOps |
|
3 |
+from scipy import ndimage |
|
4 |
+ |
|
5 |
+sobel_kernel = np.array([ |
|
6 |
+ [-1, 0, 1], |
|
7 |
+ [-2, 0, 2], |
|
8 |
+ [-1, 0, 1], |
|
9 |
+]) |
|
10 |
+ |
|
11 |
+def sobel(arr): |
|
12 |
+ return ndimage.convolve(arr, sobel_kernel, mode=constant) |
|
13 |
+ |
|
14 |
+def sobel_image(img): |
|
15 |
+ img = np.array(img) |
|
16 |
+ return Image.fromarray(sobel(img)) |