-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b2def1
commit 43a8b80
Showing
12 changed files
with
238 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
0.1.0 | ||
- drawing refractive index and fluorescence phantoms | ||
- sinogram generation | ||
- basic functionalities (sphere element): | ||
- simple cell phantom | ||
- propagators: Rytov and projection | ||
- fluorescence projector | ||
0.0.1 | ||
- initial setup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import numpy as np | ||
|
||
from .elements import Sphere | ||
|
||
|
||
class Fluorescence(object): | ||
|
||
def __init__(self, phantom, grid_size, pixel_size): | ||
"""Fluorescence projector | ||
Notes | ||
----- | ||
- The origin of the coordinate system is the center of the grid. | ||
For even grid sizes, the origin is between two pixels. For odd | ||
grid sizes the origin coincides with the center pixel. | ||
""" | ||
self.phantom = phantom | ||
self.pixel_size = pixel_size | ||
self.grid_size = grid_size | ||
gx, gy = grid_size | ||
#: center of the volume used | ||
self.center = np.array([gx, gy, 0]) / 2 - .5 | ||
|
||
def project(self): | ||
fluor = np.zeros(self.grid_size, dtype=float) | ||
for element in self.phantom: | ||
if isinstance(element, Sphere): | ||
fluor += self.project_sphere(element) | ||
|
||
return fluor | ||
|
||
def project_sphere(self, sphere): | ||
center = self.center + sphere.center/self.pixel_size | ||
# grid | ||
x = np.arange(self.grid_size[0]).reshape(-1, 1) | ||
y = np.arange(self.grid_size[1]).reshape(1, -1) | ||
cx, cy, _ = center | ||
# sphere location | ||
rpx = sphere.radius / self.pixel_size | ||
r = rpx**2 - (x - cx)**2 - (y - cy)**2 | ||
# distance | ||
z = np.zeros_like(r) | ||
rvalid = r > 0 | ||
z[rvalid] = 2 * np.sqrt(r[rvalid]) | ||
|
||
fluor = z * sphere.fl_brightness | ||
return fluor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import os | ||
import os.path as op | ||
import sys | ||
|
||
import matplotlib.pylab as plt | ||
|
||
thisdir = op.dirname(op.abspath(__file__)) | ||
sys.path.insert(0, op.dirname(thisdir)) | ||
|
||
DPI = 80 | ||
|
||
|
||
if __name__ == "__main__": | ||
# Do not display example plots | ||
plt.show = lambda: None | ||
files = os.listdir(thisdir) | ||
files = [f for f in files if f.endswith(".py")] | ||
files = [f for f in files if not f == op.basename(__file__)] | ||
files = sorted([op.join(thisdir, f) for f in files]) | ||
|
||
for f in files: | ||
fname = f[:-3] + ".png" | ||
if not op.exists(fname): | ||
exec_str = open(f).read() | ||
if exec_str.count("plt.show()"): | ||
exec(exec_str) | ||
plt.savefig(fname, dpi=DPI) | ||
print("Image created: '{}'".format(fname)) | ||
else: | ||
print("No image: '{}'".format(fname)) | ||
else: | ||
print("Image skipped (already exists): '{}'".format(fname)) | ||
plt.close() |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
"""Reconstruction of a simple cell phantom | ||
This example uses :ref:`ODTbrain<odtbrain:index>` and | ||
:ref:`radontea<radontea:index>` for the reconstruction of the refractive | ||
index and the fluorescence of the simple cell phantom. | ||
The reconstruction is compared to the ground truth of the cell phantom. | ||
""" | ||
import cellsino | ||
import matplotlib.pylab as plt | ||
import numpy as np | ||
import odtbrain as odt | ||
import radontea as rt | ||
|
||
|
||
# number of sinogram angles | ||
num_ang = 160 | ||
# sinogram acquisition angles | ||
angles = np.linspace(0, 2*np.pi, num_ang, endpoint=False) | ||
# detector grid size | ||
grid_size = (250, 250) | ||
# vacuum wavelength [m] | ||
wavelength = 550e-9 | ||
# pixel size [m] | ||
pixel_size = 0.08e-6 | ||
# refractive index of the surrounding medium | ||
medium_index = 1.335 | ||
|
||
# initialize cell phantom | ||
phantom = cellsino.phantoms.SimpleCell() | ||
|
||
# initialize sinogram with geometric parameters | ||
sino = cellsino.Sinogram(phantom=phantom, | ||
wavelength=wavelength, | ||
pixel_size=pixel_size, | ||
grid_size=grid_size) | ||
|
||
# compute sinogram (field according to Rytov approximation and fluorescence) | ||
sino_field, sino_fluor = sino.compute(angles=angles, propagator="rytov") | ||
|
||
# reconstruction of refractive index | ||
sino_rytov = odt.sinogram_as_rytov(sino_field) | ||
potential = odt.backpropagate_3d(uSin=sino_rytov, | ||
angles=angles, | ||
res=wavelength/pixel_size, | ||
nm=medium_index) | ||
ri = odt.odt_to_ri(f=potential, | ||
res=wavelength/pixel_size, | ||
nm=medium_index) | ||
|
||
# reconstruction of fluorescence | ||
fl = rt.backproject_3d(sinogram=sino_fluor, | ||
angles=angles) | ||
|
||
# reference for comparison | ||
rimod, flmod = phantom.draw(grid_size=ri.shape, | ||
pixel_size=pixel_size) | ||
|
||
# plotting | ||
idx = 150 | ||
|
||
plt.figure(figsize=(7, 5.5)) | ||
|
||
plotkwri = {"vmax": ri.real.max(), | ||
"vmin": ri.real.min(), | ||
"interpolation": "none", | ||
"cmap": "viridis", | ||
} | ||
|
||
plotkwfl = {"vmax": fl.max(), | ||
"vmin": 0, | ||
"interpolation": "none", | ||
"cmap": "Greens_r", | ||
} | ||
|
||
ax1 = plt.subplot(221, title="refractive index (ground_truth)") | ||
mapper = ax1.imshow(rimod[idx].real, **plotkwri) | ||
plt.colorbar(mappable=mapper, ax=ax1) | ||
|
||
ax2 = plt.subplot(222, title="refractive index (reconstruction)") | ||
mapper = ax2.imshow(ri[idx].real, **plotkwri) | ||
plt.colorbar(mappable=mapper, ax=ax2) | ||
|
||
ax3 = plt.subplot(223, title="fluorescence (ground truth)") | ||
mapper = ax3.imshow(flmod[idx], **plotkwfl) | ||
plt.colorbar(mappable=mapper, ax=ax3) | ||
|
||
ax4 = plt.subplot(224, title="fluorescence (reconstruction)") | ||
mapper = ax4.imshow(fl[idx], **plotkwfl) | ||
plt.colorbar(mappable=mapper, ax=ax4) | ||
|
||
for ax in [ax1, ax2, ax3, ax4]: | ||
ax.grid(color="w", alpha=.5) | ||
ax.set_xticks(np.arange(0, grid_size[0], 50)) | ||
ax.set_yticks(np.arange(0, grid_size[0], 50)) | ||
ax.set_xticklabels([]) | ||
ax.set_yticklabels([]) | ||
|
||
plt.tight_layout() | ||
|
||
plt.show() |