torchcvnn.transforms.CenterCrop¶
- class torchcvnn.transforms.CenterCrop(height: int, width: int)[source]¶
Center crops an input array/tensor to the specified size.
This transform extracts a centered rectangular region from the input array/tensor with the specified dimensions. The crop is centered on both height and width axes.
- Parameters:
- Returns:
- Center cropped array/tensor with shape (C, height, width),
where C is the number of channels
- Return type:
np.ndarray | torch.Tensor
Examples
>>> transform = CenterCrop(height=224, width=224) >>> output = transform(input_tensor) # Center crops to 224x224
Notes
If input is smaller than crop size, it will return the original input
Crop is applied identically to all channels
Uses functional.center_crop() implementation for both numpy and torch
Methods
__init__(height, width)