-
Notifications
You must be signed in to change notification settings - Fork 13
/
build_reference_table.py
43 lines (35 loc) · 1.22 KB
/
build_reference_table.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
40
41
42
43
#!/usr/bin/env python
__author__ = "Adeel Ahmad"
__email__ = "adeelahmad14@hotmail.com"
__status__ = "Production"
import numpy as np
from scipy.ndimage import convolve
from skimage import io
import matplotlib.pyplot as plt
def buildRefTable(img):
"""
builds the reference table for the given input template image
:param im: input binary image
:return:
table = a reconstructed reference table...
"""
table = [[0 for x in range(1)] for y in range(90)] # creating a empty list
# r will be calculated corresponding to this point
img_center = [int(img.shape[0]/2), int(img.shape[1]/2)]
def findAngleDistance(x1, y1):
x2, y2 = img_center[0], img_center[1]
r = [(x2-x1), (y2-y1)]
if (x2-x1 != 0):
return [int(np.rad2deg(np.arctan(int((y2-y1)/(x2-x1))))), r]
else:
return [0, 0]
filter_size = 3
for x in range(img.shape[0]-(filter_size-1)):
for y in range(img.shape[1]-(filter_size-1)):
if (img[x, y] != 0):
theta, r = findAngleDistance(x, y)
if (r != 0):
table[np.absolute(theta)].append(r)
for i in range(len(table)):
table[i].pop(0)
return table