forked from przemekpastuszka/biometrics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hough.py
39 lines (28 loc) · 929 Bytes
/
hough.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
32
33
34
35
36
37
38
39
# Metody biometryczne
# Przemyslaw Pastuszka
from PIL import Image, ImageDraw
import utils
import argparse
import math
def get_hough_image(im):
(x, y) = im.size
x *= 1.0
y *= 1.0
im_load = im.load()
result = Image.new("RGBA", im.size, 0)
draw = ImageDraw.Draw(result)
for i in range(0, im.size[0]):
for j in range(0, im.size[1]):
if im_load[i, j] > 220:
line = lambda t: (t, (-(i / x - 0.5) * (t / x) + (j / y - 0.5)) * x)
draw.line([line(0), line(x)], fill=(50, 0, 0, 10))
return result
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Hough transform")
parser.add_argument("image", nargs=1, help = "Path to image")
args = parser.parse_args()
im = Image.open(args.image[0])
im = im.convert("L") # covert to grayscale
im.show()
hough_img = get_hough_image(im)
hough_img.show()