-
Notifications
You must be signed in to change notification settings - Fork 2
/
reconstruction_demo.py
38 lines (28 loc) · 1.43 KB
/
reconstruction_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
import pyapr
from skimage import io as skio
from pyapr.reconstruction import reconstruct_constant, reconstruct_smooth, reconstruct_level
"""
This demo illustrates three different pixel image reconstruction methods:
constant each pixel takes the value of the particle whose cell contains the pixel
smooth additionally smooths regions of coarser resolution to reduce 'blockiness'
level each pixel takes the value of the resolution level of the particle cell it belongs to
"""
# get input APR file path from gui
io_int = pyapr.utils.InteractiveIO()
fpath_apr = io_int.get_apr_file_name()
# Read APR and particles from file
apr, parts = pyapr.io.read(fpath_apr)
pc_recon = reconstruct_constant(apr, parts) # piecewise constant reconstruction
smooth_recon = reconstruct_smooth(apr, parts) # smooth reconstruction
level_recon = reconstruct_level(apr) # level reconstruction
# Save the results
file_name = '.'.join(fpath_apr.split('/')[-1].split('.')[:-1])
save_path = io_int.save_tiff_file_name(file_name + '_reconstruct_const.tif')
if save_path:
skio.imsave(save_path, pc_recon, check_contrast=False)
save_path = io_int.save_tiff_file_name(file_name + '_reconstruct_smooth.tif')
if save_path:
skio.imsave(save_path, smooth_recon, check_contrast=False)
save_path = io_int.save_tiff_file_name(file_name + '_reconstruct_level.tif')
if save_path:
skio.imsave(save_path, level_recon, check_contrast=False)