Wed, 24 Apr 2024 11:34:09 +0300
added function to generate table
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(θ)] | |
103 | end | |
104 | else | |
105 | error("Unknown shaketype $(params.shaketype)") | |
106 | end | |
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) | |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
184 | |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
185 | |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
186 | # Set up counter and zero factor for stabilisation |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
187 | @assert(params.maxiter ≥ maximum(params.stable_interval)) |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
188 | indx = 1 |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
189 | zero_factor = indx in params.stable_interval ? 0.0 : 1.0 |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
190 | |
7 | 191 | # Restart the seed to enable comparison across predictors |
28
f7c1007f0127
added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents:
25
diff
changeset
|
192 | #Random.seed!(rng,951508) # algreadygood |
f7c1007f0127
added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents:
25
diff
changeset
|
193 | Random.seed!(rng,67584) |
7 | 194 | |
0 | 195 | nextv = shake(params) |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
196 | v_true = zero_factor.*nextv() |
0 | 197 | v_cumul = copy(v_true) |
198 | ||
199 | while true | |
200 | # Extract subwindow of original image and add noise | |
201 | b_true = zeros(sz...) | |
202 | extract_subimage!(b_true, im, v_cumul; threads=true) | |
5 | 203 | b = b_true .+ params.noise_level.*randn(rng,sz...) |
25 | 204 | v = v_true.*(1.0 .+ params.shake_noise_level.*randn(rng,size(v_true)...)) |
0 | 205 | # Pass data to iteration routine |
206 | data = OnlineData{DisplacementConstant}(b_true, b, v, v_true, v_cumul) | |
207 | if !put_unless_closed!(datachannel, data) | |
208 | return | |
209 | end | |
210 | # Next step shake | |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
211 | v_true = zero_factor.*nextv() |
0 | 212 | v_cumul .+= v_true |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
213 | # Update indx and zero factor |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
214 | indx += 1 |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
215 | zero_factor = indx in params.stable_interval ? 0.0 : 1.0 |
0 | 216 | end |
217 | end | |
218 | ||
219 | function imgen_shake(imname, sz) | |
220 | im = Float64.(Gray.(TestImages.testimage(imname))) | |
221 | dynrange = maximum(im) | |
222 | return ImGen(curry(generate_shake_image, im, sz), sz, 1, dynrange, | |
223 | "$(imname)$(sz[1])x$(sz[2])") | |
224 | end | |
225 | ||
8
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 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
228 | ######################################################################## |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
229 | # PETscan |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
230 | ######################################################################## |
24
2d9e64235ba7
renamed generate_radon as generate_sinogram
Neil Dizon <neil.dizon@helsinki.fi>
parents:
22
diff
changeset
|
231 | function generate_sinogram(im, sz, |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
232 | :: Type{DisplacementConstant}, |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
233 | datachannel :: Channel{PetOnlineData{DisplacementConstant}}, |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
234 | params :: NamedTuple) |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
235 | |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
236 | # Set up counter and zero factor for stabilisation |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
237 | @assert(params.maxiter ≥ maximum(params.stable_interval)) |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
238 | indx = 1 |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
239 | 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
|
240 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
241 | # Restart the seed to enable comparison across predictors |
28
f7c1007f0127
added function to generate table
Neil Dizon <neil.dizon@helsinki.fi>
parents:
25
diff
changeset
|
242 | Random.seed!(rng,314159) |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
243 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
244 | nextv = shake(params) |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
245 | v_true = zero_factor.*nextv() |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
246 | v_cumul = copy(v_true) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
247 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
248 | S_true = generate_radonmask(params) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
249 | |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
250 | theta_true = zero_factor*rotatebytheta(params) |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
251 | theta_cumul = copy(theta_true) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
252 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
253 | while true |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
254 | # Define the transformation matrix |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
255 | 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
|
256 | tform = recenter(RotMatrix(theta_cumul), center_point) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
257 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
258 | # Apply the transformation to the image using warp |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
259 | 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
|
260 | |
25 | 261 | v = v_true.*(1.0 .+ params.shake_noise_level.*randn(rng,size(v_true)...)) |
262 | 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
|
263 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
264 | # Generate the true and noisy sinograms |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
265 | sinogram_true = zeros(params.radondims...) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
266 | sinogram_true .*= params.scale |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
267 | radon!(sinogram_true, b_true) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
268 | sinogram_noisy = copy(sinogram_true) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
269 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
270 | 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
|
271 | 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
|
272 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
273 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
274 | # Pass data to iteration routine |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
275 | 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
|
276 | if !put_unless_closed!(datachannel, data) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
277 | return |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
278 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
279 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
280 | # Next step shake |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
281 | v_true = zero_factor.*nextv() |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
282 | v_cumul .+= v_true |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
283 | # Next theta |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
284 | theta_true = zero_factor*rotatebytheta(params) |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
285 | theta_cumul += theta_true |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
286 | # Next sinogram mask |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
287 | S_true = generate_radonmask(params) |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
288 | # Update indx and zero factor |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
289 | indx += 1 |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
290 | 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
|
291 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
292 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
293 | |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
294 | function imgen_shepplogan_radon(sz) |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
295 | 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
|
296 | dynrange = maximum(im) |
24
2d9e64235ba7
renamed generate_radon as generate_sinogram
Neil Dizon <neil.dizon@helsinki.fi>
parents:
22
diff
changeset
|
297 | 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
|
298 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
299 | |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
300 | function imgen_brainphantom_radon(sz) |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
301 | data = matread("src/PET/phantom_slice.mat") |
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
302 | 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
|
303 | dynrange = maximum(im) |
24
2d9e64235ba7
renamed generate_radon as generate_sinogram
Neil Dizon <neil.dizon@helsinki.fi>
parents:
22
diff
changeset
|
304 | 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
|
305 | end |
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
7
diff
changeset
|
306 | |
22
a30a8745a83b
added stable interval for denoising
Neil Dizon <neil.dizon@helsinki.fi>
parents:
8
diff
changeset
|
307 | normalise = (data) -> data./maximum(data) |
0 | 308 | end # Module |