Skip to content

Instantly share code, notes, and snippets.

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)
# make psf same size as image
psfSize=FinalDimensions([img.dimension(0), img.dimension(1), img.dimension(2)]);
# convert wavelength to meters
# imaging 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:
if val<0:
# 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:
# create output
out = ops.create().img(imgF);
# add border in z direction
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.