Crop#
- class deeptrack.optical.augmentations.Crop(*args, crop: int | list[int] | tuple[int] | Callable[[ndarray | Tensor], tuple[int, ...]], crop_mode: str | Callable[[...], str] = 'retain', corner: str | Callable[[...], str] = 'random', **kwargs)#
Bases:
AugmentationCrop a region of an image.
The cropped region can be specified either by defining the number of pixels to remove from the borders or by specifying the size of the output image.
Parameters#
- crop: int | tuple[int, …] | list[int] | Callable
Defines the cropping amount. If an integer, the same value is used for all axes. If a tuple or list, values are interpreted per axis. If crop_mode=”retain”, crop specifies the output size. If crop_mode=”remove”, crop specifies the number of pixels removed from the borders. A callable may also be provided, which receives the input array and returns any of the above formats.
- crop_mode: PropertyLike[str], optional
How the crop parameter is interpreted. - “retain”: crop specifies the output size. (default) - “remove”: crop specifies the number of pixels removed.
- corner: PropertyLike[str | tuple[int, int] | Callable], optional
Top-left corner of the cropped region. - “random” selects a random valid corner. (default) - A tuple specifies the corner explicitly. - A callable receives the input array and returns a corner.
Methods#
- _get_xp(…) -> np.ndarray | torch.Tensor
Internal method that performs cropping on either a NumPy array or a PyTorch tensor based on the specified parameters.
Examples#
>>> import deeptrack as dt
>>> particle = dt.PointParticle(position=(32, 32)) >>> optics = dt.Fluorescence() >>> crop = dt.Crop(crop=64, crop_mode="retain", corner=(0,0)) >>> image = optics(particle) >> crop >>> image.plot();