-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender_psf.py
60 lines (46 loc) · 1.55 KB
/
render_psf.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
49
50
51
52
53
54
55
56
57
58
59
60
"""Render the trained PSF.
The simulated PSF will be saved at "result" directory.
Download and expand the dataset in "data" directory.
Usage:
python render_psf.py
"""
import os
from argparse import ArgumentParser
import torch
import util.io
from module.bead import Bead
from module.microscope import Microscope
from util.fft import crop_psf, fftshift
def main(hparams):
"""Render PSF."""
save_dir = "result"
os.makedirs(save_dir, exist_ok=True)
phase_path = os.path.join("data", "fitted_psf", "fixed_cell", "designed_phase.tif")
axial_sampling_nm = 200
depth_range_nm = 12000
focus_offset_nm = 6000
output_psf_sz = 128
hparams.axial_sampling_nm = axial_sampling_nm
hparams.focus_offset_nm = focus_offset_nm
hparams.depth_range_nm = depth_range_nm
axial_sz_px = int(depth_range_nm // hparams.axial_sampling_nm)
phase = util.io.imread(phase_path)
if torch.cuda.is_available():
device = torch.device("cuda")
else:
device = torch.device("cpu")
microscope = Microscope(
hparams,
init_phase=phase,
).to(device)
psf = microscope.psf(torch.arange(axial_sz_px))
psf = fftshift(crop_psf(psf, output_psf_sz), (-1, -2))
psf /= psf.max()
psf = torch.cat([psf[0], psf[1]], dim=-1)
util.io.imsave(os.path.join(save_dir, "psf.tif"), psf)
if __name__ == "__main__":
parser = ArgumentParser(add_help=False)
parser = Microscope.add_model_specific_args(parser)
parser = Bead.add_model_specific_args(parser)
hparams = parser.parse_args()
main(hparams)