Exemple #1
0
def create_state(image, pos, rad, slab=None, sigma=0.05, conf=conf_simple):
    """
    Create a state from a blank image, set of pos and radii

    Parameters:
    -----------
    image : `peri.util.Image` object
        raw confocal image with which to compare.

    pos : initial conditions for positions (in raw image coordinates)
    rad : initial conditions for radii array (can be scalar)
    sigma : float, noise level

    slab : float
        z-position of the microscope slide in the image (pixel units)
    """
    # we accept radius as a scalar, so check if we need to expand it
    if not hasattr(rad, '__iter__'):
        rad = rad * np.ones(pos.shape[0])

    model = models.models[conf.get('model')]()

    # setup the components based on the configuration
    components = []
    for k, v in conf.get('comps', {}).iteritems():
        args = conf.get('args').get(k, {})
        comp = model.registry[k][v](**args)
        components.append(comp)

    sphs = objs.PlatonicSpheresCollection(pos, rad)
    if slab is not None:
        sphs = ComponentCollection([sphs, objs.Slab(zpos=slab + pad)],
                                   category='obj')
    components.append(sphs)

    s = states.ImageState(image, components, sigma=sigma)

    if isinstance(image, util.NullImage):
        s.model_to_data()
    return s
Exemple #2
0
def create_img():
    """Creates an image, as a `peri.util.Image`, which is similar
    to the image in the tutorial"""
    # 1. particles + coverslip
    rad = 0.5 * np.random.randn(POS.shape[0]) + 4.5  # 4.5 +- 0.5 px particles
    part = objs.PlatonicSpheresCollection(POS, rad, zscale=0.89)
    slab = objs.Slab(zpos=4.92, angles=(-4.7e-3, -7.3e-4))
    objects = comp.ComponentCollection([part, slab], category='obj')

    # 2. psf, ilm
    p = exactpsf.FixedSSChebLinePSF(kfki=1.07, zslab=-29.3, alpha=1.17,
            n2n1=0.98, sigkf=-0.33, zscale=0.89, laser_wavelength=0.45)
    i = ilms.BarnesStreakLegPoly2P1D(npts=(16,10,8,4), zorder=8)
    b = ilms.LegendrePoly2P1D(order=(7,2,2), category='bkg')
    off = comp.GlobalScalar(name='offset', value=-2.11)
    mdl = models.ConfocalImageModel()
    st = states.ImageState(util.NullImage(shape=[48,64,64]),
            [objects, p, i, b, off], mdl=mdl, model_as_data=True)
    b.update(b.params, BKGVALS)
    i.update(i.params, ILMVALS)
    im = st.model + np.random.randn(*st.model.shape) * 0.03
    return util.Image(im)
Exemple #3
0
psf = exactpsf.FixedSSChebLinePSF()
st = states.ImageState(im_ilm, [ilm, psf], mdl=models.BlurredFieldModel())
opt.do_levmarq(st, st.params)

# Plotting the residuals shows that they're good, aside from scan noise
# inherent to the line CCD camera:

plot_averaged_residuals(st)

# Next, we include the coverslip slide. To do this we first re-set the tile on
# our raw image to the full image:
im_ilm.set_tile(util.Tile([0, 0, 0], [60, 100, 100]))

# We then create a coverslip object:
slab = objs.Slab(zpos=35.0, category='obj')
# We also need our illumination to have a z-dependence now. Since we already
# spent time updating the ilm parameters, we update the corresponding values
# of the new ilm to the older ones:
ilm_z = ilms.BarnesStreakLegPoly2P1D(npts=(50, 30, 20, 13, 7, 7, 7), zorder=7)
ilm_z.set_values(ilm.params, ilm.values)
# Keep in mind that setting the parameters only works for this certain
# ilm classes. The BarnesStreakLegPoly2P1D (1) has the same named Barnes
# parameters regardless of the z-order, and (2) these determine the ilm field
# in the xy-plane in the same way when the number of points is the same and
# the image shape is the same. In contrast, if we had fit the in-plane
# illumination with a lower set of npts, just setting the parameters wouldn't
# work. [This is because the BarnesStreakLegPoly2P1D barnes parameters are
# labeled according to their distance from the leftmost edge of the image. So
# ilm-b0-49 would be on the rightmost side of the image if npts=(50,...), but
# it would be in the middle of the image if npts=(100,...).] We could get
Exemple #4
0
from peri import util
from peri.viz.interaction import OrthoViewer
import matplotlib

im = util.RawImage('../../Downloads/small_confocal_image.tif')

import numpy
from peri.comp import objs

coverslip = objs.Slab(zpos=6)
particle_positions = numpy.load('../../Downloads/particle-positions.npy')
particle_radii = 5.0
particles = objs.PlatonicSpheresCollection(particle_positions, particle_radii)

from peri.comp import comp

objects = comp.ComponentCollection([particles, coverslip], category='obj')

from peri.comp import ilms

illumination = ilms.BarnesStreakLegPoly2P1D(npts=(16, 10, 8, 4), zorder=8)

background = ilms.LegendrePoly2P1D(order=(7, 2, 2), category='bkg')

offset = comp.GlobalScalar(name='offset', value=0.)

from peri.comp import exactpsf

point_spread_function = exactpsf.FixedSSChebLinePSF()

from peri import models
Exemple #5
0
from peri import states, util, models
from peri.comp import psfs, objs, ilms, GlobalScalar, ComponentCollection
from peri.test import nbody

import peri.opt.optimize as opt
import peri.opt.addsubtract as addsub

im = util.NullImage(shape=(32, ) * 3)
pos, rad, tile = nbody.create_configuration(3, im.tile)

P = ComponentCollection(
    [objs.PlatonicSpheresCollection(pos, rad),
     objs.Slab(2)], category='obj')

H = psfs.AnisotropicGaussian()
I = ilms.BarnesStreakLegPoly2P1D(npts=(25, 13, 3),
                                 zorder=2,
                                 local_updates=False)
B = ilms.LegendrePoly2P1D(order=(3, 1, 1), category='bkg', constval=0.01)
C = GlobalScalar('offset', 0.0)
I.randomize_parameters()

s = states.ImageState(im, [B, I, H, P, C], pad=16, model_as_data=True)