src/PET/PET.jl

Sun, 21 Apr 2024 19:04:00 +0300

author
Neil Dizon <neil.dizon@helsinki.fi>
date
Sun, 21 Apr 2024 19:04:00 +0300
changeset 20
7d3a75b875fa
parent 19
7c4dfeb48dd9
child 22
a30a8745a83b
permissions
-rw-r--r--

added zero dual predictor for denoising

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

mercurial