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