mdreg.fit#

mdreg.fit(moving, fit_pixels=None, fit_coreg=None, fit_image=None, tol=1e-06, maxit=5, verbose=0, force_2d=False, path=None)[source]#

Remove motion from a series of 2D- or 3D images.

Parameters:
  • moving (numpy.ndarray | zarr.Array) – The series of images to be corrected, with dimensions (x,y,t) or (x,y,z,t).

  • fit_pixels (dict, optional) – A dictionary defining a single-pixel signal model. The possible items in the dictionary are the keywords of the function mdreg.fit_pixels. For a slice-by-slice computation (4D array with force_2d=True), fit_pixels can be a list of dictionaries, one for each slice. The default is None.

  • fit_coreg (dict, optional) – The parameters for coregistering the images. fit_coreg has one required item ‘package’ with possible values ‘skimage’ (default), ‘elastix’ and ‘ants’. The other parameters are the possible keywords of the coreg_series function of the package specified.

  • fit_image (dict or list, optional) – A dictionary defining the function to fit the signal data, and its parameter values. This argument is ignored if fit_pixels is already provided. fit_image has one required key ‘func’ that specifies the fit function to use. The other entries are the keyword arguments of this fit function. The fit function can be one of the functions built in to mdreg, or a custom made function. A valid fit function must take a signal array as argument, and return two variables: an array with the same shape containing the fit to the model, and a second variable that contains the fitted parameters. For a slice-by-slice computation (4D array with force_2d=True), fit_image can be a list of dictionaries, one for each slice. If fit_image is not provided, a constant model is used.

  • tol (float, optional) – Stopping criterion for the iteration. The iteration stops if the largest difference between new and old coregistered series in any pixel at any time point is less than tol of the largest value. The default is 1e-6.

  • maxit (int, optional) – The maximum number of iterations. The default is 0.

  • verbose (int, optional) – The level of feedback to provide to the user. 0: no feedback; 1: text output only; 2: text output and progress bars. The default is 2.

  • force_2d (bool, optional) – By default, a 3-dimensional moving array will be coregistered with a 3-dimensional deformation field. To perform slice-by-slice 2-dimensional registration instead, set force_2d to True. This keyword is ignored when the arrays are 2-dimensional. The default is False.

  • path (str, optional) – Path on disk where to save the results. If no path is provided, the results are not saved to disk. Defaults to None.

Returns:

  • coreg (numpy.ndarray | zarr.Array) – The coregistered images with the same dimensions as moving.

  • fit (numpy.ndarray | zarr.Array) – The fitted signal model with the same dimensions as arr.

  • transfo (numpy.ndarray | zarr.Array | list) – The parameters of the transformation deforming the moving image to the coregistered image. With skimage, this is the deformation field with the same dimensions as moving, and one additional dimension for the components of the vector field. With elastix this is an array of parameter objects and with ants this is an array of files with transform parameters. Note when force_2d = True these are 2-dimensional arrays with one transform per slice and per time point.

  • pars (numpy.ndarray | zarr.Array) – The parameters of the fitted signal model with dimensions (x,y,n) or (x,y,z,n), where n is the number of free parameters of the signal model.