prtools.crop#
- crop(x, shape, shift=None, mode='absolute', indexing='ij')[source]#
Extract a contiguous subarray from a larger array.
The subarray is extracted about the center of the source array unless a shift is specified.
- Parameters:
x (array_like) – Source array
shape (array_like of ints) – Shape of subarray array in
(nrows, ncols).shift (array_like of ints, optional) – Subarray center shift. Default is None (subarray is extracted about the center of the source array).
mode ({'absolute', 'center'}, optional) – Specifies how the subarray center located. If ‘absolute’ (default) the subarray is extracted about the location given by
shift. If ‘center’, the subarray is extracted about the center of the source array shifted byshift.indexing ({'ij', 'xy'}, optional) – Matrix (‘ij’, default) or cartesian (‘xy’) indexing of shift.
- Returns:
out – Subarray extracted from the source array.
- Return type:
ndarray
See also
Examples
>>> circ = prtools.circle(shape=(128,128), radius=64) >>> circ_crop = prtools.crop(circ, shape=(110,110)) >>> fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(5,2)) >>> ax[0].imshow(circ, cmap='gray') >>> ax[0].set_title('Original array') >>> ax[1].imshow(circ_crop, cmap='gray') >>> ax[1].set_title('Subarray')
>>> circ = prtools.circle(shape=(128,128), radius=64) >>> circ_crop = prtools.crop(circ, shape=(64,64), shift=(32,32)) >>> fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(5,2)) >>> ax[0].imshow(circ, cmap='gray') >>> ax[0].set_title('Original array') >>> ax[1].imshow(circ_crop, cmap='gray') >>> ax[1].set_title('Subarray')
>>> circ = prtools.circle(shape=(128,128), radius=64) >>> circ_crop = prtools.crop(circ, shape=(64,64), shift=(-32,-32), ... mode='center') >>> fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(5,2)) >>> ax[0].imshow(circ, cmap='gray') >>> ax[0].set_title('Original array') >>> ax[1].imshow(circ_crop, cmap='gray') >>> ax[1].set_title('Subarray')