-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathevolution.py
More file actions
132 lines (97 loc) · 3.88 KB
/
Copy pathevolution.py
File metadata and controls
132 lines (97 loc) · 3.88 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import numpy as np
from tqdm import tqdm
from v1diffusion import operators
def parallel_diffusion(u0, T, dt=0.1, beta=0.5, model=0, progress=True):
"""
Hypoelliptic evolution in PTR2 according to Boscain-2016
This method takes an input an image lifted in PTR2 and applies the
hypoelliptic heat operator \Delta_H at time intervals of dt until final time
T is reached
u0: image in PTR2
T: time to run the evolution
dt: time interval
beta: weight coefficient
progress: to either show or not tqdm animated progress bar
@returns: an image in PTR2
"""
u1 = u0 #Initialization of u1 in case the loop is not ran
t = 0
for _step in tqdm(range(0, int(T/dt)), disable=(not progress)):
u1 = u1+dt*operators.hypoelliptic_heat_operator(u1, beta, model)
t += dt
return np.asarray(u1)
def orthogonal_diffusion(u0, T, dt=0.1, beta=0.5, model=0, progress=True):
u1 = u0.copy() #Initialization of u1 in case the loop is not ran
t = 0
for _step in tqdm(range(0, int(T/dt)), disable=(not progress)):
u1 = u1+dt*operators.orthogonal_operator(u1, beta, model)
t += dt
return u1
def parallel_concentration(u0, T, dt=0.01, beta=0.5, model=0, progress=True):
"""
Handler function to regress the hypoelliptic evolution with negative dt
"""
u1 = u0 #Initialization of u1 in case the loop is not ran
t = 0
for _step in tqdm(range(0, int(T/dt)), disable=(not progress)):
u1 = u1-dt*operators.hypoelliptic_heat_operator(u1, beta, model)
t += dt
return np.asarray(u1)
def orthogonal_concentration(u0, T, dt=0.01, beta=0.5, model=0, progress=True):
"""
Handler function to regress the hypoelliptic evolution with negative dt
"""
u1 = u0 #Initialization of u1 in case the loop is not ran
t = 0
for _step in tqdm(range(0, int(T/dt)), disable=(not progress)):
u1 = u1-dt*operators.orthogonal_operator(u1, beta, model)
t += dt
return np.asarray(u1)
def v1_unsharp_filter(u, C=1, T=1, beta=1, model=0):
"""
SE(2) unsharp filter as described in Ballerin-Grong-25, Section 4.3.
The image is blurred along X3 (orthogonal to level lines) by running
the forward orthogonal diffusion for time T. The blurred version is
then used as the "mask" in classical unsharp masking:
output = u + C * (u - u_blurred)
u: image in PTR2/SE2
C: sharpening factor (C=0 → no change, C=1 → standard unsharp)
T: diffusion time (controls blur radius)
beta: weight coefficient for the X2 component
"""
u_blurred = orthogonal_diffusion(u, T, beta=beta, model=model)
return u + C * (u - u_blurred)
def evolve_vc_hypoelliptic(u0, img, T, a0=1, b0=1, a1=1, b1=1, sigma=1,
epss=0.1, dt=0.1, progress=True):
r"""
Hypoelliptic evolution with varying coefficients in PTR2
This method takes an input an image lifted in PTR2 and applies
the hypoelliptic heat operator \Delta_H with varying coefficients
at time intervals of dt until final time T is reached
u0: image in PTR2
img: the original 2D greyscale image
T: time to run the evolution
a0: starting weight
b0: starting weight
a1: starting weight
a2: starting weight
sigma: weight
epss: weight
dt: time interval
progress: to either show or not tqdm animated progress bar
@returns: an image in PTR2
"""
u1 = u0.copy() #Initialization of u1 in case the loop is not ran
eps = np.exp(-img**2/sigma)
t = 0
for _step in tqdm(range(0, int(T/dt)), disable=(not progress)):
a = np.zeros(img.shape)
b = np.zeros(img.shape)
a_mask = (a0+a1*eps)/(a0+a1)>epss
b_mask = (b0+b1*eps)/(b0+b1)>epss
a[a_mask] = a0 + a1*eps[a_mask]
b[b_mask] = b0 + b1*eps[b_mask]
u1 = u0+dt*operators.vc_hypoelliptic_heat_operator(u0, a, b)
u0 = u1.copy()
t+=dt
return u1