plenoptic.process.center_crop#

plenoptic.process.center_crop(x, output_size)[source]#

Crop out the center of a signal.

If x has an even number of elements on either of those final two dimensions, we round up.

Parameters:
  • x (Tensor) – N-dimensional tensor, we assume the last two dimensions are height and width.

  • output_size (int) – The size of the output. Must be a positive int. Note that we only support a single number, so both dimensions are cropped identically.

Return type:

Tensor

Returns:

cropped – Tensor whose last two dimensions have each been cropped to output_size.

Raises:
  • TypeError – If output_size is not a single int.

  • ValueError – If output_size is not positive or larger than the height/width of ``x.

Examples

>>> import plenoptic as po
>>> img = po.data.einstein()
>>> img.shape
torch.Size([1, 1, 256, 256])
>>> crop = po.process.center_crop(img, 128)
>>> crop.shape
torch.Size([1, 1, 128, 128])
>>> po.plot.imshow([img, crop], title=["input", "cropped"])
<PyrFigure ...>

(png, hires.png, pdf)

../../_images/plenoptic-process-center_crop-1.png