def runner(parser, options, args): if not hasattr(parser, 'runner'): options.psf_path = None options.input_path = None options.output_path = None if args: if len(args) in [2, 3]: if options.psf_path: print >> sys.stderr, "WARNING: overwriting psf path %r with %r" % ( options.psf_path, args[0]) options.psf_path = args[0] if options.input_path: print >> sys.stderr, "WARNING: overwriting input path %r with %r" % ( options.input_path, args[1]) options.input_path = args[1] else: parser.error( "Incorrect number of arguments (expected 2 or 3 but got %r)" % ((args))) if len(args) == 3: if options.output_path: print >> sys.stderr, "WARNING: overwriting output path %r with %r" % ( options.output_path, args[2]) options.output_path = args[2] options.input_path = fix_path(options.input_path) if options.output_path is None: deconvolve_dir = get_path_dir(options.input_path, 'iocbio.deconvolve') else: deconvolve_dir = get_path_dir(options.output_path, 'iocbio.deconvolve') psf_path = get_psf_path(options) psf = ImageStack.load(psf_path, options=options) stack = ImageStack.load(options.input_path, options=options) deconvolved_image = deconvolve(psf, stack, deconvolve_dir, options=options) if options.output_path is None: b, e = os.path.splitext(options.input_path) suffix = deconvolved_image.pathinfo.suffix options.output_path = b + suffix + (e or '.tif') options.output_path = fix_path(options.output_path) if 1: print 'Saving result to %r' % (options.output_path) deconvolved_image.save(options.output_path)
import numpy from iocbio.ops import convolve from iocbio.microscope.deconvolution import deconvolve from iocbio.io import ImageStack import scipy.stats from matplotlib import pyplot as plt kernel = numpy.array([0, 1, 3, 1, 0]) test_data = numpy.array([0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0]) * 50 data = convolve(kernel, test_data) degraded_data = scipy.stats.poisson.rvs(numpy.where(data <= 0, 1e-16, data)).astype(data.dtype) psf = ImageStack(kernel, voxel_sizes=(1, )) stack = ImageStack(degraded_data, voxel_sizes=(1, )) deconvolved_data = deconvolve(psf, stack).images plt.plot(test_data, label='test') plt.plot(data, label='convolved') plt.plot(degraded_data, label='degraded') plt.plot(deconvolved_data, label='deconvolved') plt.legend() plt.ylabel('data') plt.xlabel('index') plt.title('Deconvolving degraded test data.') plt.savefig('deconvolve_poisson_1d.png') plt.show()
import numpy from iocbio.ops import convolve from iocbio.microscope.deconvolution import deconvolve from iocbio.io import ImageStack import scipy.stats from matplotlib import pyplot as plt kernel = numpy.array([0,1,3,1,0]) test_data = numpy.array([0, 0,0,0,2, 0,0,0,0, 0,1,0,1, 0,0,0])*50 data =convolve(kernel, test_data) degraded_data = scipy.stats.poisson.rvs(numpy.where(data<=0, 1e-16, data)).astype(data.dtype) psf = ImageStack(kernel, voxel_sizes = (1,)) stack = ImageStack(degraded_data, voxel_sizes = (1,)) deconvolved_data = deconvolve(psf, stack).images plt.plot(test_data, label='test') plt.plot (data, label='convolved') plt.plot (degraded_data, label='degraded') plt.plot (deconvolved_data, label='deconvolved') plt.legend() plt.ylabel('data') plt.xlabel('index') plt.title('Deconvolving degraded test data.') plt.savefig('deconvolve_poisson_1d.png') plt.show ()