Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This script deconvolves with a theoretical PSF that has the lower half zeroed as an attempt to deconvolve images form a section cutting device.
#@ OpService ops
#@ UIService ui
#@ ImgPlus img
#@ Integer numIterations(value=20)
#@ Float numericalAperture(value=0.25)
#@ Float wavelength(value=705)
#@ Float riImmersion(value=1.00)
#@ Float riSample(value=1.5)
#@ Float xySpacing(value=570)
#@ Float zSpacing(value=1700)
#@OUTPUT ImgPlus psf
#@OUTPUT ImgPlus deconvolved
from net.imglib2.util import Intervals
from net.imglib2 import FinalInterval
from net.imglib2 import FinalDimensions
from net.imglib2.type.numeric.real import FloatType;
from net.imglib2.view import Views
# convert to float (TODO: make sure deconvolution op works on other types)
imgF=ops.convert().float32(img)
# make psf same size as image
psfSize=FinalDimensions([img.dimension(0), img.dimension(1), img.dimension(2)]);
# convert wavelength to meters
wavelength=wavelength*1E-9
xySpacing=xySpacing*1E-9
zSpacing=zSpacing*1E-9
# imaging depth 0
depth=0;
# create the PSF
psf = ops.create().kernelDiffraction(psfSize, numericalAperture, wavelength,
riSample, riImmersion, xySpacing, zSpacing, depth, FloatType());
# subtract background from psf to avoid a discontuinity after zeroing the first half
for t in psf:
val=t.getRealFloat()-.0001;
if val<0:
val=0;
t.setReal(val);
# zero out half the PSF by first defining an interval over the bottom half of the PSF
bottomHalf=Views.interval(psf, Intervals.createMinMax(0, 0, psf.dimension(2)/2,
psf.dimension(0)-1, psf.dimension(1)-1, psf.dimension(2)-1));
# then loop through the interval and set each voxel to 0
for t in bottomHalf:
t.setReal(0);
# create output
out = ops.create().img(imgF);
# add border in z direction
borderSize=[0,0,psfSize.dimension(2)/2];
deconvolved = ops.deconvolve().richardsonLucy(imgF, psf, borderSize, None,
None, None, None, numIterations, False, True);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.