forked from przemekpastuszka/biometrics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsobel.py
31 lines (24 loc) · 864 Bytes
/
sobel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Metody biometryczne
# Przemyslaw Pastuszka
from PIL import Image, ImageFilter
from math import sqrt
import utils
sobelOperator = [[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]]
def merge_images(a, b, f):
result = a.copy()
result_load = result.load()
a_load = a.load()
b_load = b.load()
(x, y) = a.size
for i in range(0, x):
for j in range(0, y):
result_load[i, j] = f(a_load[i, j], b_load[i, j])
return result
def partial_sobels(im):
ySobel = im.filter(ImageFilter.Kernel((3, 3), utils.flatten(sobelOperator), 1))
xSobel = im.filter(ImageFilter.Kernel((3, 3), utils.flatten(utils.transpose(sobelOperator)), 1))
return (xSobel, ySobel)
def full_sobels(im):
(xSobel, ySobel) = partial_sobels(im)
sobel = merge_images(xSobel, ySobel, lambda x, y: sqrt(x**2 + y**2))
return (xSobel, ySobel, sobel)