Thu, 04 Jul 2024 03:09:56 +1000
modified rotation and added new strict tv preserving predictor
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 |
36 | 21 | using ImageTools.Visualise: secs_ns, grayimg, do_visualise |
8
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 ColorSchemes |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
26 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
27 | ##################### |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
28 | # Load local modules |
36 | 29 | #####################a |
30 | include("AlgorithmNew.jl") | |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
31 | include("AlgorithmProximal.jl") |
34
aca9c90f151c
Reduce dependencies; separate Stats from PlotResults (disabled by default to avoid heavy deps)
Tuomo Valkonen <tuomov@iki.fi>
parents:
28
diff
changeset
|
32 | #include("PlotResults.jl") |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
33 | |
36 | 34 | import .AlgorithmNew |
23
1c4b7d1f261f
added plotting functions
Neil Dizon <neil.dizon@helsinki.fi>
parents:
22
diff
changeset
|
35 | import .AlgorithmProximal |
1c4b7d1f261f
added plotting functions
Neil Dizon <neil.dizon@helsinki.fi>
parents:
22
diff
changeset
|
36 | |
36 | 37 | using ..Radon: backproject! |
38 | using ..ImGenerate | |
39 | using ..OpticalFlow | |
40 | using ..Run | |
34
aca9c90f151c
Reduce dependencies; separate Stats from PlotResults (disabled by default to avoid heavy deps)
Tuomo Valkonen <tuomov@iki.fi>
parents:
28
diff
changeset
|
41 | #using .PlotResults |
8
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 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
44 | ############## |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
45 | # Our exports |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
46 | ############## |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
47 | |
36 | 48 | export demo_petS1, demo_petS2, demo_petS3, |
66
dc69a0d234ae
modified rotation and added new strict tv preserving predictor
Neil Dizon <neil.dizon@helsinki.fi>
parents:
52
diff
changeset
|
49 | demo_petS4, demo_petS5, demo_petS6, demo_petS7, demo_petS8, |
36 | 50 | demo_petB1, demo_petB2, demo_petB3, |
66
dc69a0d234ae
modified rotation and added new strict tv preserving predictor
Neil Dizon <neil.dizon@helsinki.fi>
parents:
52
diff
changeset
|
51 | demo_petB4, demo_petB5, demo_petB6, demo_petB7, demo_petB8, |
34
aca9c90f151c
Reduce dependencies; separate Stats from PlotResults (disabled by default to avoid heavy deps)
Tuomo Valkonen <tuomov@iki.fi>
parents:
28
diff
changeset
|
52 | batchrun_shepplogan, batchrun_brainphantom, batchrun_pet |
aca9c90f151c
Reduce dependencies; separate Stats from PlotResults (disabled by default to avoid heavy deps)
Tuomo Valkonen <tuomov@iki.fi>
parents:
28
diff
changeset
|
53 | #plot_pet |
8
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 | ################################### |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
56 | # Parameterisation and experiments |
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 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
59 | const default_save_prefix="img/" |
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 | const default_params = ( |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
62 | ρ = 0, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
63 | verbose_iter = 100, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
64 | maxiter = 4000, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
65 | save_results = true, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
66 | save_images = true, |
25 | 67 | save_images_iters = Set([100, 300, 500, 800, 1000, |
68 | 1300, 1500, 1800, 2000, | |
69 | 2300, 2500, 2800, 3000, | |
70 | 3300, 3500, 3800, 4000]), | |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
71 | pixelwise_displacement=false, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
72 | dual_flow = true, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
73 | prox_predict = true, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
74 | handle_interrupt = true, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
75 | init = :zero, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
76 | plot_movement = false, |
28
f7c1007f0127
added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents:
27
diff
changeset
|
77 | stable_interval = Set(0), |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
78 | ) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
79 | |
36 | 80 | const p_known₀_pet = default_params ⬿ ( |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
81 | noise_level = 0.5, |
38 | 82 | shake_noise_level = 0.25, |
36 | 83 | shake = 1.0, |
39 | 84 | rotation_factor = 0.15, |
85 | rotation_noise_level = 0.035, | |
45 | 86 | α = 0.25, |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
87 | ρ̃₀ = 1.0, |
11 | 88 | σ̃₀ = 1.0, |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
89 | δ = 0.9, |
28
f7c1007f0127
added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents:
27
diff
changeset
|
90 | σ₀ = 1.0, |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
91 | τ₀ = 0.9, |
36 | 92 | λ = 1, |
15
befb8d5125cd
added stable interval for PET
Neil Dizon <neil.dizon@helsinki.fi>
parents:
14
diff
changeset
|
93 | radondims = [128,64], |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
94 | sz = (256,256), |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
95 | scale = 1, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
96 | c = 1.0, |
36 | 97 | sino_sparsity = 0.5, |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
98 | L = 300.0, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
99 | L_experiment = false, |
28
f7c1007f0127
added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents:
27
diff
changeset
|
100 | #stable_interval = Set(0), |
f7c1007f0127
added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents:
27
diff
changeset
|
101 | stable_interval = union(Set(1000:2000),Set(3500:4000)), |
18
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
102 | ) |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
103 | |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
104 | const shepplogan = imgen_shepplogan_radon(p_known₀_pet.sz) |
39 | 105 | const p_known₀_pets = p_known₀_pet ⬿ ( seed = 314159, ) |
18
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
106 | |
39 | 107 | const p_known₀_petb = p_known₀_pet ⬿ ( seed = 9182737465, ) |
18
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
108 | const brainphantom = imgen_brainphantom_radon(p_known₀_pet.sz) |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
109 | |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
110 | const shepplogan_experiments_pdps_known = ( |
36 | 111 | Experiment(AlgorithmNew, DisplacementConstant, shepplogan, |
52
cb029cdb141a
activation function for dual scscaling
Neil Dizon <neil.dizon@helsinki.fi>
parents:
50
diff
changeset
|
112 | p_known₀_pets ⬿ (predictor=DualScaling(x -> (1/(1 + exp(-1000(x - 0.05)))), 1.0, 1e-12),)), |
36 | 113 | Experiment(AlgorithmNew, DisplacementConstant, shepplogan, |
39 | 114 | p_known₀_pets ⬿ (predictor=Greedy(),)), |
36 | 115 | Experiment(AlgorithmNew, DisplacementConstant, shepplogan, |
39 | 116 | p_known₀_pets ⬿ (predictor=nothing,),), |
36 | 117 | Experiment(AlgorithmNew, DisplacementConstant, shepplogan, |
39 | 118 | p_known₀_pets ⬿ (predictor=PrimalOnly(),)), |
18
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
119 | Experiment(AlgorithmProximal, DisplacementConstant, shepplogan, |
39 | 120 | p_known₀_pets ⬿ (phantom_ρ = 100,)), |
36 | 121 | Experiment(AlgorithmNew, DisplacementConstant, shepplogan, |
39 | 122 | p_known₀_pets ⬿ (predictor=Rotation(),)), |
36 | 123 | Experiment(AlgorithmNew, DisplacementConstant, shepplogan, |
39 | 124 | p_known₀_pets ⬿ (predictor=ZeroDual(),)), |
66
dc69a0d234ae
modified rotation and added new strict tv preserving predictor
Neil Dizon <neil.dizon@helsinki.fi>
parents:
52
diff
changeset
|
125 | Experiment(AlgorithmNew, DisplacementConstant, shepplogan, |
dc69a0d234ae
modified rotation and added new strict tv preserving predictor
Neil Dizon <neil.dizon@helsinki.fi>
parents:
52
diff
changeset
|
126 | p_known₀_pets ⬿ (predictor=StrictGreedy(),)), |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
127 | ) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
128 | |
18
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
129 | const brainphantom_experiments_pdps_known = ( |
36 | 130 | Experiment(AlgorithmNew, DisplacementConstant, brainphantom, |
52
cb029cdb141a
activation function for dual scscaling
Neil Dizon <neil.dizon@helsinki.fi>
parents:
50
diff
changeset
|
131 | p_known₀_petb ⬿ (predictor=DualScaling(x -> (-abs(x-1)^1/5 + 1), 0.75, 1e-12),)), |
36 | 132 | Experiment(AlgorithmNew, DisplacementConstant, brainphantom, |
133 | p_known₀_petb ⬿ (predictor=Greedy(),)), | |
134 | Experiment(AlgorithmNew, DisplacementConstant, brainphantom, | |
135 | p_known₀_petb ⬿ (predictor=nothing,),), | |
136 | Experiment(AlgorithmNew, DisplacementConstant, brainphantom, | |
137 | p_known₀_petb ⬿ (predictor=PrimalOnly(),)), | |
18
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
138 | Experiment(AlgorithmProximal, DisplacementConstant, brainphantom, |
36 | 139 | p_known₀_petb ⬿ (phantom_ρ = 100,)), |
140 | Experiment(AlgorithmNew, DisplacementConstant, brainphantom, | |
141 | p_known₀_petb ⬿ (predictor=Rotation(),)), | |
142 | Experiment(AlgorithmNew, DisplacementConstant, brainphantom, | |
143 | p_known₀_petb ⬿ (predictor=ZeroDual(),)), | |
66
dc69a0d234ae
modified rotation and added new strict tv preserving predictor
Neil Dizon <neil.dizon@helsinki.fi>
parents:
52
diff
changeset
|
144 | Experiment(AlgorithmNew, DisplacementConstant, brainphantom, |
dc69a0d234ae
modified rotation and added new strict tv preserving predictor
Neil Dizon <neil.dizon@helsinki.fi>
parents:
52
diff
changeset
|
145 | p_known₀_petb ⬿ (predictor=StrictGreedy(),)), |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
146 | ) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
147 | |
18
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
148 | |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
149 | const shepplogan_experiments_all = Iterators.flatten(( |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
150 | shepplogan_experiments_pdps_known, |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
151 | )) |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
152 | |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
153 | const brainphantom_experiments_all = Iterators.flatten(( |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
154 | brainphantom_experiments_pdps_known, |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
155 | )) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
156 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
157 | ####################### |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
158 | # Demos and batch runs |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
159 | ####################### |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
160 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
161 | function demo(experiment; kwargs...) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
162 | run_experiments(;experiments=(experiment,), |
36 | 163 | save_prefix=default_save_prefix, |
164 | visfn=iterate_visualise_pet, | |
165 | datatype=PetOnlineData, | |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
166 | save_results=false, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
167 | save_images=false, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
168 | visualise=true, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
169 | recalculate=true, |
28
f7c1007f0127
added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents:
27
diff
changeset
|
170 | verbose_iter=50, |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
171 | fullscreen=true, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
172 | kwargs...) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
173 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
174 | |
18
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
175 | demo_petS1 = () -> demo(shepplogan_experiments_pdps_known[1]) # Dual scaling |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
176 | demo_petS2 = () -> demo(shepplogan_experiments_pdps_known[2]) # Greedy |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
177 | demo_petS3 = () -> demo(shepplogan_experiments_pdps_known[3]) # No Prediction |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
178 | demo_petS4 = () -> demo(shepplogan_experiments_pdps_known[4]) # Primal only |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
179 | demo_petS5 = () -> demo(shepplogan_experiments_pdps_known[5]) # Proximal (old) |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
180 | demo_petS6 = () -> demo(shepplogan_experiments_pdps_known[6]) # Rotation |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
181 | demo_petS7 = () -> demo(shepplogan_experiments_pdps_known[7]) # Zero dual |
66
dc69a0d234ae
modified rotation and added new strict tv preserving predictor
Neil Dizon <neil.dizon@helsinki.fi>
parents:
52
diff
changeset
|
182 | demo_petS8 = () -> demo(shepplogan_experiments_pdps_known[8]) # StrictGreedy |
18
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
183 | |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
184 | demo_petB1 = () -> demo(brainphantom_experiments_pdps_known[1]) # Dual scaling |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
185 | demo_petB2 = () -> demo(brainphantom_experiments_pdps_known[2]) # Greedy |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
186 | demo_petB3 = () -> demo(brainphantom_experiments_pdps_known[3]) # No Prediction |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
187 | demo_petB4 = () -> demo(brainphantom_experiments_pdps_known[4]) # Primal only |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
188 | demo_petB5 = () -> demo(brainphantom_experiments_pdps_known[5]) # Proximal (old) |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
189 | demo_petB6 = () -> demo(brainphantom_experiments_pdps_known[6]) # Rotation |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
190 | demo_petB7 = () -> demo(brainphantom_experiments_pdps_known[7]) # Zero dual |
66
dc69a0d234ae
modified rotation and added new strict tv preserving predictor
Neil Dizon <neil.dizon@helsinki.fi>
parents:
52
diff
changeset
|
191 | demo_petB8 = () -> demo(brainphantom_experiments_pdps_known[8]) # StrictGreedy |
dc69a0d234ae
modified rotation and added new strict tv preserving predictor
Neil Dizon <neil.dizon@helsinki.fi>
parents:
52
diff
changeset
|
192 | |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
193 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
194 | |
28
f7c1007f0127
added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents:
27
diff
changeset
|
195 | function batchrun_shepplogan(;kwargs...) |
18
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
196 | run_experiments(;experiments=shepplogan_experiments_all, |
36 | 197 | visfn=iterate_visualise_pet, |
198 | datatype=PetOnlineData, | |
199 | save_prefix=default_save_prefix, | |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
200 | save_results=true, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
201 | save_images=true, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
202 | visualise=false, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
203 | recalculate=false, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
204 | kwargs...) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
205 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
206 | |
28
f7c1007f0127
added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents:
27
diff
changeset
|
207 | function batchrun_brainphantom(;kwargs...) |
18
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
208 | run_experiments(;experiments=brainphantom_experiments_all, |
36 | 209 | visfn=iterate_visualise_pet, |
210 | datatype=PetOnlineData, | |
211 | save_prefix=default_save_prefix, | |
18
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
212 | save_results=true, |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
213 | save_images=true, |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
214 | visualise=false, |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
215 | recalculate=false, |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
216 | kwargs...) |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
217 | end |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
218 | |
28
f7c1007f0127
added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents:
27
diff
changeset
|
219 | function batchrun_pet(;kwargs...) |
f7c1007f0127
added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents:
27
diff
changeset
|
220 | batchrun_shepplogan(;kwargs...) |
f7c1007f0127
added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents:
27
diff
changeset
|
221 | batchrun_brainphantom(;kwargs...) |
18
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
222 | end |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
223 | |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
224 | ###################################################### |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
225 | # Iterator that does visualisation and log collection |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
226 | ###################################################### |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
227 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
228 | function rescale(arr, new_range) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
229 | old_min = minimum(arr) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
230 | old_max = maximum(arr) |
36 | 231 | scale_factor = (new_range[2] - new_range[1]) / (old_max - old_min) |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
232 | 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
|
233 | return scaled_arr |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
234 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
235 | |
36 | 236 | function iterate_visualise_pet(datachannel::Channel{PetOnlineData{DisplacementT}}, |
237 | st :: State, | |
238 | step :: Function, | |
239 | params :: NamedTuple) where DisplacementT | |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
240 | try |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
241 | sc = nothing |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
242 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
243 | d = take!(datachannel) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
244 | |
36 | 245 | for iter=1:params.maxiter |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
246 | dnext = take!(datachannel) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
247 | 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
|
248 | stn = st |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
249 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
250 | if isnothing(stn.start_time) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
251 | # 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
|
252 | # boundaries, so only start timing after the first iteration. |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
253 | stn = @set stn.start_time=secs_ns() |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
254 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
255 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
256 | 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
|
257 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
258 | # Normalise movement to image dimensions so |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
259 | # our TikZ plotting code doesn't need to know |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
260 | # the image pixel size. |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
261 | sc = 1.0./maximum(size(d.b_true)) |
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 verb || iter ≤ 20 || (iter ≤ 200 && mod(iter, 10) == 0) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
264 | verb_start = secs_ns() |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
265 | tm = verb_start - stn.start_time - stn.wasted_time |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
266 | value, x, v, vhist = calc_objective() |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
267 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
268 | entry = LogEntry(iter, tm, value, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
269 | #sc*d.v_cumul_true[1], |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
270 | #sc*d.v_cumul_true[2], |
36 | 271 | #sc*v[1], sc*v[2], |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
272 | assess_psnr(x, d.b_true), |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
273 | assess_ssim(x, d.b_true), |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
274 | #assess_psnr(d.b_noisy, d.b_true), |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
275 | #assess_ssim(d.b_noisy, d.b_true) |
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 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
278 | # (**) 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
|
279 | # while iterating |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
280 | stn = @set stn.log=LinkedListEntry(entry, stn.log) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
281 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
282 | if !isnothing(vhist) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
283 | vhist=vhist.*sc |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
284 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
285 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
286 | if verb |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
287 | @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
|
288 | iter, params.maxiter, value, entry.psnr, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
289 | entry.ssim, entry.iter/entry.time) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
290 | if isa(stn.vis, Channel) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
291 | 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
|
292 | params.plot_movement, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
293 | stn.log, vhist)) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
294 | |
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 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
297 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
298 | if params.save_images && (!haskey(params, :save_images_iters) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
299 | || iter ∈ params.save_images_iters) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
300 | 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
|
301 | normalise = (data) -> data./maximum(data) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
302 | # 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
|
303 | # 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
|
304 | # 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
|
305 | 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
|
306 | if !isnothing(vhist) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
307 | open(fn("movement", "txt"), "w") do io |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
308 | writedlm(io, ["est_y" "est_x"]) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
309 | writedlm(io, vhist) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
310 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
311 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
312 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
313 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
314 | stn = @set stn.wasted_time += (secs_ns() - verb_start) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
315 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
316 | return stn |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
317 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
318 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
319 | 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
|
320 | 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
|
321 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
322 | return st |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
323 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
324 | d=dnext |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
325 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
326 | catch ex |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
327 | if params.handle_interrupt && isa(ex, InterruptException) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
328 | # If SIGINT is received (user pressed ^C), terminate computations, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
329 | # 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
|
330 | # ending the iterations, but letting the algorithm finish up. |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
331 | # 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
|
332 | # 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
|
333 | # 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
|
334 | # the next iteration is finished. |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
335 | 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
|
336 | st = @set st.aborted = true |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
337 | else |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
338 | rethrow(ex) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
339 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
340 | end |
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 | return st |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
343 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
344 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
345 | # Clip image values to allowed range |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
346 | clip = x -> min(max(x, 0.0), 1.0) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
347 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
348 | # 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
|
349 | function mapped_img(im, cmap) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
350 | l = length(cmap) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
351 | 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
|
352 | return apply.(im) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
353 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
354 | |
18
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
355 | |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
356 | ######################### |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
357 | # Plotting SSIM and PSNR |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
358 | ######################### |
e6a2ebaf467d
added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents:
15
diff
changeset
|
359 | |
34
aca9c90f151c
Reduce dependencies; separate Stats from PlotResults (disabled by default to avoid heavy deps)
Tuomo Valkonen <tuomov@iki.fi>
parents:
28
diff
changeset
|
360 | #function plot_pet(kwargs...) |
aca9c90f151c
Reduce dependencies; separate Stats from PlotResults (disabled by default to avoid heavy deps)
Tuomo Valkonen <tuomov@iki.fi>
parents:
28
diff
changeset
|
361 | # ssim_plot("shepplogan") |
aca9c90f151c
Reduce dependencies; separate Stats from PlotResults (disabled by default to avoid heavy deps)
Tuomo Valkonen <tuomov@iki.fi>
parents:
28
diff
changeset
|
362 | # psnr_plot("shepplogan") |
aca9c90f151c
Reduce dependencies; separate Stats from PlotResults (disabled by default to avoid heavy deps)
Tuomo Valkonen <tuomov@iki.fi>
parents:
28
diff
changeset
|
363 | # fv_plot("shepplogan") |
aca9c90f151c
Reduce dependencies; separate Stats from PlotResults (disabled by default to avoid heavy deps)
Tuomo Valkonen <tuomov@iki.fi>
parents:
28
diff
changeset
|
364 | # ssim_plot("brainphantom") |
aca9c90f151c
Reduce dependencies; separate Stats from PlotResults (disabled by default to avoid heavy deps)
Tuomo Valkonen <tuomov@iki.fi>
parents:
28
diff
changeset
|
365 | # psnr_plot("brainphantom") |
aca9c90f151c
Reduce dependencies; separate Stats from PlotResults (disabled by default to avoid heavy deps)
Tuomo Valkonen <tuomov@iki.fi>
parents:
28
diff
changeset
|
366 | # fv_plot("brainphantom") |
aca9c90f151c
Reduce dependencies; separate Stats from PlotResults (disabled by default to avoid heavy deps)
Tuomo Valkonen <tuomov@iki.fi>
parents:
28
diff
changeset
|
367 | #end |
8
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 | end # Module |