API documentation#

cli#

Motion tracking of MPS data This is software to estimate motion in Brightfield images.

class mps_motion.cli.JSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]#
default(obj)[source]#

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
mps_motion.cli.main(filename: str | Path, algorithm: FLOW_ALGORITHMS = FLOW_ALGORITHMS.farneback, outdir: str | None = None, reference_frame: str = '0', estimate_reference_frame: bool = True, scale: float = 1.0, apply_filter: bool = True, spacing: int = 5, compute_xy_components: bool = False, make_displacement_video: bool = True, make_velocity_video: bool = True, verbose: bool = False, video_disp_scale: int = 4, video_disp_step: int = 24, video_vel_scale: int = 1, video_vel_step: int = 24, suppress_error: bool = False, start_x: int | None = None, end_x: int | None = None, start_y: int | None = None, end_y: int | None = None, start_t: float | None = None, end_t: float | None = None)[source]#

Estimate motion in stack of images

Parameters:
  • filename (str) – Path to file to be analyzed, typically an .nd2 or .czi Brightfield file

  • algorithm (mt.FLOW_ALGORITHMS, optional) – The algorithm used to estimate motion, by default mt.FLOW_ALGORITHMS.farneback

  • outdir (Optional[str], optional) – Directory where to store the results. If not provided, a folder with the the same as the filename will be created and results will be stored in a subfolder inside that called motion.

  • reference_frame (str, optional) – Which frame should be the reference frame when computing the displacements. This can either be a number indicating the timepoint, or the value ‘mean’, ‘median’, ‘max’ or ‘mean’. Default: ‘0’ (i.e the first frame)

  • estimate_reference_frame (bool, optional) – If True, estimate the the reference frame, by default True. Note that this will overwrite the argument reference_frame

  • scale (float, optional) – Rescale data before running motion track. This is useful if the spatial resolution of the images are large. Scale = 1.0 will keep the original size, by default 0.3

  • apply_filter – If True, set pixels with max displacement lower than the mean maximum displacement to zero. This will prevent non-tissue pixels to be included, which is especially error prone for velocity estimations, by default True.

  • bool – If True, set pixels with max displacement lower than the mean maximum displacement to zero. This will prevent non-tissue pixels to be included, which is especially error prone for velocity estimations, by default True.

  • optional – If True, set pixels with max displacement lower than the mean maximum displacement to zero. This will prevent non-tissue pixels to be included, which is especially error prone for velocity estimations, by default True.

  • spacing (int, optional) – Spacing between frames in velocity computations, by default 5.

  • compute_xy_components (bool, optional) – If True the compute x- and y components of the displacement and velocity and plot them as well, by default False.

  • make_displacement_video (bool, optional) – If True, create video of displacement vectors, by default False.

  • make_velocity_video (bool, optional) – If True, create video of velocity vectors, by default False.

  • verbose (bool, optional) – Print more to the console, by default False

  • overwrite (bool, optional) – If outdir allready exist an contains the relevant files then set this to false to use that data, by default True

Raises:
  • IOError – If filename does not exist

  • ValueError – If scale is zero or lower, or higher than 1.0

block_matching#

mps_motion.block_matching.flow(image: ndarray, reference_image: ndarray, block_size: str | int = 'auto', max_block_movement: str | int = 'auto', resize: bool = True)[source]#

Computes the displacements from reference_image to image using a block matching algorithm. Briefly, we subdivde the images into blocks of size block_size x block_size and compare the two images within a range of +/- max_block_movement for each block.

Parameters:
  • image (np.ndarray) – The frame that you want to compute displacement for relative to the referernce frame

  • reference_image (np.ndarray) – The frame used as reference

  • block_size (int) – Size of the blocks

  • max_block_movement (int) – Maximum allowed movement of blocks when searching for best match.

  • resize (bool) – If True, make sure to resize the output images to have the same shape as the input, by default True.

Note

Make sure to have max_block_movement big enough. If this is too small then the results will be wrong. It is better to choose a too large value of this. However, choosing a too large value will mean that you need to compare more blocks which will increase the running time.

mps_motion.block_matching.flow_map(args)[source]#

Helper function for running block maching algorithm in paralell

mps_motion.block_matching.get_displacements(frames: ndarray, reference_image: ndarray, block_size: str | int = 'auto', max_block_movement: str | int = 'auto', resize=True, **kwargs) Array | ndarray[source]#

Computes the displacements from reference_image to all frames using a block matching algorithm. Briefly, we subdivde the images into blocks of size block_size x block_size and compare the two images within a range of +/- max_block_movement for each block.

Parameters:
  • frames (np.ndarray) – The frame that you want to compute displacement for relative to the referernce frame. Input must be of shape (N, M, T, 2), where N is the width, M is the height and T is the number number of frames.

  • reference_image (np.ndarray) – The frame used as reference

  • block_size (int) – Size of the blocks, by default 9

  • max_block_movement (int) – Maximum allowed movement of blocks when searching for best match, by default 18.

  • resize (bool) – If True, make sure to resize the output images to have the same shape as the input, by default True.

Note

Make sure to have max_block_movement big enough. If this is too small then the results will be wrong. It is better to choose a too large value of this. However, choosing a too large value will mean that you need to compare more blocks which will increase the running time.

Returns:

utils.Array with displacement of shape (N’, M’, T’, 2), where N’ is the width, M’ is the height and T’ is the number number of frames. Note if resize=True then we have (N, M, T, 2) = (N’, M’, T’, 2).

Return type:

utils.Array

dualtvl1#

ZACH, Christopher; POCK, Thomas; BISCHOF, Horst. A duality based approach for realtime tv-l 1 optical flow. In: Joint pattern recognition symposium. Springer, Berlin, Heidelberg, 2007. p. 214-223.

http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.709.4597&rep=rep1&type=pdf

mps_motion.dualtvl1.get_displacements(frames: ndarray, reference_image: ndarray, tau: float = 0.25, lmbda: float = 0.08, theta: float = 0.37, nscales: int = 6, warps: int = 5, **kwargs) Array | ndarray[source]#

Compute the optical flow using the Dual TV-L1 method from the reference frame to all other frames

Parameters:
  • frames (np.ndarray) – The frames with some moving objects

  • reference_image (np.ndarray) – The reference image

  • tau (float, optional) – Time step of the numerical scheme, by default 0.25

  • lmbda (float, optional) – Weight parameter for the data term, attachment parameter. This is the most relevant parameter, which determines the smoothness of the output. The smaller this parameter is, the smoother the solutions we obtain. It depends on the range of motions of the images, so its value should be adapted to each image sequence, by default 0.08

  • theta (float, optional) – parameter used for motion estimation. It adds a variable allowing for illumination variations Set this parameter to 1. if you have varying illumination. See: Chambolle et al, A First-Order Primal-Dual Algorithm for Convex Problems with Applications to Imaging Journal of Mathematical imaging and vision, may 2011 Vol 40 issue 1, pp 120-145, by default 0.37

  • nscales (int, optional) – Number of scales used to create the pyramid of images, by default 6

  • warps (int, optional) – Number of warpings per scale. Represents the number of times that I1(x+u0) and grad( I1(x+u0) ) are computed per scale. This is a parameter that assures the stability of the method. It also affects the running time, so it is a compromise between speed and accuracy., by default 5

Returns:

An array of motion vectors relative to the reference image. If shape of input frames are (N, M, T) then the shape of the output is (N, M, T, 2).

Return type:

Array

farneback#

Farnebäck, G. (2003, June). Two-frame motion estimation based on polynomial expansion. In Scandinavian conference on Image analysis (pp. 363-370). Springer, Berlin, Heidelberg.

mps_motion.farneback.flow(image: ndarray, reference_image: ndarray, pyr_scale: float = 0.5, levels: int = 3, winsize: int = 15, iterations: int = 3, poly_n: int = 5, poly_sigma: float = 1.2, flags: int = 0, factor: float = 1.0)[source]#

Compute the optical flow using the Farneback method from the reference frame to another image

Parameters:
  • image (np.ndarray) – The target image

  • reference_image (np.ndarray) – The reference image

  • pyr_scale (float, optional) – parameter, specifying the image scale (<1) to build pyramids for each image; pyr_scale=0.5 means a classical pyramid, where each next layer is twice smaller than the previous one, by default 0.5

  • levels (int, optional) – number of pyramid layers including the initial image; levels=1 means that no extra layers are created and only the original images are used, by default 3

  • winsize (int, optional) – averaging window size; larger values increase the algorithm robustness to image noise and give more chances for fast motion detection, but yield more blurred motion field, by default 15

  • iterations (int, optional) – number of iterations the algorithm does at each pyramid level, by default 3

  • poly_n (int, optional) – size of the pixel neighborhood used to find polynomial expansion in each pixel. larger values mean that the image will be approximated with smoother surfaces, yielding more robust algorithm and more blurred motion field, typically poly_n =5 or 7., by default 5

  • poly_sigma (float, optional) – standard deviation of the Gaussian that is used to smooth derivatives used as a basis for the polynomial expansion; for poly_n=5, you can set poly_sigma=1.1, for poly_n=7, a good value would be poly_sigma=1.5, by default 1.2

  • flags (int, optional) – By default 0. operation flags that can be a combination of the following: - OPTFLOW_USE_INITIAL_FLOW uses the input flow as an initial flow approximation. - OPTFLOW_FARNEBACK_GAUSSIAN uses the Gaussian winsize x winsize filter instead of a box filter of the same size for optical flow estimation; usually, this option gives z more accurate flow than with a box filter, at the cost of lower speed; normally, winsize for a Gaussian window should be set to a larger value to achieve the same level of robustness.

  • factor (float) – Factor to multiply the result

Returns:

The motion vectors

Return type:

np.ndarray

mps_motion.farneback.get_displacements(frames, reference_image: ndarray, pyr_scale: float = 0.5, levels: int = 3, winsize: int = 15, iterations: int = 3, poly_n: int = 5, poly_sigma: float = 1.2, flags: int = 0, **kwargs) Array | ndarray[source]#

Compute the optical flow using the Farneback method from the reference frame to all other frames

Parameters:
  • frames (np.ndarray) – The frames with some moving objects

  • reference_image (np.ndarray) – The reference image

  • pyr_scale (float, optional) – parameter, specifying the image scale (<1) to build pyramids for each image; pyr_scale=0.5 means a classical pyramid, where each next layer is twice smaller than the previous one, by default 0.5

  • levels (int, optional) – number of pyramid layers including the initial image; levels=1 means that no extra layers are created and only the original images are used, by default 3

  • winsize (int, optional) – averaging window size; larger values increase the algorithm robustness to image noise and give more chances for fast motion detection, but yield more blurred motion field, by default 15

  • iterations (int, optional) – number of iterations the algorithm does at each pyramid level, by default 3

  • poly_n (int, optional) – size of the pixel neighborhood used to find polynomial expansion in each pixel. larger values mean that the image will be approximated with smoother surfaces, yielding more robust algorithm and more blurred motion field, typically poly_n =5 or 7., by default 5

  • poly_sigma (float, optional) – standard deviation of the Gaussian that is used to smooth derivatives used as a basis for the polynomial expansion; for poly_n=5, you can set poly_sigma=1.1, for poly_n=7, a good value would be poly_sigma=1.5, by default 1.2

  • flags (int, optional) – By default 0. operation flags that can be a combination of the following: - OPTFLOW_USE_INITIAL_FLOW uses the input flow as an initial flow approximation. - OPTFLOW_FARNEBACK_GAUSSIAN uses the Gaussian winsize x winsize filter instead of a box filter of the same size for optical flow estimation; usually, this option gives z more accurate flow than with a box filter, at the cost of lower speed; normally, winsize for a Gaussian window should be set to a larger value to achieve the same level of robustness.

Returns:

An array of motion vectors relative to the reference image. If shape of input frames are (N, M, T) then the shape of the output is (N, M, T, 2).

Return type:

Array

mps_motion.farneback.get_velocities(frames: ndarray, time_stamps: ndarray, spacing: int = 1, pyr_scale: float = 0.5, levels: int = 3, winsize: int = 15, iterations: int = 3, poly_n: int = 5, poly_sigma: float = 1.2, flags: int = 0) Array | ndarray[source]#

Compute the optical flow using the Farneback method from the reference frame to all other frames

Parameters:
  • frames (np.ndarray) – The frames with some moving objects

  • time_stamps (np.ndarray) – Time stamps

  • spacing (int) – Spacing between frames used to compute velocities

  • pyr_scale (float, optional) – parameter, specifying the image scale (<1) to build pyramids for each image; pyr_scale=0.5 means a classical pyramid, where each next layer is twice smaller than the previous one, by default 0.5

  • levels (int, optional) – number of pyramid layers including the initial image; levels=1 means that no extra layers are created and only the original images are used, by default 3

  • winsize (int, optional) – averaging window size; larger values increase the algorithm robustness to image noise and give more chances for fast motion detection, but yield more blurred motion field, by default 15

  • iterations (int, optional) – number of iterations the algorithm does at each pyramid level, by default 3

  • poly_n (int, optional) – size of the pixel neighborhood used to find polynomial expansion in each pixel. larger values mean that the image will be approximated with smoother surfaces, yielding more robust algorithm and more blurred motion field, typically poly_n =5 or 7., by default 5

  • poly_sigma (float, optional) – standard deviation of the Gaussian that is used to smooth derivatives used as a basis for the polynomial expansion; for poly_n=5, you can set poly_sigma=1.1, for poly_n=7, a good value would be poly_sigma=1.5, by default 1.2

  • flags (int, optional) – By default 0. operation flags that can be a combination of the following: - OPTFLOW_USE_INITIAL_FLOW uses the input flow as an initial flow approximation. - OPTFLOW_FARNEBACK_GAUSSIAN uses the Gaussian winsize x winsize filter instead of a box filter of the same size for optical flow estimation; usually, this option gives z more accurate flow than with a box filter, at the cost of lower speed; normally, winsize for a Gaussian window should be set to a larger value to achieve the same level of robustness.

Returns:

An array of motion vectors relative to the reference image. If shape of input frames are (N, M, T) then the shape of the output is (N, M, T, 2).

Return type:

Array

filters#

class mps_motion.filters.Filters(value)[source]#

An enumeration.

exception mps_motion.filters.InvalidThresholdError[source]#
class mps_motion.filters.NameSpace(*args, **kwargs)[source]#
mps_motion.filters.threshold(array: Array | ndarray, vmin: float | None = None, vmax: float | None = None, copy: bool = True) Array | ndarray[source]#

Threshold an array

Parameters:
  • array (utils.Array) – The array

  • vmin (Optional[float], optional) – Lower threshold value, by default None

  • vmax (Optional[float], optional) – Upper threshold value, by default None

  • copy (bool, optional) – Operative on the given array or use a copy, by default True

Returns:

Inpute array with the lowest value beeing vmin and highest value begin vmax

Return type:

utils.Array

mps_motion.filters.threshold_norm(array: Array | ndarray, ns: NameSpace, vmin: float | None = None, vmax: float | None = None, copy: bool = True) Array | ndarray[source]#

Threshold an array of vectors based on the norm of the vectors.

For example if the vectors are displacement then you can use this function to scale all vectors so that the magnitudes are within vmin and vmax

Parameters:
  • array (utils.Array) – The input array which is 4D and the last dimension is 2.

  • ns (NameSpace) – Wheter to use numpy or dask

  • vmin (Optional[float], optional) – Lower bound on the norm, by default None

  • vmax (Optional[float], optional) – Upper bound on the norm, by default None

  • copy (bool, optional) – Wheter to operate on the input are or use a copy, by default True

Returns:

The thresholded array

Return type:

utils.Array

lucas_kanade#

Lucas, B. D., & Kanade, T. (1981). An iterative image registration technique with an application to stereo vision.

http://cseweb.ucsd.edu/classes/sp02/cse252/lucaskanade81.pdf

class mps_motion.lucas_kanade.Interpolation(value)[source]#

An enumeration.

mps_motion.lucas_kanade.flow(image: ndarray, reference_image: ndarray, points: ndarray | None = None, winSize: Tuple[int, int] = (15, 15), maxLevel: int = 2, criteria=(3, 10, 0.03), step: str | int = 'auto', interpolation: Interpolation = Interpolation.nearest) ndarray[source]#

Compute the optical from reference_image to image

Parameters:
  • image (np.ndarray) – The target image

  • reference_image (np.ndarray) – The reference image

  • points (np.ndarray) – Points where to compute the motion vectors

  • winSize (Tuple[int, int], optional) – Size of search window in each pyramid level, by default (15, 15)

  • maxLevel (int, optional) – 0-based maximal pyramid level number; if set to 0, pyramids are not used (single level), if set to 1, two levels are used, and so on; if pyramids are passed to input then algorithm will use as many levels as pyramids have but no more than maxLevel, by default 2

  • criteria (tuple, optional) – Parameter, specifying the termination criteria of the iterative search algorithm (after the specified maximum number of iterations criteria.maxCount or when the search window moves by less than criteria.epsilon, by default (cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 10, 0.03)

  • step (int, optional) – Step in pixels between points where motion is computed, by default 16

  • interpolation (Interpolation) – Interpolate flow to original shape using radial basis function (‘rbf’), nearest neigbour interpolation (‘nearest’) or do not interpolate but reshape (‘reshape’), or use the original output from the LK algorithm (‘none’), by default ‘nearest’

Returns:

Array of optical flow from reference image to image

Return type:

np.ndarray

mps_motion.lucas_kanade.get_displacements(frames, reference_image: ndarray, step: str | int = 'auto', winSize: Tuple[int, int] = (15, 15), maxLevel: int = 2, criteria=(3, 10, 0.03), interpolation: Interpolation = Interpolation.nearest, **kwargs) ndarray[source]#

Compute the optical flow using the Lucas Kanade method from the reference frame to all other frames

Parameters:
  • frames (np.ndarray) – The frames with some moving objects. Input must be of shape (N, M, T, 2), where N is the width, M is the height and T is the number

  • reference_image (np.ndarray) – The reference image

  • step (int, optional) – Step in pixels between points where motion is computed, by default 16

  • winSize (Tuple[int, int], optional) – Size of search window in each pyramid level, by default (15, 15)

  • maxLevel (int, optional) – 0-based maximal pyramid level number; if set to 0, pyramids are not used (single level), if set to 1, two levels are used, and so on; if pyramids are passed to input then algorithm will use as many levels as pyramids have but no more than maxLevel, by default 2

  • criteria (tuple, optional) – Parameter, specifying the termination criteria of the iterative search algorithm (after the specified maximum number of iterations criteria.maxCount or when the search window moves by less than criteria.epsilon, by default (cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 10, 0.03)

  • interpolation (Interpolation) – Interpolate flow to original shape using radial basis function (‘rbf’), nearest neigbour interpolation (‘nearest’) or do not interpolate but reshape (‘reshape’), or use the original output from the LK algorithm (‘none’), by default ‘nearest’

Returns:

An array of motion vectors relative to the reference image. If shape of input frames are (N, M, T) then the shape of the output is (N’, M’, T’, 2). Note if resize=True then we have (N, M, T, 2) = (N’, M’, T’, 2).

Return type:

Array

mps_motion.lucas_kanade.get_uniform_reference_points(image: ndarray, step: int = 48) ndarray[source]#

Create a grid of uniformly spaced points width the gived steps size constraind by the image dimensions.

Parameters:
  • image (np.ndarray) – An image used to set the constraint on the dimensions

  • step (int, optional) – The stepsize, by default 48

Returns:

An array of uniformly spaced points

Return type:

np.ndarray

mechanics#

mps_motion.mechanics.compute_displacement(v: Array | ndarray, t: Array | ndarray, ref_index=0, spacing: int = 1) Array[source]#

Compute displacement from velocity

Parameters:
  • v (Array) – Velocities

  • t (Array) – time stamps

  • ref_index (int, optional) – Index to be used as reference frame, by default 0

  • spacing (int, optional) – Spacing used to compute velocities, by default 1

Returns:

Displacement

Return type:

da.Array

Raises:

NotImplementedError – If spacing is different from 1

mps_motion.mechanics.compute_gradients(displacement: Array | ndarray, dx=1) Array[source]#

Compute gradients of the displacement

Parameters:
  • displacement (Array) – Displacement vectors

  • dx (int, optional) – Number of difference steps for gradient computations, by default 1

Returns:

Gradients

Return type:

da.Array

mps_motion.mechanics.compute_green_lagrange_strain_tensor(F: Array | ndarray) Array[source]#

Compute Green-Lagrange strain tensor

\[\mathbf{E} = \frac{1}{2} \left( F^T F - I \right)\]
Parameters:

F (Array) – Deformation gradient

Returns:

Green-Lagrange strain tensor

Return type:

da.Array

mps_motion.mechanics.compute_velocity(u: Array | ndarray, t: Array | ndarray, spacing: int = 1) Array[source]#

Compute velocity from displacement

Parameters:
  • u (Array) – Displacement vectors

  • t (Array) – Time stamps

  • spacing (int, optional) – Number of steps between time steps to compute velocities, by default 1

Returns:

Velocity

Return type:

da.Array

motion_tracking#

class mps_motion.motion_tracking.FLOW_ALGORITHMS(value)[source]#

An enumeration.

class mps_motion.motion_tracking.RefFrames(value)[source]#

An enumeration.

exception mps_motion.motion_tracking.ReferenceFrameError[source]#
mps_motion.motion_tracking.get_reference_image(reference_frame: float | str | RefFrames, frames: ndarray, time_stamps: ndarray | None = None, smooth_ref_transition: bool = True) ndarray[source]#

Get reference frame

Parameters:
  • reference_frame (Union[float, str, RefFrames]) – Either a float of string representing the time-point of the frame that should be used as reference

  • frames (np.ndarray) – The image frames

  • time_stamps (Optional[np.ndarray], optional) – The time stamps, by default None

  • smooth_ref_transition (bool, optional) – If true, compute the mean frame of the three closest frames, by default True

Returns:

reference_image

Return type:

np.ndarray

scaling#

mps_motion.scaling.interpolate_lk_flow(disp: ndarray, reference_points: ndarray, size_x: int, size_y: int, interpolation_method: str = 'linear') ndarray[source]#

Given an array of displacements (of flow) coming from the Lucas Kanade method return a new array which interpolates the data onto a given size, i.e the original size of the image.

Parameters:
  • disp (np.ndarray) – The flow or displacement from LK algorithm

  • reference_points (np.ndarray) – Reference points

  • size_x (int) – Size of the output in x-direction

  • size_y (int) – Size of the output in y-direction

  • interpolation_method (str) – Method for interpolation, by default ‘linear’

Returns:

Interpolated values

Return type:

np.ndarray

mps_motion.scaling.rbfinterp2d(coord, input_array, xgrid, ygrid, rbfunction='gaussian', epsilon=10, k=50, nchunks=5)[source]#

Fast 2-D grid interpolation of a sparse (multivariate) array using a radial basis function.

https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html

Parameters:
  • coord (array_like) – Array of shape (n, 2) containing the coordinates of the data points into a 2-dimensional space.

  • input_array (array_like) – Array of shape (n) or (n, m) containing the values of the data points, where n is the number of data points and m the number of co-located variables. All values in input_array are required to have finite values.

  • xgrid (array_like) – 1D arrays representing the coordinates of the 2-D output grid.

  • ygrid (array_like) – 1D arrays representing the coordinates of the 2-D output grid.

  • rbfunction ({"gaussian", "multiquadric", "inverse quadratic", "inverse multiquadric", "bump"}, optional) – The name of one of the available radial basis function based on a normalized Euclidian norm as defined in the Notes section below. More details provided in the wikipedia reference page linked below.

  • epsilon (float, optional) – The shape parameter used to scale the input to the radial kernel. A smaller value for epsilon produces a smoother interpolation. More details provided in the wikipedia reference page linked below.

  • k (int or None, optional) – The number of nearest neighbours used for each target location. This can also be useful to to speed-up the interpolation. If set to None, it interpolates using all the data points at once.

  • nchunks (int, optional) – The number of chunks in which the grid points are split to limit the memory usage during the interpolation.

Returns:

output_array – The interpolated field(s) having shape (m, ygrid.size, xgrid.size).

Return type:

ndarray

Notes

The coordinates are normalized before computing the Euclidean norms:

\[x = (x - min(x)) / max[max(x) - min(x), max(y) - min(y)], y = (y - min(y)) / max[max(x) - min(x), max(y) - min(y)],\]

where the min and max values are taken as the 2nd and 98th percentiles.

References

Wikipedia contributors, “Radial basis function,” Wikipedia, The Free Encyclopedia, https://en.wikipedia.org/w/index.php?title=Radial_basis_function&oldid=906155047 (accessed August 19, 2019).

stats#

class mps_motion.stats.Analysis(u_peaks, u_peaks_first, u_width50_global, u_width50_first, u_width50_global_first_last, u_width50_first_first_last, time_above_half_height, time_above_half_height_first, time_between_contraction_and_relaxation, max_contraction_velocity, max_relaxation_velocity, frequency)[source]#
frequency: List[float]#

Alias for field number 11

max_contraction_velocity: List[float]#

Alias for field number 9

max_relaxation_velocity: List[float]#

Alias for field number 10

time_above_half_height: List[float]#

Alias for field number 6

time_above_half_height_first: List[float]#

Alias for field number 7

time_between_contraction_and_relaxation: List[float]#

Alias for field number 8

u_peaks: List[float]#

Alias for field number 0

u_peaks_first: List[float]#

Alias for field number 1

u_width50_first: List[float]#

Alias for field number 3

u_width50_first_first_last: List[float]#

Alias for field number 5

u_width50_global: List[float]#

Alias for field number 2

u_width50_global_first_last: List[float]#

Alias for field number 4

exception mps_motion.stats.ProminenceError[source]#
mps_motion.stats.find_two_most_prominent_peaks(y, raise_on_failure: bool = False) Tuple[int, int][source]#

Return the indices of the two most promintent peaks

Parameters:

y (np.ndarray) – The signals

Returns:

Indices of the first and second peak

Return type:

Tuple[int, int]

utils#

class mps_motion.utils.LoggerWrapper(_logger: Logger, level: int = 20)[source]#

Simple wrapper around logger so that any logger can be used to log the progressbar

exception mps_motion.utils.ShapeError[source]#
mps_motion.utils.unmask(array, fill_value=0.0)[source]#

Take a mask array and fills it with the given fill value and return an regular numpy array

visu#

mps_motion.visu.draw_flow(image, flow, step=16, scale: float = 1.0, thickness: int = 2)[source]#

[summary]

Parameters:
  • image ([type]) – [description]

  • flow ([type]) – [description]

  • step (int, optional) – [description], by default 16

Returns:

[description]

Return type:

[type]