/
off_axis_example.py
68 lines (44 loc) · 1.95 KB
/
off_axis_example.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
61
62
63
64
65
66
67
# -*- coding: utf-8 -*-
"""
Minimal example of how to use off-axis holography functionality of PyHoloscope.
This example loads an off-axis hologram and a background image (i.e. with the
sample removed).
The images are loaded using the PyHoloscope 'load_image' function.
Alternatively you can load these in using any method that results in them
being stored in a 2D numpy array.
We instantiate a 'Holo' object and pass in the system parameters and some
options.
We call the 'process' method of 'Holo' to demodulate the hologram to recover
the phase.
If you have a GPU and Cupy is installed the GPU will be used, otherwise it
will revert to CPU.
We use the 'amplitude' and 'phase' functions to extract the amplitude
and phase of the complex demodulated image.
"""
from matplotlib import pyplot as plt
from pathlib import Path
import context # Paths
import pyholoscope as pyh
# Experimental Parameters
wavelength = 630e-9
pixelSize = .3e-6
# Load images
holoFile = Path('../test/test data/tissue_paper_oa.tif')
backFile = Path('../test/test data/tissue_paper_oa_background.tif')
hologram = pyh.load_image(holoFile)
background = pyh.load_image(backFile)
# Create Holo object
holo = pyh.Holo(mode = pyh.OFF_AXIS,
background = background, # For correcting background phase
relativePhase = True) # We will remove the background phase
holo.calib_off_axis() # Finds modulation frequency and
# pre-computes background phase
# Remove the off-axis modulation and recover the phase
reconField = holo.process(hologram)
""" Display results """
plt.figure(dpi = 150); plt.title('Hologram')
plt.imshow(hologram, cmap = 'gray')
plt.figure(dpi = 150); plt.title('Intensity')
plt.imshow(pyh.amplitude(reconField), cmap = 'gray', interpolation='none')
plt.figure(dpi = 150); plt.title('Phase')
plt.imshow(pyh.phase(reconField), cmap = 'twilight', interpolation='none')