src/ImGenerate.jl

changeset 24
2d9e64235ba7
parent 22
a30a8745a83b
child 25
c9b06736a477
equal deleted inserted replaced
23:1c4b7d1f261f 24:2d9e64235ba7
198 while true 198 while true
199 # Extract subwindow of original image and add noise 199 # Extract subwindow of original image and add noise
200 b_true = zeros(sz...) 200 b_true = zeros(sz...)
201 extract_subimage!(b_true, im, v_cumul; threads=true) 201 extract_subimage!(b_true, im, v_cumul; threads=true)
202 b = b_true .+ params.noise_level.*randn(rng,sz...) 202 b = b_true .+ params.noise_level.*randn(rng,sz...)
203 v = v_true.*(1.0 .+ params.shake_noise_level.*randn(rng,size(v_true)...)) 203 v = v_true.*(1.0 .+ zero_factor*params.shake_noise_level.*randn(rng,size(v_true)...))
204 # Pass data to iteration routine 204 # Pass data to iteration routine
205 data = OnlineData{DisplacementConstant}(b_true, b, v, v_true, v_cumul) 205 data = OnlineData{DisplacementConstant}(b_true, b, v, v_true, v_cumul)
206 if !put_unless_closed!(datachannel, data) 206 if !put_unless_closed!(datachannel, data)
207 return 207 return
208 end 208 end
225 225
226 226
227 ######################################################################## 227 ########################################################################
228 # PETscan 228 # PETscan
229 ######################################################################## 229 ########################################################################
230 function generate_radon(im, sz, 230 function generate_sinogram(im, sz,
231 :: Type{DisplacementConstant}, 231 :: Type{DisplacementConstant},
232 datachannel :: Channel{PetOnlineData{DisplacementConstant}}, 232 datachannel :: Channel{PetOnlineData{DisplacementConstant}},
233 params :: NamedTuple) 233 params :: NamedTuple)
234 234
235 # Set up counter and zero factor for stabilisation 235 # Set up counter and zero factor for stabilisation
255 tform = recenter(RotMatrix(theta_cumul), center_point) 255 tform = recenter(RotMatrix(theta_cumul), center_point)
256 256
257 # Apply the transformation to the image using warp 257 # Apply the transformation to the image using warp
258 b_true = copy(warp(im, tform, axes(im), fillvalue=Flat())) 258 b_true = copy(warp(im, tform, axes(im), fillvalue=Flat()))
259 259
260 v = v_true.*(1.0 .+ params.shake_noise_level.*randn(rng,size(v_true)...)) 260 v = v_true.*(1.0 .+ zero_factor*params.shake_noise_level.*randn(rng,size(v_true)...))
261 theta = theta_true*(1.0 + params.rotation_noise_level.*randn(rng)) 261 theta = theta_true*(1.0 + zero_factor*params.rotation_noise_level.*randn(rng))
262 262
263 # Generate the true and noisy sinograms 263 # Generate the true and noisy sinograms
264 sinogram_true = zeros(params.radondims...) 264 sinogram_true = zeros(params.radondims...)
265 sinogram_true .*= params.scale 265 sinogram_true .*= params.scale
266 radon!(sinogram_true, b_true) 266 radon!(sinogram_true, b_true)
291 end 291 end
292 292
293 function imgen_shepplogan_radon(sz) 293 function imgen_shepplogan_radon(sz)
294 im = convert(Array{Float64},TestImages.shepp_logan(sz[1], highContrast=true)) 294 im = convert(Array{Float64},TestImages.shepp_logan(sz[1], highContrast=true))
295 dynrange = maximum(im) 295 dynrange = maximum(im)
296 return ImGen(curry(generate_radon, im, sz), sz, 1, dynrange, "shepplogan$(sz[1])x$(sz[2])") 296 return ImGen(curry(generate_sinogram, im, sz), sz, 1, dynrange, "shepplogan$(sz[1])x$(sz[2])")
297 end 297 end
298 298
299 function imgen_brainphantom_radon(sz) 299 function imgen_brainphantom_radon(sz)
300 data = matread("src/PET/phantom_slice.mat") 300 data = matread("src/PET/phantom_slice.mat")
301 im = normalise(imresize(convert(Array{Float64},data["square_data"]),sz)) 301 im = normalise(imresize(convert(Array{Float64},data["square_data"]),sz))
302 dynrange = maximum(im) 302 dynrange = maximum(im)
303 return ImGen(curry(generate_radon, im, sz), sz, 1, dynrange, "brainphantom$(sz[1])x$(sz[2])") 303 return ImGen(curry(generate_sinogram, im, sz), sz, 1, dynrange, "brainphantom$(sz[1])x$(sz[2])")
304 end 304 end
305 305
306 normalise = (data) -> data./maximum(data) 306 normalise = (data) -> data./maximum(data)
307 end # Module 307 end # Module

mercurial