trw.transforms.crop

Module Contents

Functions

_crop_5d(image, min, max)

_crop_4d(image, min, max)

_crop_3d(image, min, max)

_crop_2d(image, min, max)

_crop_1d(image, min, max)

batch_crop(images: trw.basic_typing.TensorNCX, min_index: Sequence[int], max_index_exclusive: Sequence[int]) → trw.basic_typing.TensorNCX

Crop an image

transform_batch_random_crop_offset(array: trw.basic_typing.TensorNCX, crop_shape: Sequence[Union[None, int]]) → numpy.ndarray

Calculate the offsets of array to randomly crop it with shape crop_shape

transform_batch_random_crop(array: trw.basic_typing.TensorNCX, crop_shape: Sequence[Union[int, None]], offsets: Sequence[Sequence[int]] = None, return_offsets: bool = False) → Union[trw.basic_typing.TensorNCX, Tuple[trw.basic_typing.TensorNCX, Sequence[Sequence[int]]]]

Randomly crop a numpy array of samples given a target size. This works for an arbitrary number of dimensions

transform_batch_random_crop_joint(arrays: Sequence[trw.basic_typing.TensorNCX], crop_shape: Sequence[Union[None, int]], return_offsets: bool = False) → Union[List[trw.basic_typing.TensorNCX], Tuple[List[trw.basic_typing.TensorNCX], trw.basic_typing.TensorNCX]]

Randomly crop a list of arrays. Apply the same cropping for each array element

trw.transforms.crop._crop_5d(image, min, max)
trw.transforms.crop._crop_4d(image, min, max)
trw.transforms.crop._crop_3d(image, min, max)
trw.transforms.crop._crop_2d(image, min, max)
trw.transforms.crop._crop_1d(image, min, max)
trw.transforms.crop.batch_crop(images: trw.basic_typing.TensorNCX, min_index: Sequence[int], max_index_exclusive: Sequence[int]) trw.basic_typing.TensorNCX

Crop an image :param images: images with shape [N * …] :param min_index: a sequence of size len(array.shape)-1 indicating cropping start :param max_index_exclusive: a sequence of size len(array.shape)-1 indicating cropping end (excluded)

Returns

a cropped images

trw.transforms.crop.transform_batch_random_crop_offset(array: trw.basic_typing.TensorNCX, crop_shape: Sequence[Union[None, int]]) numpy.ndarray

Calculate the offsets of array to randomly crop it with shape crop_shape

Examples

Crop a 3D arrays stored as NCX. Use None to keep dim=1: >>> arrays = torch.zeros([10, 1, 64, 64, 64]) >>> cropped_arrays = transform_batch_random_crop_offset(array, crop_shape=[None, 16, 16, 16]) >>> cropped_arrays.shape [10, 1, 16, 16, 16]

Parameters
  • array – a numpy array. Samples are stored in the first dimension

  • crop_shape – a sequence of size len(array.shape)-1 indicating the shape of the crop. If a dimension is None, the whole axis is kept for this dimension.

Returns

a offsets to crop the array

trw.transforms.crop.transform_batch_random_crop(array: trw.basic_typing.TensorNCX, crop_shape: Sequence[Union[int, None]], offsets: Sequence[Sequence[int]] = None, return_offsets: bool = False) Union[trw.basic_typing.TensorNCX, Tuple[trw.basic_typing.TensorNCX, Sequence[Sequence[int]]]]

Randomly crop a numpy array of samples given a target size. This works for an arbitrary number of dimensions

Parameters
  • array – a numpy or Torch array. Samples are stored in the first dimension

  • crop_shape – a sequence of size len(array.shape)-1 indicating the shape of the crop. If None in one of the element of the shape, take the whole dimension

  • offsets – if None, offsets will be randomly created to crop with crop_shape, else an array indicating the crop position for each sample

  • return_offsets – if True, returns a tuple (cropped array, offsets)

Returns

a cropped array and optionally the crop positions

trw.transforms.crop.transform_batch_random_crop_joint(arrays: Sequence[trw.basic_typing.TensorNCX], crop_shape: Sequence[Union[None, int]], return_offsets: bool = False) Union[List[trw.basic_typing.TensorNCX], Tuple[List[trw.basic_typing.TensorNCX], trw.basic_typing.TensorNCX]]

Randomly crop a list of arrays. Apply the same cropping for each array element

Parameters
  • arrays – a list of numpy or Torch arrays. Samples are stored in the first dimension

  • crop_shape – a sequence of size len(array.shape)-1 indicating the size of the cropped tensor

  • return_offsets – if true, returns where the cropping started

Returns

a cropped array, [cropping offset]