-
Notifications
You must be signed in to change notification settings - Fork 2
/
richardson_lucy_demo.py
48 lines (37 loc) · 1.41 KB
/
richardson_lucy_demo.py
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
import pyapr
from time import time
"""
Read a selected APR from file and apply Richardson-Lucy deconvolution
"""
# Get input APR file path from gui
io_int = pyapr.utils.InteractiveIO()
fpath_apr = io_int.get_apr_file_name()
# Read from APR file
apr, parts = pyapr.io.read(fpath_apr)
# Copy particles to float
parts = pyapr.FloatParticles(parts)
# Add a small offset to the particle values to avoid division by 0
offset = 1e-5 * parts.max()
parts += offset
# Specify the PSF and number of iterations
psf = pyapr.filter.get_gaussian_stencil(size=5, sigma=1, ndims=3, normalize=True)
# Richardson-lucy deconvolution
t0 = time()
output = pyapr.restoration.richardson_lucy(apr, parts, psf, num_iter=10)
print('RL took {} seconds'.format(time()-t0))
# Using total variation regularization
t0 = time()
output_tv = pyapr.restoration.richardson_lucy_tv(apr, parts, psf, reg_param=1e-2, num_iter=10)
print('RLTV took {} seconds'.format(time()-t0))
# if pyapr is built with CUDA enabled and psf is of size (3, 3, 3) or (5, 5, 5)
cuda = False
if pyapr.cuda_enabled() and psf.shape in [(3, 3, 3), (5, 5, 5)]:
t0 = time()
output_cuda = pyapr.restoration.richardson_lucy_cuda(apr, parts, psf, num_iter=10)
print('RL cuda took {} seconds'.format(time()-t0))
cuda = True
# Display the results
pyapr.viewer.parts_viewer(apr, output)
pyapr.viewer.parts_viewer(apr, output_tv)
if cuda:
pyapr.viewer.parts_viewer(apr, output_cuda)