peri.runner

peri.runner.locate_spheres(image, feature_rad, dofilter=False, order=(3, 3, 3), trim_edge=True, **kwargs)

Get an initial featuring of sphere positions in an image.

Parameters:
  • image (peri.util.Image object) – Image object which defines the image file as well as the region.
  • feature_rad (float) – Radius of objects to find, in pixels. This is a featuring radius and not a real radius, so a better value is frequently smaller than the real radius (half the actual radius is good). If use_tp is True, then the twice feature_rad is passed as trackpy’s diameter keyword.
  • dofilter (boolean, optional) – Whether to remove the background before featuring. Doing so can often greatly increase the success of initial featuring and decrease later optimization time. Filtering functions by fitting the image to a low-order polynomial and featuring the residuals. In doing so, this will change the mean intensity of the featured image and hence the good value of minmass will change when dofilter is True. Default is False.
  • order (3-element tuple, optional) – If dofilter, the 2+1D Leg Poly approximation to the background illumination field. Default is (3,3,3).
Other Parameters:
 
  • invert (boolean, optional) – Whether to invert the image for featuring. Set to True if the image is dark particles on a bright background. Default is True
  • minmass (Float or None, optional) – The minimum mass/masscut of a particle. Default is None, which calculates internally.
  • use_tp (Bool, optional) – Whether or not to use trackpy. Default is False, since trackpy cuts out particles at the edge.
Returns:

positions – Positions of the particles in order (z,y,x) in image pixel units.

Return type:

np.ndarray [N,3]

Notes

Optionally filters the image by fitting the image I(x,y,z) to a polynomial, then subtracts this fitted intensity variation and uses centroid methods to find the particles.

peri.runner.optimize_from_initial(s, max_mem=1000000000.0, invert=True, desc=”, rz_order=3, min_rad=None, max_rad=None)

Optimizes a state from an initial set of positions and radii, without any known microscope parameters.

Parameters:
  • s (peri.states.ImageState) – The state to optimize. It is modified internally and returned.
  • max_mem (Numeric, optional) – The maximum memory for the optimizer to use. Default is 1e9 (bytes)
  • invert (Bool, optional) – True if the image is dark particles on a bright background, False otherwise. Used for add-subtract. Default is True.
  • desc (String, optional) – An additional description to infix for periodic saving along the way. Default is the null string ''.
  • rz_order (int, optional) – rz_order as passed to opt.burn. Default is 3
  • min_rad (Float or None, optional) – The minimum radius to identify a particles as bad, as passed to add-subtract. Default is None, which picks half the median radii. If your sample is not monodisperse you should pick a different value.
  • max_rad (Float or None, optional) – The maximum radius to identify a particles as bad, as passed to add-subtract. Default is None, which picks 1.5x the median radii. If your sample is not monodisperse you should pick a different value.
Returns:

s – The optimized state, which is the same as the input s but modified in-place.

Return type:

peri.states.ImageState

Links the state st psf zscale with the global zscale

peri.runner.finish_state(st, desc=’finish-state’, invert=True)

Final optimization for the best-possible state.

Runs a local add-subtract to capture any difficult-to-feature particles, then does another set of optimization designed to get to the best possible fit.

Parameters:
  • st (peri.states.ImageState) – The state to finish
  • desc (String, optional) – Description to intermittently save the state as, as passed to state.save. Default is ‘finish-state’.
  • invert (Bool) – Whether to invert the image for featuring, as passed to addsubtract.add_subtract. Default is True.