|
1 #################################################################### |
|
2 # Predictive online PDPS for optical flow with known velocity field |
|
3 #################################################################### |
|
4 |
|
5 __precompile__() |
|
6 |
|
7 module AlgorithmZeroDual |
|
8 |
|
9 identifier = "pdps_known_zerodual" |
|
10 |
|
11 using Printf |
|
12 |
|
13 using AlgTools.Util |
|
14 import AlgTools.Iterate |
|
15 using ImageTools.Gradient |
|
16 |
|
17 using ..OpticalFlow: ImageSize, |
|
18 Image, |
|
19 pdflow! |
|
20 |
|
21 ######################### |
|
22 # Iterate initialisation |
|
23 ######################### |
|
24 |
|
25 function init_rest(x::Image) |
|
26 imdim=size(x) |
|
27 |
|
28 y = zeros(2, imdim...) |
|
29 Δx = copy(x) |
|
30 Δy = copy(y) |
|
31 x̄ = copy(x) |
|
32 |
|
33 return x, y, Δx, Δy, x̄ |
|
34 end |
|
35 |
|
36 function init_iterates(xinit::Image) |
|
37 return init_rest(copy(xinit)) |
|
38 end |
|
39 |
|
40 function init_iterates(dim::ImageSize) |
|
41 return init_rest(zeros(dim...)) |
|
42 end |
|
43 |
|
44 ############ |
|
45 # Algorithm |
|
46 ############ |
|
47 |
|
48 function solve( :: Type{DisplacementT}; |
|
49 dim :: ImageSize, |
|
50 iterate = AlgTools.simple_iterate, |
|
51 params::NamedTuple) where DisplacementT |
|
52 |
|
53 ################################ |
|
54 # Extract and set up parameters |
|
55 ################################ |
|
56 |
|
57 α, ρ = params.α, params.ρ |
|
58 R_K² = ∇₂_norm₂₂_est² |
|
59 γ = 1.0 |
|
60 Λ = params.Λ |
|
61 τ₀, σ₀ = params.τ₀, params.σ₀ |
|
62 |
|
63 τ = τ₀/γ |
|
64 @assert(1+γ*τ ≥ Λ) |
|
65 σ = σ₀*1/(τ*R_K²) |
|
66 |
|
67 println("Step length parameters: τ=$(τ), σ=$(σ)") |
|
68 |
|
69 ###################### |
|
70 # Initialise iterates |
|
71 ###################### |
|
72 |
|
73 x, y, Δx, Δy, x̄ = init_iterates(dim) |
|
74 init_data = (params.init == :data) |
|
75 |
|
76 #################### |
|
77 # Run the algorithm |
|
78 #################### |
|
79 |
|
80 v = iterate(params) do verbose :: Function, |
|
81 b :: Image, |
|
82 v_known :: DisplacementT, |
|
83 🚫unused_b_next :: Image |
|
84 |
|
85 ################## |
|
86 # Prediction step |
|
87 ################## |
|
88 if init_data |
|
89 x .= b |
|
90 init_data = false |
|
91 end |
|
92 |
|
93 pdflow!(x, Δx, y, Δy, v_known, false) |
|
94 y .= zeros(size(y)...) |
|
95 |
|
96 ############ |
|
97 # PDPS step |
|
98 ############ |
|
99 |
|
100 ∇₂ᵀ!(Δx, y) # primal step: |
|
101 @. x̄ = x # | save old x for over-relax |
|
102 @. x = (x-τ*(Δx-b))/(1+τ) # | prox |
|
103 @. x̄ = 2x - x̄ # over-relax |
|
104 ∇₂!(Δy, x̄) # dual step: y |
|
105 @. y = (y + σ*Δy)/(1 + σ*ρ/α) # | |
|
106 proj_norm₂₁ball!(y, α) # | prox |
|
107 |
|
108 ################################ |
|
109 # Give function value if needed |
|
110 ################################ |
|
111 v = verbose() do |
|
112 ∇₂!(Δy, x) |
|
113 value = norm₂²(b-x)/2 + params.α*γnorm₂₁(Δy, params.ρ) |
|
114 value, x, [NaN, NaN], nothing |
|
115 end |
|
116 |
|
117 v |
|
118 end |
|
119 |
|
120 return x, y, v |
|
121 end |
|
122 |
|
123 end # Module |
|
124 |
|
125 |