-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-psf.cpp
64 lines (54 loc) · 1.65 KB
/
generate-psf.cpp
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
#include <armadillo>
#include "make_psf.h"
namespace {
#ifdef LSTSQ_USE_LAPACK
constexpr bool has_lapack = true;
#else
constexpr bool has_lapack = false;
#endif
} // namespace
int main() {
using arma::hdf5_name;
using microsc_psf::makePSF;
using microsc_psf::microscope_params_t;
using microsc_psf::precision_li2017_t;
namespace hdf5_opts = arma::hdf5_opts;
using namespace ::units::literals;
microscope_params_t params{};
params.NA = 1.4;
params.ti0 = 150.0_um;
params.ni = 1.5;
params.ni0 = 1.5;
params.pz = 2.0_um;
precision_li2017_t precision{};
precision.num_basis = 153;
precision.rho_samples = 1000;
precision.solver = has_lapack ? microsc_psf::SandersonAndCurtin2020 : microsc_psf::EigenBdcSVD;
const auto psf =
makePSF(params, {0.1_um, 0.25_um}, {256, 128}, 0.610_um, precision);
#ifdef ARMA_USE_HDF5
std::cout << "Saving volume to HDF5...\n";
psf.save(hdf5_name("psf.h5", "psf", hdf5_opts::trans));
std::cout << R"(Done.
Import to Matlab: h5read("psf.h5", "psf");
Import to Python:
import h5py
with h5py.File("psf.h5", "r") as h5file:
psf = h5file["psf"][()]
)";
#endif
{
using namespace arma;
mat xy_plane = sqrt(psf.slice(32));
xy_plane *= 255 / max(xy_plane.as_col());
xy_plane.save("psf_xy.pgm", pgm_binary);
std::cout << "PSF XY plane saved to 'psf_xy.pgm'.\n";
}
{
using namespace arma;
mat xz_plane = sqrt(psf.col(60));
mat(xz_plane.t() * 255 / max(xz_plane.as_col())).save("psf_xz.pgm", pgm_binary);
std::cout << "PSF XZ plane saved to 'psf_xz.pgm'.\n";
}
return 0;
}