src/PET/PET.jl

Fri, 03 May 2024 14:37:45 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Fri, 03 May 2024 14:37:45 -0500
changeset 61
d10ea0811650
parent 52
cb029cdb141a
child 66
dc69a0d234ae
permissions
-rw-r--r--

Proper quote marks in README

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
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
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
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
29 #####################a
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
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
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
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
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
37 using ..Radon: backproject!
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
38 using ..ImGenerate
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
39 using ..OpticalFlow
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
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
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
48 export demo_petS1, demo_petS2, demo_petS3,
18
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
49 demo_petS4, demo_petS5, demo_petS6, demo_petS7,
36
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
50 demo_petB1, demo_petB2, demo_petB3,
18
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
51 demo_petB4, demo_petB5, demo_petB6, demo_petB7,
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
c9b06736a477 added fv_plot
Neil Dizon <neil.dizon@helsinki.fi>
parents: 23
diff changeset
67 save_images_iters = Set([100, 300, 500, 800, 1000,
c9b06736a477 added fv_plot
Neil Dizon <neil.dizon@helsinki.fi>
parents: 23
diff changeset
68 1300, 1500, 1800, 2000,
c9b06736a477 added fv_plot
Neil Dizon <neil.dizon@helsinki.fi>
parents: 23
diff changeset
69 2300, 2500, 2800, 3000,
c9b06736a477 added fv_plot
Neil Dizon <neil.dizon@helsinki.fi>
parents: 23
diff changeset
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
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
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
75116ad1d2e6 seed number changed
Neil Dizon <neil.dizon@helsinki.fi>
parents: 28
diff changeset
82 shake_noise_level = 0.25,
36
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
83 shake = 1.0,
39
Tuomo Valkonen <tuomov@iki.fi>
parents: 36 38
diff changeset
84 rotation_factor = 0.15,
Tuomo Valkonen <tuomov@iki.fi>
parents: 36 38
diff changeset
85 rotation_noise_level = 0.035,
45
21909e22f875 Fix default α
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
86 α = 0.25,
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
87 ρ̃₀ = 1.0,
11
97e9c745a000 update params
Neil Dizon <neil.dizon@helsinki.fi>
parents: 8
diff changeset
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
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
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
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
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
Tuomo Valkonen <tuomov@iki.fi>
parents: 36 38
diff changeset
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
Tuomo Valkonen <tuomov@iki.fi>
parents: 36 38
diff changeset
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
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
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
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
113 Experiment(AlgorithmNew, DisplacementConstant, shepplogan,
39
Tuomo Valkonen <tuomov@iki.fi>
parents: 36 38
diff changeset
114 p_known₀_pets ⬿ (predictor=Greedy(),)),
36
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
115 Experiment(AlgorithmNew, DisplacementConstant, shepplogan,
39
Tuomo Valkonen <tuomov@iki.fi>
parents: 36 38
diff changeset
116 p_known₀_pets ⬿ (predictor=nothing,),),
36
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
117 Experiment(AlgorithmNew, DisplacementConstant, shepplogan,
39
Tuomo Valkonen <tuomov@iki.fi>
parents: 36 38
diff changeset
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
Tuomo Valkonen <tuomov@iki.fi>
parents: 36 38
diff changeset
120 p_known₀_pets ⬿ (phantom_ρ = 100,)),
36
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
121 Experiment(AlgorithmNew, DisplacementConstant, shepplogan,
39
Tuomo Valkonen <tuomov@iki.fi>
parents: 36 38
diff changeset
122 p_known₀_pets ⬿ (predictor=Rotation(),)),
36
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
123 Experiment(AlgorithmNew, DisplacementConstant, shepplogan,
39
Tuomo Valkonen <tuomov@iki.fi>
parents: 36 38
diff changeset
124 p_known₀_pets ⬿ (predictor=ZeroDual(),)),
50
b413b7df8cd6 remove activated dual
Neil Dizon <neil.dizon@helsinki.fi>
parents: 47
diff changeset
125 # Experiment(AlgorithmNew, DisplacementConstant, shepplogan,
b413b7df8cd6 remove activated dual
Neil Dizon <neil.dizon@helsinki.fi>
parents: 47
diff changeset
126 # p_known₀_pets ⬿ (predictor=ActivatedDual(),)),
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
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
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
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
132 Experiment(AlgorithmNew, DisplacementConstant, brainphantom,
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
133 p_known₀_petb ⬿ (predictor=Greedy(),)),
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
134 Experiment(AlgorithmNew, DisplacementConstant, brainphantom,
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
135 p_known₀_petb ⬿ (predictor=nothing,),),
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
136 Experiment(AlgorithmNew, DisplacementConstant, brainphantom,
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
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
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
139 p_known₀_petb ⬿ (phantom_ρ = 100,)),
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
140 Experiment(AlgorithmNew, DisplacementConstant, brainphantom,
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
141 p_known₀_petb ⬿ (predictor=Rotation(),)),
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
142 Experiment(AlgorithmNew, DisplacementConstant, brainphantom,
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
143 p_known₀_petb ⬿ (predictor=ZeroDual(),)),
50
b413b7df8cd6 remove activated dual
Neil Dizon <neil.dizon@helsinki.fi>
parents: 47
diff changeset
144 # Experiment(AlgorithmNew, DisplacementConstant, brainphantom,
b413b7df8cd6 remove activated dual
Neil Dizon <neil.dizon@helsinki.fi>
parents: 47
diff changeset
145 # p_known₀_petb ⬿ (predictor=ActivatedDual(),)),
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
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
163 save_prefix=default_save_prefix,
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
164 visfn=iterate_visualise_pet,
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
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
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
182
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
183 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
184 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
185 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
186 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
187 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
188 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
189 demo_petB7 = () -> demo(brainphantom_experiments_pdps_known[7]) # Zero dual
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
190
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
191
28
f7c1007f0127 added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents: 27
diff changeset
192 function batchrun_shepplogan(;kwargs...)
18
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
193 run_experiments(;experiments=shepplogan_experiments_all,
36
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
194 visfn=iterate_visualise_pet,
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
195 datatype=PetOnlineData,
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
196 save_prefix=default_save_prefix,
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
197 save_results=true,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
198 save_images=true,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
199 visualise=false,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
200 recalculate=false,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
201 kwargs...)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
202 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
203
28
f7c1007f0127 added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents: 27
diff changeset
204 function batchrun_brainphantom(;kwargs...)
18
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
205 run_experiments(;experiments=brainphantom_experiments_all,
36
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
206 visfn=iterate_visualise_pet,
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
207 datatype=PetOnlineData,
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
208 save_prefix=default_save_prefix,
18
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
209 save_results=true,
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
210 save_images=true,
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
211 visualise=false,
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
212 recalculate=false,
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
213 kwargs...)
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
214 end
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
215
28
f7c1007f0127 added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents: 27
diff changeset
216 function batchrun_pet(;kwargs...)
f7c1007f0127 added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents: 27
diff changeset
217 batchrun_shepplogan(;kwargs...)
f7c1007f0127 added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents: 27
diff changeset
218 batchrun_brainphantom(;kwargs...)
18
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
219 end
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
220
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
221 ######################################################
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
222 # Iterator that does visualisation and log collection
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
223 ######################################################
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 function rescale(arr, new_range)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
226 old_min = minimum(arr)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
227 old_max = maximum(arr)
36
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
228 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
229 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
230 return scaled_arr
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
231 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
232
36
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
233 function iterate_visualise_pet(datachannel::Channel{PetOnlineData{DisplacementT}},
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
234 st :: State,
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
235 step :: Function,
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
236 params :: NamedTuple) where DisplacementT
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
237 try
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
238 sc = nothing
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
239
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
240 d = take!(datachannel)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
241
36
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
242 for iter=1:params.maxiter
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
243 dnext = take!(datachannel)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
244 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
245 stn = st
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
246
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
247 if isnothing(stn.start_time)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
248 # 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
249 # boundaries, so only start timing after the first iteration.
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
250 stn = @set stn.start_time=secs_ns()
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
251 end
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 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
254
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
255 # Normalise movement to image dimensions so
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
256 # our TikZ plotting code doesn't need to know
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
257 # the image pixel size.
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
258 sc = 1.0./maximum(size(d.b_true))
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
259
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
260 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
261 verb_start = secs_ns()
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
262 tm = verb_start - stn.start_time - stn.wasted_time
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
263 value, x, v, vhist = calc_objective()
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
264
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
265 entry = LogEntry(iter, tm, value,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
266 #sc*d.v_cumul_true[1],
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
267 #sc*d.v_cumul_true[2],
36
e4a8f662a1ac Reduce code duplication.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
268 #sc*v[1], sc*v[2],
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
269 assess_psnr(x, d.b_true),
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
270 assess_ssim(x, d.b_true),
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
271 #assess_psnr(d.b_noisy, d.b_true),
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
272 #assess_ssim(d.b_noisy, d.b_true)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
273 )
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
274
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
275 # (**) 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
276 # while iterating
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
277 stn = @set stn.log=LinkedListEntry(entry, stn.log)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
278
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
279 if !isnothing(vhist)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
280 vhist=vhist.*sc
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
281 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
282
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
283 if verb
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
284 @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
285 iter, params.maxiter, value, entry.psnr,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
286 entry.ssim, entry.iter/entry.time)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
287 if isa(stn.vis, Channel)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
288 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
289 params.plot_movement,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
290 stn.log, vhist))
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
291
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
292 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
293 end
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 if params.save_images && (!haskey(params, :save_images_iters)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
296 || iter ∈ params.save_images_iters)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
297 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
298 normalise = (data) -> data./maximum(data)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
299 # 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
300 # 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
301 # 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
302 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
303 if !isnothing(vhist)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
304 open(fn("movement", "txt"), "w") do io
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
305 writedlm(io, ["est_y" "est_x"])
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
306 writedlm(io, vhist)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
307 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
308 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
309 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
310
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
311 stn = @set stn.wasted_time += (secs_ns() - verb_start)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
312
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
313 return stn
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
314 end
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 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
317 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
318
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
319 return st
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
320 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
321 d=dnext
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
322 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
323 catch ex
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
324 if params.handle_interrupt && isa(ex, InterruptException)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
325 # If SIGINT is received (user pressed ^C), terminate computations,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
326 # 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
327 # ending the iterations, but letting the algorithm finish up.
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
328 # 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
329 # 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
330 # 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
331 # the next iteration is finished.
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
332 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
333 st = @set st.aborted = true
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
334 else
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
335 rethrow(ex)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
336 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
337 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
338
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
339 return st
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 # Clip image values to allowed range
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
343 clip = x -> min(max(x, 0.0), 1.0)
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 # 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
346 function mapped_img(im, cmap)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
347 l = length(cmap)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
348 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
349 return apply.(im)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
350 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
351
18
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
352
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
353 #########################
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
354 # Plotting SSIM and PSNR
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
34
aca9c90f151c Reduce dependencies; separate Stats from PlotResults (disabled by default to avoid heavy deps)
Tuomo Valkonen <tuomov@iki.fi>
parents: 28
diff changeset
357 #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
358 # 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
359 # 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
360 # 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
361 # 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
362 # 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
363 # 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
364 #end
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
365
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
366 end # Module

mercurial