ops¶
square_center_crop¶
- square_center_crop(img, noise=0.0)¶
crop a single image of shape (channels, width, height) around the center with optional random shift along the longest dimension.
- Parameters
img (
Tensor
) – single image tensor of shape (channels, width, height).noise (
float
) – for shifting the crop window along the longest dimension Defaults to 0.0 (no noise).
Example
>>> import torch >>> from hearth.vision.ops import square_center_crop >>> >>> img = torch.randint(0, 255, size=(3, 345, 256)) >>> square_center_crop(img).shape torch.Size([3, 256, 256])
>>> square_center_crop(img, noise=0.5).shape torch.Size([3, 256, 256])
>>> square_center_crop(img.transpose(1, 2), noise=0.5).shape torch.Size([3, 256, 256])
- Return type
Tensor