-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutils.py
55 lines (42 loc) · 1.24 KB
/
utils.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
44
45
46
47
48
49
50
51
52
53
54
55
import numpy as np
import itertools
import networkx
import time
import os
import pickle
from config import COLOUR_RGB_MAP, INTENSITY_NORMALIZATION
def xy_array(array):
if len(array.shape) == 2:
return array
ny, nx, m = array.shape
print(f'(ny, nx, m) ={array.shape}')
result = np.zeros([ny, nx])
for i in range(ny):
for j in range(nx):
square_intensity = 0
for k in range(m-1):
square_intensity += array[i][j][k] ** 2
result[i][j] = np.sqrt(square_intensity)/INTENSITY_NORMALIZATION
return result
def weight(g, h, beta):
arg = -(g-h)*(g-h)*beta
return np.exp(arg)
def get_neighbour_pixels(x, y, nx, ny):
neighbours = []
for pixel in [(x, y-1), (x-1, y)]:
u, v = pixel
if u >= 0 and v >= 0:
neighbours.append((u, v))
return neighbours
def get_ordered_nodelist(nodes_list, seeds_list):
for seed in seeds_list[::-1]:
nodes_list.insert(0, nodes_list.pop(nodes_list.index(seed)))
return nodes_list
def gaussian(g, h, beta):
arg = -(g-h)*(g-h)*beta
return np.exp(arg)
def pixel_norm_2(pixel):
norm = 0
for i in pixel:
norm += i**2
return np.sqrt(norm)/INTENSITY_NORMALIZATION