Sun, 21 Apr 2024 13:43:18 +0300
added zero dual in PET
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
1 | __precompile__() |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
2 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
3 | module PET |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
4 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
5 | ######################## |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
6 | # Load external modules |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
7 | ######################## |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
8 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
9 | using Printf |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
10 | using FileIO |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
11 | #using JLD2 |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
12 | using Setfield |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
13 | using ImageQualityIndexes: assess_psnr, assess_ssim |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
14 | using DelimitedFiles |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
15 | import GR |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
16 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
17 | using AlgTools.Util |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
18 | using AlgTools.StructTools |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
19 | using AlgTools.LinkedLists |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
20 | using AlgTools.Comms |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
21 | using ImageTools.Visualise: secs_ns, grayimg, do_visualise |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
22 | using ImageTools.ImFilter: gaussian |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
23 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
24 | # For PET |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
25 | #using Colors |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
26 | #using ColorTypes |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
27 | using ColorSchemes |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
28 | #using PerceptualColourMaps |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
29 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
30 | ##################### |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
31 | # Load local modules |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
32 | ##################### |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
33 | include("OpticalFlow.jl") |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
34 | include("Radon.jl") |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
35 | include("ImGenerate.jl") |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
36 | include("AlgorithmDualScaling.jl") |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
37 | include("AlgorithmGreedy.jl") |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
38 | include("AlgorithmNoPrediction.jl") |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
39 | include("AlgorithmPrimalOnly.jl") |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
40 | include("AlgorithmProximal.jl") |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
41 | include("AlgorithmRotation.jl") |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
42 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
43 | using .Radon |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
44 | using .ImGenerate |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
45 | using .OpticalFlow |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
46 | using .AlgorithmDualScaling |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
47 | using .AlgorithmGreedy |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
48 | using .AlgorithmNoPrediction |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
49 | using .AlgorithmPrimalOnly |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
50 | using .AlgorithmProximal |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
51 | using .AlgorithmRotation |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
52 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
53 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
54 | ############## |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
55 | # Our exports |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
56 | ############## |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
57 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
58 | export demo_pet1, demo_pet2, demo_pet3, demo_pet4, demo_pet5, demo_pet6, batchrun_pet |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
59 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
60 | ################################### |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
61 | # Parameterisation and experiments |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
62 | ################################### |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
63 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
64 | struct Experiment |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
65 | mod :: Module |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
66 | DisplacementT :: Type |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
67 | imgen :: ImGen |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
68 | params :: NamedTuple |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
69 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
70 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
71 | function Base.show(io::IO, e::Experiment) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
72 | displacementname(::Type{DisplacementFull}) = "DisplacementFull" |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
73 | displacementname(::Type{DisplacementConstant}) = "DisplacementConstant" |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
74 | print(io, " |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
75 | mod: $(e.mod) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
76 | DisplacementT: $(displacementname(e.DisplacementT)) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
77 | imgen: $(e.imgen.name) $(e.imgen.dim[1])×$(e.imgen.dim[2]) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
78 | params: $(e.params ⬿ (kernel = "(not shown)",)) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
79 | ") |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
80 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
81 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
82 | const default_save_prefix="img/" |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
83 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
84 | const default_params = ( |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
85 | ρ = 0, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
86 | verbose_iter = 100, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
87 | maxiter = 4000, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
88 | save_results = true, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
89 | save_images = true, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
90 | save_images_iters = Set([100, 200, 300, 500, 800, 1000, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
91 | 1300, 1500, 1800, 2000, 4000]), |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
92 | pixelwise_displacement=false, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
93 | dual_flow = true, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
94 | prox_predict = true, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
95 | handle_interrupt = true, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
96 | init = :zero, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
97 | plot_movement = false, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
98 | ) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
99 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
100 | const p_known₀_pet = ( |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
101 | noise_level = 0.5, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
102 | shake_noise_level = 0.1, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
103 | shake = 1.0, |
14
c286925c0f35
Change rand to randn in PET
Neil Dizon <neil.dizon@helsinki.fi>
parents:
11
diff
changeset
|
104 | rotation_factor = 0.075, |
15
befb8d5125cd
added stable interval for PET
Neil Dizon <neil.dizon@helsinki.fi>
parents:
14
diff
changeset
|
105 | rotation_noise_level = 0.00075, |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
106 | α = 1.0, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
107 | ρ̃₀ = 1.0, |
11 | 108 | σ̃₀ = 1.0, |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
109 | δ = 0.9, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
110 | σ₀ = 0.5, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
111 | τ₀ = 0.9, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
112 | λ = 1, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
113 | origsize = 256, |
15
befb8d5125cd
added stable interval for PET
Neil Dizon <neil.dizon@helsinki.fi>
parents:
14
diff
changeset
|
114 | radondims = [128,64], |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
115 | sz = (256,256), |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
116 | scale = 1, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
117 | c = 1.0, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
118 | sino_sparsity = 0.5, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
119 | L = 300.0, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
120 | L_experiment = false, |
15
befb8d5125cd
added stable interval for PET
Neil Dizon <neil.dizon@helsinki.fi>
parents:
14
diff
changeset
|
121 | stable_interval = union(Set(1500:200),Set(3500:4000)), |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
122 | ) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
123 | |
14
c286925c0f35
Change rand to randn in PET
Neil Dizon <neil.dizon@helsinki.fi>
parents:
11
diff
changeset
|
124 | const petscan = imgen_shepplogan_radon(p_known₀_pet.sz) |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
125 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
126 | const pet_experiments_pdps_known = ( |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
127 | Experiment(AlgorithmDualScaling, DisplacementConstant, petscan, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
128 | p_known₀_pet), |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
129 | Experiment(AlgorithmGreedy, DisplacementConstant, petscan, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
130 | p_known₀_pet), |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
131 | Experiment(AlgorithmNoPrediction, DisplacementConstant, petscan, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
132 | p_known₀_pet), |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
133 | Experiment(AlgorithmPrimalOnly, DisplacementConstant, petscan, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
134 | p_known₀_pet), |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
135 | Experiment(AlgorithmProximal, DisplacementConstant, petscan, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
136 | p_known₀_pet ⬿ (phantom_ρ = 100,)), |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
137 | Experiment(AlgorithmRotation, DisplacementConstant, petscan, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
138 | p_known₀_pet), |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
139 | ) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
140 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
141 | const pet_experiments_all = Iterators.flatten(( |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
142 | pet_experiments_pdps_known, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
143 | )) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
144 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
145 | ################ |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
146 | # Log |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
147 | ################ |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
148 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
149 | struct LogEntry <: IterableStruct |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
150 | iter :: Int |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
151 | time :: Float64 |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
152 | function_value :: Float64 |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
153 | #v_cumul_true_y :: Float64 |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
154 | #v_cumul_true_x :: Float64 |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
155 | #v_cumul_est_y :: Float64 |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
156 | #v_cumul_est_x :: Float64 |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
157 | psnr :: Float64 |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
158 | ssim :: Float64 |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
159 | #psnr_data :: Float64 |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
160 | #ssim_data :: Float64 |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
161 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
162 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
163 | struct LogEntryHiFi <: IterableStruct |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
164 | iter :: Int |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
165 | v_cumul_true_y :: Float64 |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
166 | v_cumul_true_x :: Float64 |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
167 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
168 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
169 | ############### |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
170 | # Main routine |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
171 | ############### |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
172 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
173 | struct State |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
174 | vis :: Union{Channel,Bool,Nothing} |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
175 | start_time :: Union{Real,Nothing} |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
176 | wasted_time :: Real |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
177 | log :: LinkedList{LogEntry} |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
178 | log_hifi :: LinkedList{LogEntryHiFi} |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
179 | aborted :: Bool |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
180 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
181 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
182 | function name(e::Experiment, p) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
183 | ig = e.imgen |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
184 | # return "$(ig.name)_$(e.mod.identifier)_$(@sprintf "%x" hash(p))" |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
185 | return "$(ig.name)_$(e.mod.identifier)_$(Int64(10000*p.σ₀))_$(Int64(10000*p.τ₀))" |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
186 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
187 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
188 | function write_tex(texfile, e_params) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
189 | open(texfile, "w") do io |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
190 | wp = (n, v) -> println(io, "\\def\\EXPPARAM$(n){$(v)}") |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
191 | wf = (n, s) -> if isdefined(e_params, s) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
192 | wp(n, getfield(e_params, s)) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
193 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
194 | wf("alpha", :α) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
195 | wf("sigmazero", :σ₀) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
196 | wf("tauzero", :τ₀) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
197 | wf("tildetauzero", :τ̃₀) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
198 | wf("delta", :δ) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
199 | wf("lambda", :λ) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
200 | wf("theta", :θ) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
201 | wf("maxiter", :maxiter) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
202 | wf("noiselevel", :noise_level) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
203 | wf("shakenoiselevel", :shake_noise_level) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
204 | wf("shake", :shake) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
205 | wf("timestep", :timestep) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
206 | wf("displacementcount", :displacementcount) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
207 | wf("phantomrho", :phantom_ρ) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
208 | if isdefined(e_params, :σ₀) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
209 | wp("sigma", (e_params.σ₀ == 1 ? "" : "$(e_params.σ₀)") * "\\sigma_{\\max}") |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
210 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
211 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
212 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
213 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
214 | function run_experiments(;visualise=true, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
215 | recalculate=true, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
216 | experiments, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
217 | save_prefix=default_save_prefix, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
218 | fullscreen=false, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
219 | kwargs...) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
220 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
221 | # Create visualisation |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
222 | if visualise |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
223 | rc = Channel(1) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
224 | visproc = Threads.@spawn bg_visualise_enhanced(rc, fullscreen=fullscreen) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
225 | bind(rc, visproc) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
226 | vis = rc |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
227 | else |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
228 | vis = false |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
229 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
230 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
231 | # Run all experiments |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
232 | for e ∈ experiments |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
233 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
234 | # Parameters for this experiment |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
235 | e_params = default_params ⬿ e.params ⬿ kwargs |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
236 | ename = name(e, e_params) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
237 | e_params = e_params ⬿ (save_prefix = save_prefix * ename, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
238 | dynrange = e.imgen.dynrange, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
239 | Λ = e.imgen.Λ) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
240 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
241 | if recalculate || !isfile(e_params.save_prefix * ".txt") |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
242 | println("Running experiment \"$(ename)\"") |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
243 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
244 | # Start data generation task |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
245 | datachannel = Channel{PetOnlineData{e.DisplacementT}}(2) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
246 | gentask = Threads.@spawn e.imgen.f(e.DisplacementT, datachannel, e_params) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
247 | bind(datachannel, gentask) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
248 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
249 | # Run algorithm |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
250 | iterate = curry(iterate_visualise, datachannel, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
251 | State(vis, nothing, 0.0, nothing, nothing, false)) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
252 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
253 | x, y, st = e.mod.solve(e.DisplacementT; |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
254 | dim=e.imgen.dim, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
255 | iterate=iterate, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
256 | params=e_params) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
257 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
258 | # Clear non-saveable things |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
259 | st = @set st.vis = nothing |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
260 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
261 | println("Wasted_time: $(st.wasted_time)s") |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
262 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
263 | if e_params.save_results |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
264 | println("Saving " * e_params.save_prefix * "(.txt,_hifi.txt,_params.tex)") |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
265 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
266 | perffile = e_params.save_prefix * ".txt" |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
267 | hififile = e_params.save_prefix * "_hifi.txt" |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
268 | texfile = e_params.save_prefix * "_params.tex" |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
269 | # datafile = e_params.save_prefix * ".jld2" |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
270 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
271 | write_log(perffile, st.log, "# params = $(e_params)\n") |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
272 | write_log(hififile, st.log_hifi, "# params = $(e_params)\n") |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
273 | write_tex(texfile, e_params) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
274 | # @save datafile x y st params |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
275 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
276 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
277 | close(datachannel) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
278 | wait(gentask) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
279 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
280 | if st.aborted |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
281 | break |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
282 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
283 | else |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
284 | println("Skipping already computed experiment \"$(ename)\"") |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
285 | # texfile = e_params.save_prefix * "_params.tex" |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
286 | # write_tex(texfile, e_params) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
287 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
288 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
289 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
290 | if visualise |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
291 | # Tell subprocess to finish, and wait |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
292 | put!(rc, nothing) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
293 | close(rc) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
294 | wait(visproc) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
295 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
296 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
297 | return |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
298 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
299 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
300 | ####################### |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
301 | # Demos and batch runs |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
302 | ####################### |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
303 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
304 | function demo(experiment; kwargs...) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
305 | run_experiments(;experiments=(experiment,), |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
306 | save_results=false, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
307 | save_images=false, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
308 | visualise=true, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
309 | recalculate=true, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
310 | verbose_iter=1, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
311 | fullscreen=true, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
312 | kwargs...) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
313 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
314 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
315 | demo_pet1 = () -> demo(pet_experiments_pdps_known[1]) # Dual scaling |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
316 | demo_pet2 = () -> demo(pet_experiments_pdps_known[2]) # Greedy |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
317 | demo_pet3 = () -> demo(pet_experiments_pdps_known[3]) # No Prediction |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
318 | demo_pet4 = () -> demo(pet_experiments_pdps_known[4]) # Primal only |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
319 | demo_pet5 = () -> demo(pet_experiments_pdps_known[5]) # Proximal (old) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
320 | demo_pet6 = () -> demo(pet_experiments_pdps_known[6]) # Rotation |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
321 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
322 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
323 | function batchrun_pet(kwargs...) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
324 | run_experiments(;experiments=pet_experiments_all, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
325 | save_results=true, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
326 | save_images=true, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
327 | visualise=false, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
328 | recalculate=false, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
329 | kwargs...) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
330 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
331 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
332 | ###################################################### |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
333 | # Iterator that does visualisation and log collection |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
334 | ###################################################### |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
335 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
336 | function rescale(arr, new_range) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
337 | old_min = minimum(arr) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
338 | old_max = maximum(arr) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
339 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
340 | scale_factor = (new_range[2] - new_range[1]) / (old_max - old_min) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
341 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
342 | scaled_arr = new_range[1] .+ (arr .- old_min) * scale_factor |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
343 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
344 | return scaled_arr |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
345 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
346 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
347 | function iterate_visualise(datachannel::Channel{PetOnlineData{DisplacementT}}, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
348 | st :: State, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
349 | step :: Function, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
350 | params :: NamedTuple) where DisplacementT |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
351 | try |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
352 | sc = nothing |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
353 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
354 | d = take!(datachannel) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
355 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
356 | for iter=1:params.maxiter |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
357 | dnext = take!(datachannel) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
358 | st = step(d.sinogram_noisy, d.v, d.theta, d.b_true, d.S) do calc_objective |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
359 | stn = st |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
360 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
361 | if isnothing(stn.start_time) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
362 | # The Julia precompiler is a miserable joke, apparently not crossing module |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
363 | # boundaries, so only start timing after the first iteration. |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
364 | stn = @set stn.start_time=secs_ns() |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
365 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
366 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
367 | verb = params.verbose_iter!=0 && mod(iter, params.verbose_iter) == 0 |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
368 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
369 | # Normalise movement to image dimensions so |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
370 | # our TikZ plotting code doesn't need to know |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
371 | # the image pixel size. |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
372 | sc = 1.0./maximum(size(d.b_true)) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
373 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
374 | if verb || iter ≤ 20 || (iter ≤ 200 && mod(iter, 10) == 0) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
375 | verb_start = secs_ns() |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
376 | tm = verb_start - stn.start_time - stn.wasted_time |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
377 | value, x, v, vhist = calc_objective() |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
378 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
379 | entry = LogEntry(iter, tm, value, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
380 | #sc*d.v_cumul_true[1], |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
381 | #sc*d.v_cumul_true[2], |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
382 | #sc*v[1], sc*v[2], |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
383 | assess_psnr(x, d.b_true), |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
384 | assess_ssim(x, d.b_true), |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
385 | #assess_psnr(d.b_noisy, d.b_true), |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
386 | #assess_ssim(d.b_noisy, d.b_true) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
387 | ) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
388 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
389 | # (**) Collect a singly-linked list of log to avoid array resizing |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
390 | # while iterating |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
391 | stn = @set stn.log=LinkedListEntry(entry, stn.log) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
392 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
393 | if !isnothing(vhist) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
394 | vhist=vhist.*sc |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
395 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
396 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
397 | if verb |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
398 | @printf("%d/%d J=%f, PSNR=%f, SSIM=%f, avg. FPS=%f\n", |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
399 | iter, params.maxiter, value, entry.psnr, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
400 | entry.ssim, entry.iter/entry.time) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
401 | if isa(stn.vis, Channel) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
402 | put_onlylatest!(stn.vis, ((rescale(backproject!(d.b_true,d.sinogram_noisy),(0.0,params.dynrange)), x), |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
403 | params.plot_movement, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
404 | stn.log, vhist)) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
405 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
406 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
407 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
408 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
409 | if params.save_images && (!haskey(params, :save_images_iters) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
410 | || iter ∈ params.save_images_iters) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
411 | fn = (t, ext) -> "$(params.save_prefix)_$(t)_frame$(iter).$(ext)" |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
412 | normalise = (data) -> data./maximum(data) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
413 | # save(File(format"PNG", fn("true", "png")), mapped_img(d.b_true, ColorSchemes.cmyk.colors[1:end])) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
414 | # save(File(format"PNG", fn("true_sinogram", "png")), mapped_img(normalise(d.sinogram_true), ColorSchemes.cmyk.colors[1:end])) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
415 | # save(File(format"PNG", fn("data_sinogram", "png")), mapped_img(normalise(d.S.*d.sinogram_noisy), ColorSchemes.cmyk.colors[1:end])) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
416 | save(File(format"PNG", fn("reco", "png")), mapped_img(x, ColorSchemes.cmyk.colors[1:end])) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
417 | if !isnothing(vhist) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
418 | open(fn("movement", "txt"), "w") do io |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
419 | writedlm(io, ["est_y" "est_x"]) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
420 | writedlm(io, vhist) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
421 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
422 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
423 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
424 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
425 | stn = @set stn.wasted_time += (secs_ns() - verb_start) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
426 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
427 | return stn |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
428 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
429 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
430 | hifientry = LogEntryHiFi(iter, sc*d.v_cumul_true[1], sc*d.v_cumul_true[2]) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
431 | st = @set st.log_hifi=LinkedListEntry(hifientry, st.log_hifi) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
432 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
433 | return st |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
434 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
435 | d=dnext |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
436 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
437 | catch ex |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
438 | if params.handle_interrupt && isa(ex, InterruptException) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
439 | # If SIGINT is received (user pressed ^C), terminate computations, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
440 | # returning current status. Effectively, we do not call `step()` again, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
441 | # ending the iterations, but letting the algorithm finish up. |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
442 | # Assuming (**) above occurs atomically, `st.log` should be valid, but |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
443 | # any results returned by the algorithm itself may be partial, as for |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
444 | # reasons of efficiency we do *not* store results of an iteration until |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
445 | # the next iteration is finished. |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
446 | printstyled("\rUser interrupt—finishing up.\n", bold=true, color=202) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
447 | st = @set st.aborted = true |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
448 | else |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
449 | rethrow(ex) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
450 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
451 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
452 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
453 | return st |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
454 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
455 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
456 | function bg_visualise_enhanced(rc; fullscreen=false) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
457 | process_channel(rc) do d |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
458 | imgs, plot_movement, log, vhist = d |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
459 | do_visualise(imgs, refresh=false, fullscreen=fullscreen) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
460 | # Overlay movement |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
461 | GR.settextcolorind(5) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
462 | GR.setcharheight(0.015) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
463 | GR.settextpath(GR.TEXT_PATH_RIGHT) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
464 | tx, ty = GR.wctondc(0, 1) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
465 | GR.text(tx, ty, @sprintf "FPS %.1f, SSIM %.2f, PSNR %.1f" (log.value.iter/log.value.time) log.value.ssim log.value.psnr) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
466 | if plot_movement |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
467 | sc=1.0 |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
468 | p=unfold_linked_list(log) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
469 | x=map(e -> 1.5+sc*e.v_cumul_true_x, p) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
470 | y=map(e -> 0.5+sc*e.v_cumul_true_y, p) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
471 | GR.setlinewidth(2) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
472 | GR.setlinecolorind(2) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
473 | GR.polyline(x, y) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
474 | x=map(e -> 1.5+sc*e.v_cumul_est_x, p) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
475 | y=map(e -> 0.5+sc*e.v_cumul_est_y, p) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
476 | GR.setlinecolorind(3) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
477 | GR.polyline(x, y) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
478 | if vhist != nothing |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
479 | GR.setlinecolorind(4) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
480 | x=map(v -> 1.5+sc*v, vhist[:,2]) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
481 | y=map(v -> 0.5+sc*v, vhist[:,1]) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
482 | GR.polyline(x, y) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
483 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
484 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
485 | GR.updatews() |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
486 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
487 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
488 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
489 | # Clip image values to allowed range |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
490 | clip = x -> min(max(x, 0.0), 1.0) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
491 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
492 | # Apply a colourmap (vector of RGB objects) to raw image data |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
493 | function mapped_img(im, cmap) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
494 | l = length(cmap) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
495 | apply = t -> cmap[1+round(UInt16, clip(t) * (l-1))] |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
496 | return apply.(im) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
497 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
498 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
499 | ############### |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
500 | # Precompiling |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
501 | ############### |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
502 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
503 | # precompile(Tuple{typeof(GR.drawimage), Float64, Float64, Float64, Float64, Int64, Int64, Array{UInt32, 2}}) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
504 | # precompile(Tuple{Type{Plots.Plot{T} where T<:RecipesBase.AbstractBackend}, Plots.GRBackend, Int64, Base.Dict{Symbol, Any}, Base.Dict{Symbol, Any}, Array{Plots.Series, 1}, Nothing, Array{Plots.Subplot{T} where T<:RecipesBase.AbstractBackend, 1}, Base.Dict{Any, Plots.Subplot{T} where T<:RecipesBase.AbstractBackend}, Plots.EmptyLayout, Array{Plots.Subplot{T} where T<:RecipesBase.AbstractBackend, 1}, Bool}) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
505 | # precompile(Tuple{typeof(Plots._plot!), Plots.Plot{Plots.GRBackend}, Base.Dict{Symbol, Any}, Tuple{Array{ColorTypes.Gray{Float64}, 2}}}) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
506 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
507 | end # Module |