src/PET/PET.jl

Wed, 24 Apr 2024 16:55:04 +0300

author
Neil Dizon <neil.dizon@helsinki.fi>
date
Wed, 24 Apr 2024 16:55:04 +0300
changeset 30
dec72b794b08
parent 28
f7c1007f0127
child 34
aca9c90f151c
child 38
75116ad1d2e6
permissions
-rw-r--r--

added img folder

8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
1 __precompile__()
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
2
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
3 module PET
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
4
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
5 ########################
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
6 # Load external modules
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
7 ########################
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
9 using Printf
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
10 using FileIO
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
11 #using JLD2
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
12 using Setfield
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
13 using ImageQualityIndexes: assess_psnr, assess_ssim
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
14 using DelimitedFiles
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
15 import GR
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
16
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
17 using AlgTools.Util
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
18 using AlgTools.StructTools
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
19 using AlgTools.LinkedLists
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
20 using AlgTools.Comms
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
21 using ImageTools.Visualise: secs_ns, grayimg, do_visualise
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
22 using ImageTools.ImFilter: gaussian
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
23
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
24 # For PET
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
25 using 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
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
29 #####################
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
30 include("OpticalFlow.jl")
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
31 include("Radon.jl")
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
32 include("ImGenerate.jl")
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
33 include("AlgorithmDualScaling.jl")
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
34 include("AlgorithmGreedy.jl")
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
35 include("AlgorithmNoPrediction.jl")
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
36 include("AlgorithmPrimalOnly.jl")
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
37 include("AlgorithmProximal.jl")
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
38 include("AlgorithmRotation.jl")
18
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
39 include("AlgorithmZeroDual.jl")
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
40 include("PlotResults.jl")
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
41
23
1c4b7d1f261f added plotting functions
Neil Dizon <neil.dizon@helsinki.fi>
parents: 22
diff changeset
42 import .AlgorithmDualScaling
1c4b7d1f261f added plotting functions
Neil Dizon <neil.dizon@helsinki.fi>
parents: 22
diff changeset
43 import .AlgorithmGreedy
1c4b7d1f261f added plotting functions
Neil Dizon <neil.dizon@helsinki.fi>
parents: 22
diff changeset
44 import .AlgorithmNoPrediction
1c4b7d1f261f added plotting functions
Neil Dizon <neil.dizon@helsinki.fi>
parents: 22
diff changeset
45 import .AlgorithmPrimalOnly
1c4b7d1f261f added plotting functions
Neil Dizon <neil.dizon@helsinki.fi>
parents: 22
diff changeset
46 import .AlgorithmProximal
1c4b7d1f261f added plotting functions
Neil Dizon <neil.dizon@helsinki.fi>
parents: 22
diff changeset
47 import .AlgorithmRotation
1c4b7d1f261f added plotting functions
Neil Dizon <neil.dizon@helsinki.fi>
parents: 22
diff changeset
48 import .AlgorithmZeroDual
1c4b7d1f261f added plotting functions
Neil Dizon <neil.dizon@helsinki.fi>
parents: 22
diff changeset
49
1c4b7d1f261f added plotting functions
Neil Dizon <neil.dizon@helsinki.fi>
parents: 22
diff changeset
50 using .Radon: backproject!
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
51 using .ImGenerate
23
1c4b7d1f261f added plotting functions
Neil Dizon <neil.dizon@helsinki.fi>
parents: 22
diff changeset
52 using .OpticalFlow: DisplacementFull, DisplacementConstant
18
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
53 using .PlotResults
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 ##############
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
57 # Our exports
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
18
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
60 export demo_petS1, demo_petS2, demo_petS3,
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
61 demo_petS4, demo_petS5, demo_petS6, demo_petS7,
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
62 demo_petB1, demo_petB2, demo_petB3,
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
63 demo_petB4, demo_petB5, demo_petB6, demo_petB7,
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
64 batchrun_shepplogan, batchrun_brainphantom, batchrun_pet,
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
65 plot_pet
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
66
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
67 ###################################
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
68 # Parameterisation and experiments
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
69 ###################################
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
70
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
71 struct Experiment
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
72 mod :: Module
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
73 DisplacementT :: Type
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
74 imgen :: ImGen
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
75 params :: NamedTuple
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
76 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
77
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
78 function Base.show(io::IO, e::Experiment)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
79 displacementname(::Type{DisplacementFull}) = "DisplacementFull"
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
80 displacementname(::Type{DisplacementConstant}) = "DisplacementConstant"
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
81 print(io, "
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
82 mod: $(e.mod)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
83 DisplacementT: $(displacementname(e.DisplacementT))
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
84 imgen: $(e.imgen.name) $(e.imgen.dim[1])×$(e.imgen.dim[2])
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
85 params: $(e.params ⬿ (kernel = "(not shown)",))
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
86 ")
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
87 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
88
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
89 const default_save_prefix="img/"
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
90
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
91 const default_params = (
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
92 ρ = 0,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
93 verbose_iter = 100,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
94 maxiter = 4000,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
95 save_results = true,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
96 save_images = true,
25
c9b06736a477 added fv_plot
Neil Dizon <neil.dizon@helsinki.fi>
parents: 23
diff changeset
97 save_images_iters = Set([100, 300, 500, 800, 1000,
c9b06736a477 added fv_plot
Neil Dizon <neil.dizon@helsinki.fi>
parents: 23
diff changeset
98 1300, 1500, 1800, 2000,
c9b06736a477 added fv_plot
Neil Dizon <neil.dizon@helsinki.fi>
parents: 23
diff changeset
99 2300, 2500, 2800, 3000,
c9b06736a477 added fv_plot
Neil Dizon <neil.dizon@helsinki.fi>
parents: 23
diff changeset
100 3300, 3500, 3800, 4000]),
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
101 pixelwise_displacement=false,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
102 dual_flow = true,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
103 prox_predict = true,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
104 handle_interrupt = true,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
105 init = :zero,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
106 plot_movement = false,
28
f7c1007f0127 added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents: 27
diff changeset
107 stable_interval = Set(0),
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
108 )
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
109
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
110 const p_known₀_pet = (
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
111 noise_level = 0.5,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
112 shake_noise_level = 0.1,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
113 shake = 1.0,
14
c286925c0f35 Change rand to randn in PET
Neil Dizon <neil.dizon@helsinki.fi>
parents: 11
diff changeset
114 rotation_factor = 0.075,
22
a30a8745a83b added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents: 19
diff changeset
115 rotation_noise_level = 0.0075,
28
f7c1007f0127 added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents: 27
diff changeset
116 α = 0.15,
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
117 ρ̃₀ = 1.0,
11
97e9c745a000 update params
Neil Dizon <neil.dizon@helsinki.fi>
parents: 8
diff changeset
118 σ̃₀ = 1.0,
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
119 δ = 0.9,
28
f7c1007f0127 added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents: 27
diff changeset
120 σ₀ = 1.0,
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
121 τ₀ = 0.9,
18
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
122 λ = 1,
15
befb8d5125cd added stable interval for PET
Neil Dizon <neil.dizon@helsinki.fi>
parents: 14
diff changeset
123 radondims = [128,64],
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
124 sz = (256,256),
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
125 scale = 1,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
126 c = 1.0,
28
f7c1007f0127 added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents: 27
diff changeset
127 sino_sparsity = 0.5,
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
128 L = 300.0,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
129 L_experiment = false,
28
f7c1007f0127 added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents: 27
diff changeset
130 #stable_interval = Set(0),
f7c1007f0127 added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents: 27
diff changeset
131 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
132 )
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
133
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
134 const shepplogan = imgen_shepplogan_radon(p_known₀_pet.sz)
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
135
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
136 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
137
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
138 const shepplogan_experiments_pdps_known = (
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
139 Experiment(AlgorithmDualScaling, DisplacementConstant, shepplogan,
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
140 p_known₀_pet),
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
141 Experiment(AlgorithmGreedy, DisplacementConstant, shepplogan,
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
142 p_known₀_pet),
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
143 Experiment(AlgorithmNoPrediction, DisplacementConstant, shepplogan,
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
144 p_known₀_pet),
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
145 Experiment(AlgorithmPrimalOnly, DisplacementConstant, shepplogan,
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
146 p_known₀_pet),
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
147 Experiment(AlgorithmProximal, DisplacementConstant, shepplogan,
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
148 p_known₀_pet ⬿ (phantom_ρ = 100,)),
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
149 Experiment(AlgorithmRotation, DisplacementConstant, shepplogan,
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
150 p_known₀_pet),
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
151 Experiment(AlgorithmZeroDual, DisplacementConstant, shepplogan,
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
152 p_known₀_pet),
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
153 )
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
154
18
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
155 const brainphantom_experiments_pdps_known = (
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
156 Experiment(AlgorithmDualScaling, DisplacementConstant, brainphantom,
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
157 p_known₀_pet),
18
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
158 Experiment(AlgorithmGreedy, DisplacementConstant, brainphantom,
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
159 p_known₀_pet),
18
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
160 Experiment(AlgorithmNoPrediction, DisplacementConstant, brainphantom,
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
161 p_known₀_pet),
18
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
162 Experiment(AlgorithmPrimalOnly, DisplacementConstant, brainphantom,
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
163 p_known₀_pet),
18
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
164 Experiment(AlgorithmProximal, DisplacementConstant, brainphantom,
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
165 p_known₀_pet ⬿ (phantom_ρ = 100,)),
18
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
166 Experiment(AlgorithmRotation, DisplacementConstant, brainphantom,
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
167 p_known₀_pet),
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
168 Experiment(AlgorithmZeroDual, DisplacementConstant, brainphantom,
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
169 p_known₀_pet),
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
170 )
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
171
18
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
172
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
173 const shepplogan_experiments_all = Iterators.flatten((
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
174 shepplogan_experiments_pdps_known,
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
175 ))
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
176
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
177 const brainphantom_experiments_all = Iterators.flatten((
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
178 brainphantom_experiments_pdps_known,
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
179 ))
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
180
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
181 ################
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
182 # Log
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
183 ################
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
184
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
185 struct LogEntry <: IterableStruct
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
186 iter :: Int
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
187 time :: Float64
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
188 function_value :: Float64
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
189 #v_cumul_true_y :: Float64
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
190 #v_cumul_true_x :: Float64
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
191 #v_cumul_est_y :: Float64
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
192 #v_cumul_est_x :: Float64
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
193 psnr :: Float64
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
194 ssim :: Float64
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
195 #psnr_data :: Float64
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
196 #ssim_data :: Float64
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
197 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
198
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
199 struct LogEntryHiFi <: IterableStruct
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
200 iter :: Int
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
201 v_cumul_true_y :: Float64
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
202 v_cumul_true_x :: Float64
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
203 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
204
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
205 ###############
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
206 # Main routine
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
207 ###############
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
208
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
209 struct State
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
210 vis :: Union{Channel,Bool,Nothing}
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
211 start_time :: Union{Real,Nothing}
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
212 wasted_time :: Real
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
213 log :: LinkedList{LogEntry}
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
214 log_hifi :: LinkedList{LogEntryHiFi}
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
215 aborted :: Bool
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
216 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
217
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
218 function name(e::Experiment, p)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
219 ig = e.imgen
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
220 # return "$(ig.name)_$(e.mod.identifier)_$(@sprintf "%x" hash(p))"
28
f7c1007f0127 added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents: 27
diff changeset
221 return "$(ig.name)_$(e.mod.identifier)_$(Int64(100*p.α))_$(Int64(10000*p.σ₀))_$(Int64(10000*p.τ₀))"
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
222 end
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 function write_tex(texfile, e_params)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
225 open(texfile, "w") do io
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
226 wp = (n, v) -> println(io, "\\def\\EXPPARAM$(n){$(v)}")
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
227 wf = (n, s) -> if isdefined(e_params, s)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
228 wp(n, getfield(e_params, s))
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
229 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
230 wf("alpha", :α)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
231 wf("sigmazero", :σ₀)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
232 wf("tauzero", :τ₀)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
233 wf("tildetauzero", :τ̃₀)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
234 wf("delta", :δ)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
235 wf("lambda", :λ)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
236 wf("theta", :θ)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
237 wf("maxiter", :maxiter)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
238 wf("noiselevel", :noise_level)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
239 wf("shakenoiselevel", :shake_noise_level)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
240 wf("shake", :shake)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
241 wf("timestep", :timestep)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
242 wf("displacementcount", :displacementcount)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
243 wf("phantomrho", :phantom_ρ)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
244 if isdefined(e_params, :σ₀)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
245 wp("sigma", (e_params.σ₀ == 1 ? "" : "$(e_params.σ₀)") * "\\sigma_{\\max}")
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
246 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
247 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
248 end
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 function run_experiments(;visualise=true,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
251 recalculate=true,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
252 experiments,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
253 save_prefix=default_save_prefix,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
254 fullscreen=false,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
255 kwargs...)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
256
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
257 # Create visualisation
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
258 if visualise
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
259 rc = Channel(1)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
260 visproc = Threads.@spawn bg_visualise_enhanced(rc, fullscreen=fullscreen)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
261 bind(rc, visproc)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
262 vis = rc
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
263 else
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
264 vis = false
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
265 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
266
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
267 # Run all experiments
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
268 for e ∈ experiments
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
269
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
270 # Parameters for this experiment
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
271 e_params = default_params ⬿ e.params ⬿ kwargs
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
272 ename = name(e, e_params)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
273 e_params = e_params ⬿ (save_prefix = save_prefix * ename,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
274 dynrange = e.imgen.dynrange,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
275 Λ = e.imgen.Λ)
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 if recalculate || !isfile(e_params.save_prefix * ".txt")
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
278 println("Running experiment \"$(ename)\"")
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
279
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
280 # Start data generation task
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
281 datachannel = Channel{PetOnlineData{e.DisplacementT}}(2)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
282 gentask = Threads.@spawn e.imgen.f(e.DisplacementT, datachannel, e_params)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
283 bind(datachannel, gentask)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
284
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
285 # Run algorithm
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
286 iterate = curry(iterate_visualise, datachannel,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
287 State(vis, nothing, 0.0, nothing, nothing, false))
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
288
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
289 x, y, st = e.mod.solve(e.DisplacementT;
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
290 dim=e.imgen.dim,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
291 iterate=iterate,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
292 params=e_params)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
293
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
294 # Clear non-saveable things
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
295 st = @set st.vis = nothing
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
296
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
297 println("Wasted_time: $(st.wasted_time)s")
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
298
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
299 if e_params.save_results
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
300 println("Saving " * e_params.save_prefix * "(.txt,_hifi.txt,_params.tex)")
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
301
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
302 perffile = e_params.save_prefix * ".txt"
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
303 hififile = e_params.save_prefix * "_hifi.txt"
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
304 texfile = e_params.save_prefix * "_params.tex"
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
305 # datafile = e_params.save_prefix * ".jld2"
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
306
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
307 write_log(perffile, st.log, "# params = $(e_params)\n")
28
f7c1007f0127 added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents: 27
diff changeset
308 #write_log(hififile, st.log_hifi, "# params = $(e_params)\n")
f7c1007f0127 added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents: 27
diff changeset
309 #write_tex(texfile, e_params)
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
310 # @save datafile x y st params
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
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
313 close(datachannel)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
314 wait(gentask)
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 if st.aborted
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
317 break
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
318 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
319 else
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
320 println("Skipping already computed experiment \"$(ename)\"")
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
321 # texfile = e_params.save_prefix * "_params.tex"
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
322 # write_tex(texfile, e_params)
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 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
325
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
326 if visualise
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
327 # Tell subprocess to finish, and wait
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
328 put!(rc, nothing)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
329 close(rc)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
330 wait(visproc)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
331 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
332
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
333 return
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
334 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
335
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
336 #######################
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
337 # Demos and batch runs
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
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
340 function demo(experiment; kwargs...)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
341 run_experiments(;experiments=(experiment,),
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
342 save_results=false,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
343 save_images=false,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
344 visualise=true,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
345 recalculate=true,
28
f7c1007f0127 added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents: 27
diff changeset
346 verbose_iter=50,
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
347 fullscreen=true,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
348 kwargs...)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
349 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
350
18
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
351 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
352 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
353 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
354 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
355 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
356 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
357 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
358
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
359 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
360 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
361 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
362 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
363 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
364 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
365 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
366
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
367
28
f7c1007f0127 added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents: 27
diff changeset
368 function batchrun_shepplogan(;kwargs...)
18
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
369 run_experiments(;experiments=shepplogan_experiments_all,
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
370 save_results=true,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
371 save_images=true,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
372 visualise=false,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
373 recalculate=false,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
374 kwargs...)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
375 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
376
28
f7c1007f0127 added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents: 27
diff changeset
377 function batchrun_brainphantom(;kwargs...)
18
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
378 run_experiments(;experiments=brainphantom_experiments_all,
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
379 save_results=true,
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
380 save_images=true,
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
381 visualise=false,
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
382 recalculate=false,
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
383 kwargs...)
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
384 end
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
385
28
f7c1007f0127 added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents: 27
diff changeset
386 function batchrun_pet(;kwargs...)
f7c1007f0127 added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents: 27
diff changeset
387 batchrun_shepplogan(;kwargs...)
f7c1007f0127 added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents: 27
diff changeset
388 batchrun_brainphantom(;kwargs...)
18
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
389 end
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
390
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
391 ######################################################
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
392 # Iterator that does visualisation and log collection
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
393 ######################################################
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
394
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
395 function rescale(arr, new_range)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
396 old_min = minimum(arr)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
397 old_max = maximum(arr)
18
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
398 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
399 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
400 return scaled_arr
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
401 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
402
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
403 function iterate_visualise(datachannel::Channel{PetOnlineData{DisplacementT}},
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
404 st :: State,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
405 step :: Function,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
406 params :: NamedTuple) where DisplacementT
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
407 try
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
408 sc = nothing
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
409
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
410 d = take!(datachannel)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
411
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
412 for iter=1:params.maxiter
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
413 dnext = take!(datachannel)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
414 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
415 stn = st
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
416
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
417 if isnothing(stn.start_time)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
418 # 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
419 # boundaries, so only start timing after the first iteration.
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
420 stn = @set stn.start_time=secs_ns()
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
421 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
422
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
423 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
424
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
425 # Normalise movement to image dimensions so
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
426 # our TikZ plotting code doesn't need to know
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
427 # the image pixel size.
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
428 sc = 1.0./maximum(size(d.b_true))
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
429
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
430 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
431 verb_start = secs_ns()
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
432 tm = verb_start - stn.start_time - stn.wasted_time
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
433 value, x, v, vhist = calc_objective()
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
434
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
435 entry = LogEntry(iter, tm, value,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
436 #sc*d.v_cumul_true[1],
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
437 #sc*d.v_cumul_true[2],
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
438 #sc*v[1], sc*v[2],
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
439 assess_psnr(x, d.b_true),
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
440 assess_ssim(x, d.b_true),
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
441 #assess_psnr(d.b_noisy, d.b_true),
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
442 #assess_ssim(d.b_noisy, d.b_true)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
443 )
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
444
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
445 # (**) 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
446 # while iterating
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
447 stn = @set stn.log=LinkedListEntry(entry, stn.log)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
448
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
449 if !isnothing(vhist)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
450 vhist=vhist.*sc
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
451 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
452
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
453 if verb
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
454 @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
455 iter, params.maxiter, value, entry.psnr,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
456 entry.ssim, entry.iter/entry.time)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
457 if isa(stn.vis, Channel)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
458 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
459 params.plot_movement,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
460 stn.log, vhist))
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
461
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
462 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
463 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
464
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
465 if params.save_images && (!haskey(params, :save_images_iters)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
466 || iter ∈ params.save_images_iters)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
467 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
468 normalise = (data) -> data./maximum(data)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
469 # 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
470 # 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
471 # 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
472 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
473 if !isnothing(vhist)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
474 open(fn("movement", "txt"), "w") do io
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
475 writedlm(io, ["est_y" "est_x"])
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
476 writedlm(io, vhist)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
477 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
478 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
479 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
480
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
481 stn = @set stn.wasted_time += (secs_ns() - verb_start)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
482
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
483 return stn
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
484 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
485
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
486 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
487 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
488
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
489 return st
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
490 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
491 d=dnext
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
492 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
493 catch ex
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
494 if params.handle_interrupt && isa(ex, InterruptException)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
495 # If SIGINT is received (user pressed ^C), terminate computations,
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
496 # 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
497 # ending the iterations, but letting the algorithm finish up.
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
498 # 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
499 # 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
500 # 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
501 # the next iteration is finished.
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
502 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
503 st = @set st.aborted = true
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
504 else
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
505 rethrow(ex)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
506 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
507 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
508
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
509 return st
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
510 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
511
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
512 function bg_visualise_enhanced(rc; fullscreen=false)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
513 process_channel(rc) do d
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
514 imgs, plot_movement, log, vhist = d
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
515 do_visualise(imgs, refresh=false, fullscreen=fullscreen)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
516 # Overlay movement
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
517 GR.settextcolorind(5)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
518 GR.setcharheight(0.015)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
519 GR.settextpath(GR.TEXT_PATH_RIGHT)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
520 tx, ty = GR.wctondc(0, 1)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
521 GR.text(tx, ty, @sprintf "FPS %.1f, SSIM %.2f, PSNR %.1f" (log.value.iter/log.value.time) log.value.ssim log.value.psnr)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
522 if plot_movement
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
523 sc=1.0
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
524 p=unfold_linked_list(log)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
525 x=map(e -> 1.5+sc*e.v_cumul_true_x, p)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
526 y=map(e -> 0.5+sc*e.v_cumul_true_y, p)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
527 GR.setlinewidth(2)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
528 GR.setlinecolorind(2)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
529 GR.polyline(x, y)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
530 x=map(e -> 1.5+sc*e.v_cumul_est_x, p)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
531 y=map(e -> 0.5+sc*e.v_cumul_est_y, p)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
532 GR.setlinecolorind(3)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
533 GR.polyline(x, y)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
534 if vhist != nothing
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
535 GR.setlinecolorind(4)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
536 x=map(v -> 1.5+sc*v, vhist[:,2])
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
537 y=map(v -> 0.5+sc*v, vhist[:,1])
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
538 GR.polyline(x, y)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
539 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
540 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
541 GR.updatews()
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
542 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
543 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
544
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
545 # Clip image values to allowed range
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
546 clip = x -> min(max(x, 0.0), 1.0)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
547
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
548 # 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
549 function mapped_img(im, cmap)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
550 l = length(cmap)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
551 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
552 return apply.(im)
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
553 end
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
554
18
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
555
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
556 #########################
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
557 # Plotting SSIM and PSNR
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
558 #########################
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
559
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
560 function plot_pet(kwargs...)
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
561 ssim_plot("shepplogan")
25
c9b06736a477 added fv_plot
Neil Dizon <neil.dizon@helsinki.fi>
parents: 23
diff changeset
562 psnr_plot("shepplogan")
c9b06736a477 added fv_plot
Neil Dizon <neil.dizon@helsinki.fi>
parents: 23
diff changeset
563 fv_plot("shepplogan")
18
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
564 ssim_plot("brainphantom")
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
565 psnr_plot("brainphantom")
25
c9b06736a477 added fv_plot
Neil Dizon <neil.dizon@helsinki.fi>
parents: 23
diff changeset
566 fv_plot("brainphantom")
18
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
567 end
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
568
e6a2ebaf467d added data generation for new phantom
Neil Dizon <neil.dizon@helsinki.fi>
parents: 15
diff changeset
569
8
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
570 ###############
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
571 # Precompiling
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
572 ###############
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
573
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
574 # precompile(Tuple{typeof(GR.drawimage), Float64, Float64, Float64, Float64, Int64, Int64, Array{UInt32, 2}})
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
575 # precompile(Tuple{Type{Plots.Plot{T} where T<:RecipesBase.AbstractBackend}, Plots.GRBackend, Int64, Base.Dict{Symbol, Any}, Base.Dict{Symbol, Any}, Array{Plots.Series, 1}, Nothing, Array{Plots.Subplot{T} where T<:RecipesBase.AbstractBackend, 1}, Base.Dict{Any, Plots.Subplot{T} where T<:RecipesBase.AbstractBackend}, Plots.EmptyLayout, Array{Plots.Subplot{T} where T<:RecipesBase.AbstractBackend, 1}, Bool})
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
576 # precompile(Tuple{typeof(Plots._plot!), Plots.Plot{Plots.GRBackend}, Base.Dict{Symbol, Any}, Tuple{Array{ColorTypes.Gray{Float64}, 2}}})
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
577
e4ad8f7ce671 Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff changeset
578 end # Module

mercurial