-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathFBL_threaded.py
55 lines (37 loc) · 1.74 KB
/
FBL_threaded.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
from utils import *
import numpy as np
smoothed_image = 0
def FBL(image, etf, iterations = 1):
global smoothed_image
size = image.shape
smoothed_image = image
for i in range(iterations):
H3 = np.zeros(size)
for h in range(size[0]):
print_progress('FBL S',h,size[0])
for w in range(size[1]):
total_weight = 0
ang = angle(etf[h][w][0],etf[h][w][1])
pix = flow_neighbour(ang*180/np.pi)
for j in range(-5,6):
if h + pix[0]*j < 0 or h + pix[0]*j >= size[0] or w + pix[1]*j < 0 or w + pix[1]*j >= size[1]: continue
H3[h][w] += smoothed_image[h+pix[0]*j][w+pix[1]*j]*gaussian(abs(j),sig_spatial)*intensity_weight(smoothed_image[h][w],smoothed_image[h+pix[0]*j][w+pix[1]*j],sig_intensity1)
total_weight += gaussian(abs(j),sig_spatial)*intensity_weight(smoothed_image[h][w],smoothed_image[h+pix[0]*j][w+pix[1]*j],sig_intensity1)
H3[h][w] /= total_weight
print ("")
smoothed_image = np.zeros(size)
for h in range(size[0]):
print_progress('FBL T',h,size[0])
for w in range(size[1]):
total_weight = 0
angle_perpendicular = (angle(etf[h][w][0],etf[h][w][1]) + np.pi/2)
if angle_perpendicular > 2*np.pi:
angle_perpendicular -= 2*np.pi
pix = flow_neighbour(angle_perpendicular*180/np.pi)
for j in range(-5,6):
if h + pix[0]*j < 0 or h + pix[0]*j >= size[0] or w + pix[1]*j < 0 or w + pix[1]*j >= size[1]: continue
smoothed_image[h][w] += H3[h+pix[0]*j][w+pix[1]*j]*gaussian(abs(j),sig_spatial)*intensity_weight(H3[h][w],H3[h+pix[0]*j][w+pix[1]*j],sig_intensity2)
total_weight += gaussian(abs(j),sig_spatial)*intensity_weight(H3[h][w],H3[h+pix[0]*j][w+pix[1]*j],sig_intensity2)
smoothed_image[h][w] /= total_weight
print("")
return smoothed_image