Fri, 03 May 2024 21:55:23 +0300
README demo options added
0 | 1 | ################### |
2 | # Image generation | |
3 | ################### | |
4 | ||
5 | module ImGenerate | |
6 | ||
7 | using ColorTypes: Gray | |
8 | import TestImages | |
9 | # We don't really *directly* depend on QuartzImageIO. The import here is | |
10 | # merely a workaround to suppress warnings when loading TestImages. | |
11 | # Something is broken in those packages. | |
12 | import QuartzImageIO | |
13 | ||
14 | using AlgTools.Util | |
15 | using AlgTools.Comms | |
16 | using ImageTools.Translate | |
17 | ||
18 | using ..OpticalFlow: Image, DisplacementConstant, DisplacementFull | |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
19 | using ..Radon |
0 | 20 | |
5 | 21 | # Added for reproducibility |
22 | import StableRNGs: StableRNG, Random | |
28
f7c1007f0127
added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents:
25
diff
changeset
|
23 | const rng = StableRNG(314159) |
5 | 24 | |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
25 | # Added for PET |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
26 | import PoissonRandom: pois_rand |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
27 | import Random: shuffle |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
28 | import Images: center, warp, imresize |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
29 | import CoordinateTransformations: recenter |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
30 | import Rotations: RotMatrix |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
31 | import Interpolations: Flat |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
32 | import MAT: matread |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
33 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
34 | |
0 | 35 | ############## |
36 | # Our exports | |
37 | ############## | |
38 | ||
39 | export ImGen, | |
40 | OnlineData, | |
41 | imgen_square, | |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
42 | imgen_shake, |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
43 | PetOnlineData, |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
44 | imgen_shepplogan_radon, |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
45 | imgen_brainphantom_radon |
0 | 46 | |
47 | ################## | |
48 | # Data structures | |
49 | ################## | |
50 | ||
51 | struct ImGen | |
52 | f :: Function | |
53 | dim :: Tuple{Int64,Int64} | |
54 | Λ :: Float64 | |
55 | dynrange :: Float64 | |
56 | name :: String | |
57 | end | |
58 | ||
59 | struct OnlineData{DisplacementT} | |
60 | b_true :: Image | |
61 | b_noisy :: Image | |
62 | v :: DisplacementT | |
63 | v_true :: DisplacementT | |
64 | v_cumul_true :: DisplacementT | |
65 | end | |
66 | ||
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
67 | struct PetOnlineData{DisplacementT} |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
68 | b_true :: Image |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
69 | sinogram_true :: Image |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
70 | sinogram_noisy :: Image |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
71 | v :: DisplacementT |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
72 | v_true :: DisplacementT |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
73 | v_cumul_true :: DisplacementT |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
74 | theta :: DisplacementT # theta = thetaknown, theta_cumul |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
75 | S :: Image |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
76 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
77 | |
0 | 78 | ################### |
79 | # Shake generation | |
80 | ################### | |
81 | ||
82 | function make_const_v(displ, sz) | |
83 | v = zeros(2, sz...) | |
84 | v[1, :, :] .= displ[1] | |
85 | v[2, :, :] .= displ[2] | |
86 | return v | |
87 | end | |
88 | ||
89 | function shake(params) | |
90 | if !haskey(params, :shaketype) || params.shaketype == :gaussian | |
5 | 91 | return () -> params.shake.*randn(rng,2) |
0 | 92 | elseif params.shaketype == :disk |
93 | return () -> begin | |
5 | 94 | θ = 2π*rand(rng,Float64) |
95 | r = params.shake*√(rand(rng,Float64)) | |
0 | 96 | return [r*cos(θ), r*sin(θ)] |
97 | end | |
98 | elseif params.shaketype == :circle | |
99 | return () -> begin | |
5 | 100 | θ = 2π*rand(rng,Float64) |
0 | 101 | r = params.shake |
102 | return [r*cos(θ), r*sin(θ)] | |
36 | 103 | end |
0 | 104 | else |
105 | error("Unknown shaketype $(params.shaketype)") | |
36 | 106 | end |
0 | 107 | end |
108 | ||
109 | pixelwise = (shakefn, sz) -> () -> make_const_u(shakefn(), sz) | |
110 | ||
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
111 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
112 | function rotatebytheta(params) |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
113 | r = params.rotation_factor*randn(rng) |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
114 | return r |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
115 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
116 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
117 | function generate_radonmask(params) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
118 | imdim = params.radondims |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
119 | sino_sparse = params.sino_sparsity |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
120 | numzero = Int64(round(sino_sparse*imdim[1]*imdim[2])) |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
121 | numone = imdim[1]*imdim[2]-numzero |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
122 | A = shuffle(rng,reshape([ones(numone); zeros(numzero)],(imdim[1],imdim[2]))) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
123 | return A |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
124 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
125 | |
0 | 126 | ################ |
127 | # Moving square | |
128 | ################ | |
129 | ||
130 | function generate_square(sz, | |
131 | :: Type{DisplacementT}, | |
132 | datachannel :: Channel{OnlineData{DisplacementT}}, | |
133 | params) where DisplacementT | |
134 | ||
135 | if false | |
136 | v₀ = make_const_v(0.1.*(-1, 1), sz) | |
137 | nextv = () -> v₀ | |
138 | elseif DisplacementT == DisplacementFull | |
139 | nextv = pixelwise(shake(params), sz) | |
140 | elseif DisplacementT == DisplacementConstant | |
141 | nextv = shake(params) | |
142 | else | |
143 | @error "Invalid DisplacementT" | |
144 | end | |
145 | ||
146 | # Constant linear displacement everywhere has Jacobian determinant one | |
147 | # (modulo the boundaries which we ignore here) | |
148 | m = round(Int, sz[1]/5) | |
149 | b_orig = zeros(sz...) | |
150 | b_orig[sz[1].-(2*m:3*m), 2*m:3*m] .= 1 | |
151 | ||
152 | v_true = nextv() | |
153 | v_cumul = copy(v_true) | |
154 | ||
155 | while true | |
156 | # Flow original data and add noise | |
157 | b_true = zeros(sz...) | |
158 | translate_image!(b_true, b_orig, v_cumul; threads=true) | |
5 | 159 | b = b_true .+ params.noise_level.*randn(rng,sz...) |
160 | v = v_true.*(1.0 .+ params.shake_noise_level.*randn(rng,size(v_true)...)) | |
0 | 161 | # Pass true data to iteration routine |
162 | data = OnlineData{DisplacementT}(b_true, b, v, v_true, v_cumul) | |
163 | if !put_unless_closed!(datachannel, data) | |
164 | return | |
165 | end | |
166 | # Next step shake | |
167 | v_true = nextv() | |
168 | v_cumul .+= v_true | |
169 | end | |
170 | end | |
171 | ||
172 | function imgen_square(sz) | |
173 | return ImGen(curry(generate_square, sz), sz, 1, 1, "square$(sz[1])x$(sz[2])") | |
174 | end | |
175 | ||
176 | ################ | |
177 | # Shake a photo | |
178 | ################ | |
179 | ||
180 | function generate_shake_image(im, sz, | |
181 | :: Type{DisplacementConstant}, | |
182 | datachannel :: Channel{OnlineData{DisplacementConstant}}, | |
183 | params :: NamedTuple) | |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
184 | |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
185 | # Set up counter and zero factor for stabilisation |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
186 | @assert(params.maxiter ≥ maximum(params.stable_interval)) |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
187 | indx = 1 |
36 | 188 | zero_factor = indx in params.stable_interval ? 0.0 : 1.0 |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
189 | |
36 | 190 | # Restart the seed to enable comparison across predictors |
191 | Random.seed!(rng, if haskey(params, :seed) params.seed else 951508 end) | |
7 | 192 | |
0 | 193 | nextv = shake(params) |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
194 | v_true = zero_factor.*nextv() |
0 | 195 | v_cumul = copy(v_true) |
196 | ||
197 | while true | |
198 | # Extract subwindow of original image and add noise | |
199 | b_true = zeros(sz...) | |
200 | extract_subimage!(b_true, im, v_cumul; threads=true) | |
5 | 201 | b = b_true .+ params.noise_level.*randn(rng,sz...) |
25 | 202 | v = v_true.*(1.0 .+ params.shake_noise_level.*randn(rng,size(v_true)...)) |
0 | 203 | # Pass data to iteration routine |
204 | data = OnlineData{DisplacementConstant}(b_true, b, v, v_true, v_cumul) | |
205 | if !put_unless_closed!(datachannel, data) | |
206 | return | |
207 | end | |
208 | # Next step shake | |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
209 | v_true = zero_factor.*nextv() |
0 | 210 | v_cumul .+= v_true |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
211 | # Update indx and zero factor |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
212 | indx += 1 |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
213 | zero_factor = indx in params.stable_interval ? 0.0 : 1.0 |
0 | 214 | end |
215 | end | |
216 | ||
217 | function imgen_shake(imname, sz) | |
218 | im = Float64.(Gray.(TestImages.testimage(imname))) | |
219 | dynrange = maximum(im) | |
220 | return ImGen(curry(generate_shake_image, im, sz), sz, 1, dynrange, | |
221 | "$(imname)$(sz[1])x$(sz[2])") | |
222 | end | |
223 | ||
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
224 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
225 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
226 | ######################################################################## |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
227 | # PETscan |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
228 | ######################################################################## |
24
2d9e64235ba7
renamed generate_radon as generate_sinogram
Neil Dizon <neil.dizon@helsinki.fi>
parents:
22
diff
changeset
|
229 | function generate_sinogram(im, sz, |
36 | 230 | :: Type{DisplacementConstant}, |
231 | datachannel :: Channel{PetOnlineData{DisplacementConstant}}, | |
232 | params :: NamedTuple) | |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
233 | |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
234 | # Set up counter and zero factor for stabilisation |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
235 | @assert(params.maxiter ≥ maximum(params.stable_interval)) |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
236 | indx = 1 |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
237 | zero_factor = indx in params.stable_interval ? 0.0 : 1.0 |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
238 | |
36 | 239 | # Restart the seed to enable comparison across predictors |
240 | Random.seed!(rng, if haskey(params, :seed) params.seed else 314159 end) | |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
241 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
242 | nextv = shake(params) |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
243 | v_true = zero_factor.*nextv() |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
244 | v_cumul = copy(v_true) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
245 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
246 | S_true = generate_radonmask(params) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
247 | |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
248 | theta_true = zero_factor*rotatebytheta(params) |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
249 | theta_cumul = copy(theta_true) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
250 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
251 | while true |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
252 | # Define the transformation matrix |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
253 | center_point = (sz[1]/2 + v_true[1], sz[2]/2 + v_true[2]) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
254 | tform = recenter(RotMatrix(theta_cumul), center_point) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
255 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
256 | # Apply the transformation to the image using warp |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
257 | b_true = copy(warp(im, tform, axes(im), fillvalue=Flat())) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
258 | |
25 | 259 | v = v_true.*(1.0 .+ params.shake_noise_level.*randn(rng,size(v_true)...)) |
260 | theta = theta_true*(1.0 + params.rotation_noise_level.*randn(rng)) | |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
261 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
262 | # Generate the true and noisy sinograms |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
263 | sinogram_true = zeros(params.radondims...) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
264 | sinogram_true .*= params.scale |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
265 | radon!(sinogram_true, b_true) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
266 | sinogram_noisy = copy(sinogram_true) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
267 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
268 | for i=1:params.radondims[1], j=1:params.radondims[2] |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
269 | sinogram_noisy[i, j] += pois_rand(rng,params.noise_level) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
270 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
271 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
272 | # Pass data to iteration routine |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
273 | data = PetOnlineData{DisplacementConstant}(b_true, sinogram_true, sinogram_noisy, v, v_true, v_cumul, [theta, theta_cumul], S_true) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
274 | if !put_unless_closed!(datachannel, data) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
275 | return |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
276 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
277 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
278 | # Next step shake |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
279 | v_true = zero_factor.*nextv() |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
280 | v_cumul .+= v_true |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
281 | # Next theta |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
282 | theta_true = zero_factor*rotatebytheta(params) |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
283 | theta_cumul += theta_true |
36 | 284 | # Next sinogram mask |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
285 | S_true = generate_radonmask(params) |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
286 | # Update indx and zero factor |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
287 | indx += 1 |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
288 | zero_factor = indx in params.stable_interval ? 0.0 : 1.0 |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
289 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
290 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
291 | |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
292 | function imgen_shepplogan_radon(sz) |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
293 | im = convert(Array{Float64},TestImages.shepp_logan(sz[1], highContrast=true)) |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
294 | dynrange = maximum(im) |
24
2d9e64235ba7
renamed generate_radon as generate_sinogram
Neil Dizon <neil.dizon@helsinki.fi>
parents:
22
diff
changeset
|
295 | return ImGen(curry(generate_sinogram, im, sz), sz, 1, dynrange, "shepplogan$(sz[1])x$(sz[2])") |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
296 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
297 | |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
298 | function imgen_brainphantom_radon(sz) |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
299 | data = matread("src/PET/phantom_slice.mat") |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
300 | im = normalise(imresize(convert(Array{Float64},data["square_data"]),sz)) |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
301 | dynrange = maximum(im) |
24
2d9e64235ba7
renamed generate_radon as generate_sinogram
Neil Dizon <neil.dizon@helsinki.fi>
parents:
22
diff
changeset
|
302 | return ImGen(curry(generate_sinogram, im, sz), sz, 1, dynrange, "brainphantom$(sz[1])x$(sz[2])") |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
303 | end |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
304 | |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
305 | normalise = (data) -> data./maximum(data) |
0 | 306 | end # Module |