def runner(parser, options, args): if not hasattr(parser, 'runner'): options.output_path = None if args: raise NotImplementedError( ` args `) if len(args) == 1: if options.input_path: print >> sys.stderr, "WARNING: overwriting input path %r with %r" % ( options.input_path, args[0]) options.input_path = args[0] elif len(args) == 2: if options.input_path: print >> sys.stderr, "WARNING: overwriting input path %r with %r" % ( options.input_path, args[0]) options.input_path = args[0] options.output_path = args[1] else: parser.error( "incorrect number of arguments (expected upto 2 but got %s)" % (len(args))) options.kernel_path = fix_path(options.kernel_path) options.input_path = fix_path(options.input_path) if options.output_path is None: b, e = os.path.splitext(options.input_path) suffix = '_convolved' % () options.output_path = b + suffix + (e or '.tif') options.output_path = fix_path(options.output_path) kernel = ImageStack.load(options.kernel_path, options=options) stack = ImageStack.load(options.input_path, options=options) result = convolve(kernel.images, stack.images, options=options) if 1: print 'Saving result to', options.output_path ImageStack(result, stack.pathinfo).save(options.output_path)
def runner(parser, options, args): if not hasattr(parser, 'runner'): options.output_path = None if args: raise NotImplementedError (`args`) if len (args)==1: if options.input_path: print >> sys.stderr, "WARNING: overwriting input path %r with %r" % (options.input_path, args[0]) options.input_path = args[0] elif len(args)==2: if options.input_path: print >> sys.stderr, "WARNING: overwriting input path %r with %r" % (options.input_path, args[0]) options.input_path = args[0] options.output_path = args[1] else: parser.error("incorrect number of arguments (expected upto 2 but got %s)" % (len(args))) options.kernel_path = fix_path(options.kernel_path) options.input_path = fix_path(options.input_path) if options.output_path is None: b,e = os.path.splitext(options.input_path) suffix = '_convolved' % () options.output_path = b + suffix + (e or '.tif') options.output_path = fix_path(options.output_path) kernel = ImageStack.load(options.kernel_path, options=options) stack = ImageStack.load(options.input_path, options=options) result = convolve (kernel.images, stack.images, options=options) if 1: print 'Saving result to',options.output_path ImageStack(result, stack.pathinfo).save(options.output_path)
from numpy import * from scipy.stats import poisson from iocbio.ops import convolve kernel = array([0, 1, 2, 2, 2, 1, 0]) x = arange(0, 2 * pi, 0.1) data = 50 + 7 * sin(x) + 5 * sin(2 * x) data_with_noise = poisson.rvs(data) data_convolved = convolve(kernel, data_with_noise) from matplotlib import pyplot as plt plt.plot(x, data, label='data') plt.plot(x, data_with_noise, 'o', label='data with poisson noise') plt.plot(x, data_convolved, label='convolved noisy data') plt.legend() plt.xlabel('x') plt.ylabel('data') plt.title('Convolution with %s for recovering data=50+7*sin(x)+5*sin(2*x)' % (kernel)) plt.savefig('convolve_1d.png') plt.show()
from numpy import * from scipy.stats import poisson from iocbio.ops import convolve kernel = array([0,1,2,2,2,1,0]) x = arange(0,2*pi,0.1) data = 50+7*sin(x)+5*sin(2*x) data_with_noise = poisson.rvs(data) data_convolved = convolve(kernel, data_with_noise) from matplotlib import pyplot as plt plt.plot (x,data,label='data') plt.plot (x,data_with_noise,'o',label='data with poisson noise') plt.plot (x,data_convolved,label='convolved noisy data') plt.legend () plt.xlabel ('x') plt.ylabel ('data') plt.title ('Convolution with %s for recovering data=50+7*sin(x)+5*sin(2*x)' % (kernel)) plt.savefig('convolve_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()
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 ()