Name: flowdec
Owner: Hammer Lab
Description: Tensorflow Deconvolution for Microscopy
Created: 2018-03-27 21:12:22.0
Updated: 2018-04-02 16:37:34.0
Pushed: 2018-04-02 16:37:32.0
Homepage: null
Size: 3560
Language: Jupyter Notebook
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Flowdec is a library containing TensorFlow (TF) implementations of image and signal deconvolution algorithms. Currently, only Richardson-Lucy Deconvolution has been implemented but others may come in the future.
Flowdec is designed to construct and execute TF graphs in python as well as use frozen, exported graphs from other languages (e.g. Java).
Here are a few other features, advantages, and disadvantages of the project currently:
Highlights
`observer
` functions be given that take intermediate results of the deconvolution process to be written out to image sequences or stacks for manual inspection. Future work may include using Tensorboard to do this instead but for now, it has been difficult to get image summaries working within TF “while” loops.Disadvantages
Here is a basic example demonstrating how Flowdec can be used in a single 3D image deconvolution:
See full example notebook here
plotlib inline
rt numpy as np
rt matplotlib.pyplot as plt
skimage import exposure
scipy import ndimage, signal
flowdec import data as fd_data
flowdec import psf as fd_psf
flowdec import restoration as fd_restoration
ad "Purkinje Neuron" dataset downsampled from 200x1024x1024 to 50x256x256
e: http://www.cellimagelibrary.org/images/CCDB_2
al = fd_data.neuron_25pct().data
tual.shape = (50, 256, 256)
eate a gaussian kernel that will be used to blur the original acquisition
el = np.zeros_like(actual)
offset in [0, 1]:
kernel[tuple((np.array(kernel.shape) - offset) // 2)] = 1
el = ndimage.gaussian_filter(kernel, sigma=1.)
rnel.shape = (50, 256, 256)
nvolve the original image with our fake PSF
= signal.fftconvolve(actual, kernel, mode='same')
ta.shape = (50, 256, 256)
n the deconvolution process and note that deconvolution initialization is best kept separate from
ecution since the "initialize" operation corresponds to creating a TensorFlow graph, which is a
latively expensive operation and should not be repeated across multiple executions
= fd_restoration.RichardsonLucyDeconvolver(data.ndim).initialize()
= algo.run(fd_data.Acquisition(data=data, kernel=kernel), niter=30).data
axs = plt.subplots(1, 3)
= axs.ravel()
set_size_inches(18, 12)
er = tuple([slice(None), slice(10, -10), slice(10, -10)])
es = ['Original Image', 'Blurred Image', 'Reconstructed Image']
i, d in enumerate([actual, data, res]):
img = exposure.adjust_gamma(d[center].max(axis=0), gamma=.2)
axs[i].imshow(img, cmap='Spectral_r')
axs[i].set_title(titles[i])
axs[i].axis('off')
As a more realistic use case, here is an example showing how a point spread function configuration can be used in a headless deconvolution:
See full deconvolution script here
nerate a configuration file containing PSF parameters (see flowdec.psf module for more details)
'{"na": 0.75, "wavelength": 0.425, "size_z": 32, "size_x": 64, "size_y": 64}' > /tmp/psf.json
voke deconvolution script with the above PSF configuration and an input dataset to deconvolve
on examples/scripts/deconvolution.py \
ta-path=flowdec/datasets/bars-25pct/data.tif \
f-config-path=/tmp/psf.json \
tput-path=/tmp/result.tif \
iter=25 --log-level=DEBUG
BUG:Loaded data with shape (32, 64, 64) and psf with shape (32, 64, 64)
FO:Beginning deconvolution of data file "flowdec/datasets/bars-25pct/data.tif"
FO:Deconvolution complete (in 7.427 seconds)
FO:Result saved to "/tmp/result.tif"
The project can be installed, ideally in a python 3.6 environment (though it should work in 3.5 too), by running:
clone https://github.com/hammerlab/flowdec.git
lowdec
install .
A local docker image can be built by running:
lowdec # Note: not flowdec/docker, just cd flowdec
er build --no-cache -t flowdec -f docker/Dockerfile .
on a system that supports nvidia-docker, the GPU-enabled version can be built instead via:
idia-docker build --no-cache -t flowdec -f docker/Dockerfile.gpu .
The image can then be run using:
n in foreground (port mapping is host:container if 8888 is already taken)
er run -ti -p 8888:8888 flowdec
n in background
er run -td -p 8888:8888 --name flowdec flowdec
er exec -it flowdec /bin/bash # Connect
The Flowdec dockerfile extends the TensorFlow DockerHub Images so its usage is similar where running it in the foreground automatically starts jupyter notebook and prints a link to connect to it via a browser on the host system.
Thanks to Kyle Douglass for explaining some of the finer aspects of this Python Gibson-Lanni PSF generator, Jizhou Li for helping to better understand that diffraction model, Hadrien Mary for giving great context on the state of open-source deconvolution libraries, and Brian Northan for lending great advice/context on library performance, blind deconvolution and how point spread functions work in general.
`apt-get install -y default-jdk maven
`