random_crop_warp#

omnipose.core.random_crop_warp(img, Y, tyx, v1, v2, nchan, rescale, scale_range, gamma_range, do_flip, ind, do_labels=True, depth=0)[source]#

This sub-fuction of random_rotate_and_resize() recursively performs random cropping until a minimum number of cell pixels are found, then proceeds with augemntations.

Parameters
  • X (float, list of ND arrays) -- image array of size [nchan x Lt x Ly x Lx] or [Lt x Ly x Lx]

  • Y (float, ND array) -- image label array of size [nlabels x Lt x Ly x Lx] or [Lt x Ly x Lx].. The 1st channel of Y is always nearest-neighbor interpolated (assumed to be masks or 0-1 representation). If Y.shape[0]==3, then the labels are assumed to be [cell probability, T flow, Y flow, X flow].

  • tyx (int, tuple) -- size of transformed images to return, e.g. (Ly,Lx) or (Lt,Ly,Lx)

  • nchan (int) -- number of channels the images have

  • rescale (float, array or list) -- how much to resize images by before performing augmentations

  • scale_range (float) -- Range of resizing of images for augmentation. Images are resized by (1-scale_range/2) + scale_range * np.random.rand()

  • gamma_range (float, list) -- images are gamma-adjusted im**gamma for gamma in [low,high]

  • do_flip (bool (optional, default True)) -- whether or not to flip images horizontally

  • ind (int) -- image index (for debugging)

  • dist_bg (float) -- nonegative value X for assigning -X to where distance=0 (deprecated, now adapts to field values)

  • depth (int) -- how many time this function has been called on an image

Returns

  • imgi (float, ND array) -- transformed images in array [nchan x xy[0] x xy[1]]

  • lbl (float, ND array) -- transformed labels in array [nchan x xy[0] x xy[1]]

  • scale (float, 1D array) -- scalar by which the image was resized