-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathexample.jl
73 lines (62 loc) · 1.72 KB
/
example.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
Use the following command in REPL to make a sysimage:
using PackageCompiler
create_sysimage([:ThreeDeconv, :PyCall], sysimage_path="sys_threedeconv.so", precompile_execution_file="example/example.jl")
"""
using ThreeDeconv
using PyCall, Printf
skimage_io = pyimport("skimage.io")
function imread(filename::String)
img = skimage_io.imread(filename)
if ndims(img) == 3
img = permutedims(img, (2, 3, 1))
end
return img
end
function imsave(filename::String, img::Array)
if ndims(img) == 3
img = permutedims(img, (3, 1, 2))
end
skimage_io.imsave(filename, img)
end
imgraw = imread("dataset/raw/bead/raw_cropped/bead_highsnr_raw.tif")
df = imread("dataset/raw/bead/raw_cropped/df.tif")
ff = imread("dataset/raw/bead/raw_cropped/ff_highsnr.tif")
img = (imgraw .- df) ./ ff
obj_mag = 100
camera_pixel_size = 6.5e3 # [nm]
xystep = camera_pixel_size / obj_mag
zstep = 150 # [nm]
medium_index = 1.515
f_tubelens = 200.e6
NA = 1.4
λ = 540 # [nm]
γ, σ = ThreeDeconv.noise_estimation(img, maxnum_pairs = 200)
@printf "Gain: %.1f, Read noise std.: %.1f \n" γ σ
pad = 10
psf_shape = size(img) .+ pad
println("Simulating PSF with the size of $(psf_shape)")
psf = ThreeDeconv.psf(
NA = NA,
objective_mag = obj_mag,
λ = λ,
medium_index = medium_index,
psf_shape = psf_shape,
camera_pixel_size = camera_pixel_size,
zstep = zstep,
f_tubelens = f_tubelens,
oversampling = 4,
)
options =
ThreeDeconv.DeconvolutionOptions(max_iters = 150, show_trace = true, check_every = 50)
reg = 0.01
result = ThreeDeconv.deconvolve(
img,
psf,
γ,
σ,
reg,
ThreeDeconv.ADMM(scale_problem = true),
options = options,
)
imsave("deconvoled_scaled_iter150.tif", result.x)